I am using Erlang to interface with Cassandra and I cannot get the get_slice command to return a list of all the columns of a row. I use:
X = thrift_client:call( C,
'get_slice',
[ "Keyspace1",
K,
#columnParent{column_family="KeyValue"},
开发者_运维百科 #slicePredicate{},
1
] ),
: but I get back :
invalidRequestException,<<"predicate column_names and slice_range may not both be null">>
: However, using the cassandra-cli interface this works fine. Any ideas?
Updated:
I amended the Erlang example to reflect the Java exmaple given to :
get_props(K) -> {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.
:and it now works. Notice the addition of the line:
S = #sliceRange{start="",finish="",reversed=false,count=100}
You are default initializing your SlicePredicate object. This will default construct a SlicePredicate with reversed set to false (compare with SQL syntax: "ORDER by DESC"), count set to 100 (compare with SQL syntax: LIMIT 100) and both slice_range and column_names set to null (unspecified in Erlang, because the "lack" of null).
Hopefully my Java code snippet could assist you (the example fetches all columns). I want to emphasize the creation and usage of the 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);
}
}
精彩评论