我正在使用Erlang与Cassandra进行交互,我无法获取get_slice命令来返回行的所有列的列表。我用:
X = thrift_client:call( C,
'get_slice',
[ "Keyspace1",
K,
#columnParent{column_family="KeyValue"},
#slicePredicate{},
1
] ),
:但我回来了:
invalidRequestException,<<"predicate column_names and slice_range may not both be null">>
:但是,使用cassandra-cli接口可以正常工作。有什么想法吗?
更新:
我修改了Erlang示例以反映给出的Java exexple:
get_props(K) - &gt; {ok,C} = thrift_client:start_link(“127.0.0.1”,9160,cassandra_thrift),
S = #sliceRange{start="",finish="",reversed=false,count=100},
X = thrift_client:call( C,
'get_slice',
[ "Keyspace1",
K,
#columnParent{column_family="KeyValue"},
#slicePredicate{slice_range=S},
1
] ),
X.
:它现在有效。注意添加以下行:
S = #sliceRange {start =“”,finish =“”,reverse = false,count = 100}
答案 0 :(得分:1)
您是默认初始化SlicePredicate对象。这将默认构造一个SlicePredicate,反向设置为false(与SQL语法比较:“ORDER by DESC”),count设置为100(与SQL语法比较:LIMIT 100),slice_range和column_names都设置为null(在Erlang中未指定,因为“缺乏”null。
希望我的Java代码段可以帮助您(示例提取所有列)。我想强调SlicePredicate的创建和使用。
private static void get_slice(Cassandra.Client client, String keyspace,
byte[] userI1, ColumnParent parent) {
SlicePredicate predicate = new SlicePredicate();
SliceRange sliceRange = new SliceRange();
sliceRange.setStart(new byte[0]);
sliceRange.setFinish(new byte[0]);
predicate.setSlice_range(sliceRange);
List<ColumnOrSuperColumn> results =
client.get_slice(
keyspace,
userI1,
parent,
predicate,
ConsistencyLevel.ONE
);
for (ColumnOrSuperColumn cosc : results) {
System.out.println("column name: " + new String(cosc.column.name));
System.out.println("column value: " + new String(cosc.column.value));
System.out.println("column timestamp: " + cosc.column.timestamp);
}
}