Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Random column fetch in cassandra

Tags:

java

cassandra

I am using this code for fetching user_id & user_code

Keyspace keyspace = HFactory.createKeyspace("test", cluster);
CqlQuery<String,String,ByteBuffer> cqlQuery = new CqlQuery<String,String,ByteBuffer>(keyspace, stringSerializer, stringSerializer, new ByteBufferSerializer());
cqlQuery.setQuery("select user_id,user_code from User");
QueryResult<CqlRows<String,String,ByteBuffer>> result = cqlQuery.execute();
Iterator iterator = result.get().iterator();
while(iterator.hasNext()) {
    Row<String, String, ByteBuffer> row =  (Row<String, String, ByteBuffer>) iterator.next();
    System.out.println("\nInserted data is as follows:\n" + row.getColumnSlice().getColumns().get(0).getValue().getInt());
    System.out.println("\nInserted data is as follows:\n" + Charset.forName("UTF-8").decode(row.getColumnSlice().getColumns().get(1).getValueBytes()));
}

Now Problem lies here that I am converting the fields according to their specific type

What if query goes random? How to handle that scenario?

like image 377
Hemant Kumar Avatar asked Nov 12 '22 11:11

Hemant Kumar


1 Answers

CQL queries are returned with metadata about the columns they contain, similar to a JDBC resultset.

I don't know if or how Hector exposes this information. For CQL, a better choice would be the new pure CQL driver here: https://github.com/datastax/java-driver

like image 123
jbellis Avatar answered Nov 15 '22 05:11

jbellis