4

我是cassandra的新手,我的数据存储结构是

list test
RowKey: key1
=> (column=colkey1:colkey2, value=amitdubey, timestamp=1381832571947000)
=> (column=colkey1:colkey3, value=amitdubey, timestamp=1381832571947000)
=> (column=colkey1:colkey4, value=amitdubey, timestamp=1381832571947000)
-------------------
RowKey: key2
=> (column=colkey1:colkey2, value=amitdubey, timestamp=1381832571947000)
=> (column=colkey1:colkey3, value=amitdubey, timestamp=1381832571947000)
=> (column=colkey1:colkey4, value=amitdubey, timestamp=1381832571947000)
-------------------

使用列定义是

create column family test
with column_type = 'Standard'
and comparator=
'CompositeType(org.apache.cassandra.db.marshal.UTF8Type,
org.apache.cassandra.db.marshal.UTF8Type)'
and default_validation_class = 'UTF8Type'
and key_validation_class = 'UTF8Type';

但是当我获取keyRow时:

SliceQuery<String,Composite,String> sliceQuery=HFactory.createSliceQuery(keyspace, se, ce, se);
sliceQuery.setColumnFamily("test");
sliceQuery.setKey("jax");
sliceQuery.setRange(null,null, false, Integer.MAX_VALUE);
QueryResult<ColumnSlice<Composite,String>>result=sliceQuery.execute();
System.out.println(orderedRows.getColumns());

输出是:

[HColumn([java.nio.HeapByteBuffer[pos=0 lim=1 cap=1], java.nio.HeapByteBuffer[pos=0 lim=1 cap=1]]=5), HColumn([java.nio.HeapByteBuffer[pos=0 lim=1 cap=1], java.nio.HeapByteBuffer[pos=0 lim=1 cap=1]]=5), HColumn([java.nio.HeapByteBuffer[pos=0 lim=1 cap=1], java.nio.HeapByteBuffer[pos=0 lim=1 cap=1]]=5), HColumn([java.nio.HeapByteBuffer[pos=0 lim=1 cap=1], java.nio.HeapByteBuffer[pos=0 lim=1 cap=1]]=5), HColumn([java.nio.HeapByteBuffer[pos=0 lim=1 cap=1], java.nio.HeapByteBuffer[pos=0 lim=1 cap=1]]=5)]       
4

1 回答 1

3

你快到了,你有数据 - 你需要解压列,见下文:

SliceQuery<String, Composite, String> sliceQuery = HFactory.createSliceQuery(keyspace, StringSerializer.get(), CompositeSerializer.get(), StringSerializer.get());
sliceQuery.setColumnFamily("test");
sliceQuery.setKey("key1");
sliceQuery.setRange(null, null, false, Integer.MAX_VALUE);
QueryResult<ColumnSlice<Composite, String>> result = sliceQuery.execute();
ColumnSlice<Composite, String> slice = result.get();

List<HColumn<Composite, String>> columns = slice.getColumns();

System.out.println("Packed");
System.out.println(columns);

System.out.println();
System.out.println("Unpacked");
for (HColumn<Composite, String> column : columns) {
  String first = column.getName().get(0, StringSerializer.get());
  String second = column.getName().get(1, StringSerializer.get());
  System.out.println(first + ":" + second + "=" + column.getValue());
}

这应该给你这样的输出:

Packed
[HColumn([java.nio.HeapByteBuffer[pos=0 lim=7 cap=7], java.nio.HeapByteBuffer[pos=0 lim=7 cap=7]]=amitdubey), HColumn([java.nio.HeapByteBuffer[pos=0 lim=7 cap=7], java.nio.HeapByteBuffer[pos=0 lim=7 cap=7]]=amitdubey), HColumn([java.nio.HeapByteBuffer[pos=0 lim=7 cap=7], java.nio.HeapByteBuffer[pos=0 lim=7 cap=7]]=amitdubey)]

Unpacked
colkey1:colkey2=amitdubey
colkey1:colkey3=amitdubey
colkey1:colkey4=amitdubey

(用赫克托 1.1-4 测试。)

于 2013-11-06T22:36:16.010 回答