I am newbie in scala and i want to convert my java code to scala. my database is cassandra and column family definition look like this
Family name :colFam
Rowkey: rowKey1
=>(name=comkey1:comkey1,value='xyz',timestamp=1554515485)
=>(name=comkey1:comkey2,value='xyz',timestamp=1554515485)
=>(name=comkey1:comkey3,value='xyz',timestamp=1554515485)
=>(name=comkey1:comkey4,value='xyz',timestamp=1554515485)
=>(name=comkey1:comkey5,value='xyz',timestamp=1554515485)
-------------------------------------------------------
Rowkey: rowKey2
=>(name=comkey1:comkey3,value='abc',timestamp=1554515485)
-------------------------------------------------------
Rowkey: rowKey4
=>(name=comkey1:comkey4,value='pqr',timestamp=1554515485)
-------------------------------------------------------
now i want to fetch all record from cassandra and my columnQuery working fine
val sliceQuery = HFactory.createColumnQuery(rankqKeyspace, StringSerializer.get(), new CompositeSerializer(), StringSerializer.get())
problem in my sliceQuery,normally slice query working fine with simple column name but when i used column type composite,it giving me error
var startKey = new Composite();
var endKey = new Composite();
startKey.addComponent("comkey1", se);
startKey.addComponent("comkey2", se);
endKey.addComponent("comkey1", se);
endKey.addComponent("comkey4", se);
val sliceQuery = HFactory.createSliceQuery(rankqKeyspace, se, new CompositeSerializer(), se)
slicesQuery.setColumnFamily("colFam");
slicesQuery.setKey(rowKey1)
slicesQuery.setRange(startKey, endKey, false, Integer.MAX_VALUE);
val result = slicesQuery.execute()
val orderedRows = result.get();
it giving me error "NullPointerException"
val orderedRows = result.get();
println(orderedRows)
this line return always null value
Edit Question
Stack Trace
java.lang.NullPointerException
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:191)
at com.google.common.collect.ImmutableClassToInstanceMap.getInstance(ImmutableClassToInstanceMap.java:147)
at me.prettyprint.hector.api.beans.AbstractComposite.serializerForComparator(AbstractComposite.java:321)
at me.prettyprint.hector.api.beans.AbstractComposite.getSerializer(AbstractComposite.java:344)
at me.prettyprint.hector.api.beans.AbstractComposite.deserialize(AbstractComposite.java:708)
at me.prettyprint.cassandra.serializers.CompositeSerializer.fromByteBuffer(CompositeSerializer.java:29)
at me.prettyprint.cassandra.serializers.CompositeSerializer.fromByteBuffer(CompositeSerializer.java:17)
at me.prettyprint.cassandra.model.HColumnImpl.getName(HColumnImpl.java:111)
at me.prettyprint.cassandra.model.HColumnImpl.toString(HColumnImpl.java:202)
at java.lang.String.valueOf(String.java:2854)
at java.lang.StringBuilder.append(StringBuilder.java:128)
at java.util.AbstractCollection.toString(AbstractCollection.java:450)
at me.prettyprint.cassandra.model.ColumnSliceImpl.toString(ColumnSliceImpl.java:54)
at java.lang.String.valueOf(String.java:2854)
at java.io.PrintStream.println(PrintStream.java:821)
at scala.Console$.println(Console.scala:240)
at scala.Predef$.println(Predef.scala:287)
at models.PinModel$.testColCompositeKey(PinModel.scala:178)
at controllers.PinController$$anonfun$test$1.apply(PinController.scala:52)
at controllers.PinController$$anonfun$test$1.apply(PinController.scala:49)
at play.api.mvc.ActionBuilder$$anonfun$apply$10.apply(Action.scala:221)
at play.api.mvc.ActionBuilder$$anonfun$apply$10.apply(Action.scala:220)
at play.api.mvc.Action$.invokeBlock(Action.scala:357)
at play.api.mvc.ActionBuilder$$anon$1.apply(Action.scala:309)
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4$$anonfun$apply$5.apply(Action.scala:109)
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4$$anonfun$apply$5.apply(Action.scala:109)
at play.utils.Threads$.withContextClassLoader(Threads.scala:18)
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4.apply(Action.scala:108)
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4.apply(Action.scala:107)
at scala.Option.map(Option.scala:145)
at play.api.mvc.Action$$anonfun$apply$1.apply(Action.scala:107)
at play.api.mvc.Action$$anonfun$apply$1.apply(Action.scala:100)
at play.api.libs.iteratee.Iteratee$$anonfun$mapM$1.apply(Iteratee.scala:481)
at play.api.libs.iteratee.Iteratee$$anonfun$mapM$1.apply(Iteratee.scala:481)
at play.api.libs.iteratee.Iteratee$$anonfun$flatMapM$1.apply(Iteratee.scala:517)
at play.api.libs.iteratee.Iteratee$$anonfun$flatMapM$1.apply(Iteratee.scala:517)
at play.api.libs.iteratee.Iteratee$$anonfun$flatMap$1$$anonfun$apply$13.apply(Iteratee.scala:493)
at play.api.libs.iteratee.Iteratee$$anonfun$flatMap$1$$anonfun$apply$13.apply(Iteratee.scala:493)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:42)
at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:386)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)