Hot questions for Using Cassandra in key value store

Top Java Programmings / Cassandra / key value store

Question:

I am creating a key-value store in Cassandra with the Java driver and it is complaining about the batch size being too big.

So I want to reduce the Cassandra batch size. I have a BatchStatement object which contains a setFetchSize method. Is this the appropriate method to set the batch size. Otherwise, how can I do it?

thanks in advance

Altober


Answer:

Batch statements are useful but they are not maded for bulk loading in Cassandra, in the C# faq Datastax clearly recommend to have a batch size in the order of tens.

If you want to insert a lot of datas, the best practise is to use regular or async statements to do so.

Question:

I am new to Cassandra. I want to programatically (QueryBuilder) query for multiple rows at once in a table with a composite primary key.

Something like:

Assume that in TABLE PRIMARY KEY(key1,key2)

Select * from TABLE where (key1=a AND key2=b) OR (key1=c AND key2=d)

Thanks in advance.

Altober


Answer:

Your statement will never work because the OR keyword do not exist in Cassandra. There's unfortunately no alternatives at the moment unless you use a custom index such as lucene

Question:

Need help in reading data from Cassandra DB of type Map(varchar,double) in Scala.

i am using Cassandra core 3.0 and data is stored in DB by third party API so i cannot change type

I was trying to read using row.getMap("column_name", classOf[String], classOf[Double])) but i am facing following error: "IllegalArgumentException: Primitive type 'double' used as type parameter"

Thanks in advance.


Answer:

I believe that the reason of the issue is that getMap returns java.util.Map and standard Java collections do not support value types (aka primitive types) as generic keys or values. Wrapper objects are used instead such as java.lang.Double (see also autoboxing). So try something like

row.getMap("column_name", classOf[String], classOf[java.lang.Double])) 

Question:

It seems that in the 2.2. version of the Java driver, in DataType, the method "asJavaClass()" from previous versions was removed. Does anyone have any idea how to get the equivalent Java Class for a given DataType.

thanks in advance

Altober


Answer:

With the introduction of custom codecs in 2.2, there is no pre-established mapping to a given Java class, that would depend on the codecs that are registered and which getter method you call to retrieve the value. At best we could provide the "default" mapping produced by the built-in codecs. What use case do you need this for?