2013-02-22 57 views
5

我使用此代码获取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())); 
} 

现在问题就出在这里,我根据自己的具体类型

如果什么查询会随机变换等领域?如何处理这种情况?

+0

Plz尝试使用不同的BufferSerialezer而不是ByteBufferSerializer,通过这个u将始终获取字节流中的所有数据,尝试从数据库中提取数据以其存储的实际格式。 – 2013-02-22 12:10:50

回答

1

CQL查询返回包含它们所包含的列的元数据,类似于JDBC结果集。

我不知道Hector是否或如何暴露此信息。对于CQL,更好的选择将是这里新的纯CQL驱动程序:https://github.com/datastax/java-driver

+0

你是如何得到它的工作?看看[我的要点](https://gist.github.com/shehaaz/5279566)...这是一个Cassandra集群会话...刚刚称为新的Cassandra();不努力......是否需要与港口?为什么我不能将它设置为localhost:9160 ....在ProtocolOptions中,DEFAULT_PORT设置为9042 ...为什么是这样?谢谢! :) – Shehaaz 2013-03-31 04:56:57