Randomly select columns in cassandra

I use this code to extract user_id and 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 the problem is that I convert the fields according to their specific type

What if the request goes randomly? How to deal with this scenario?

+5
source share
1 answer

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

I do not know how and how Hector discloses this information. For CQL, the best choice would be a new clean CQL driver here: https://github.com/datastax/java-driver

+1
source

All Articles