我有一个简单的列族“用户”
System.out.println(" read User");
long timestamp = System.currentTimeMillis();
clientA.insert(ByteBuffer.wrap("mike".getBytes()), new ColumnParent("Users"),
new Column(ByteBuffer.wrap("email".getBytes())).setValue(ByteBuffer.wrap("mike@gmail.com".getBytes())).setTimestamp(timestamp)
, ConsistencyLevel.ONE);
clientA.insert(ByteBuffer.wrap("mike".getBytes()), new ColumnParent("Users"),
new Column(ByteBuffer.wrap("totalPosts".getBytes())).setValue(ByteBuffer.allocate(4).putInt(27).array()).setTimestamp(timestamp)
, ConsistencyLevel.ONE);
SlicePredicate predicate = new SlicePredicate();
predicate.setSlice_range(new SliceRange(ByteBuffer.wrap(new byte[0]), ByteBuffer.wrap(new byte[0]), false, 10));
ColumnParent parent = new ColumnParent("Users");
List<ColumnOrSuperColumn> results = clientA.get_slice(ByteBuffer.wrap("mike".getBytes()),
parent,
predicate,
ConsistencyLevel.ONE);
for (ColumnOrSuperColumn result : results) {
Column column = result.column;
System.out.println(new String(column.getName()) + " -> "+ new String(column.getValue())+", "+column.getValue().length);
}
它返回
read User
email -> mike@gmail.com, 14
totalPosts ->
因此,thrift 客户端无法读取 totalPosts
使用 cassandra-cli
[default@test] 获取用户['mike']['totalPosts']; =>(列=totalPosts,值=0000001b,时间戳=1336493080621)经过时间:10 毫秒。
如何使用 Java thrift 客户端检索此整数值?
使用卡桑德拉 1.1
编辑:似乎是由于这部分
for (ColumnOrSuperColumn result : results) {
Column column = result.column;
System.out.println(new String(column.getName()) + " -> "+Arrays.toString(column.getValue()));
}
返回
email -> [109, 105, 107, 101, 64, 103, 109, 97, 105, 108, 46, 99, 111, 109]
totalPosts -> [0, 0, 0, 27]