5

I am trying to figure out how to set a blob column under where clause. any idea?

For example if I put the following query in cqlsh it works

select * from hello where id=0xc1c1795a0b;

//id is a blob column in cassandra

I tried the following

JavaRDD<CassandraRow> cassandraRowsRDD = javaFunctions(sc).cassandraTable("test", "hello")
.select("range" )
.where("id=?", "0xc1c1795a0b");

This gave me a type converter exception

and I tried this

JavaRDD<CassandraRow> cassandraRowsRDD = javaFunctions(sc).cassandraTable("test", "hello")
.select("range" )
.where("id=?", "0xc1c1795a0b".getBytes());

This gave me no error however it returned no results. The query in my cqlsh did return bunch of results. so I am not sure to set a blob in the where clause. I am using Java. any ideas?

Erick Ramirez
  • 13,964
  • 1
  • 18
  • 23
user1870400
  • 6,028
  • 13
  • 54
  • 115

1 Answers1

3

Use this.

import com.datastax.driver.core.utils.Bytes;

JavaRDD<CassandraRow> cassandraRowsRDD = javaFunctions(sc).cassandraTable("test", "hello")
.select("range" )
.where("id=?",Bytes.getArray(Bytes.fromHexString("0xc1c1795a0b")));
abaghel
  • 14,783
  • 2
  • 50
  • 66
  • Thanks! I have another problem that has been super hard to trace. can you please look into this one?http://stackoverflow.com/questions/39953245/how-to-fix-java-lang-classcastexception-cannot-assign-instance-of-scala-collect – user1870400 Oct 10 '16 at 07:47