Database Reference
In-Depth Information
Getting Range Slices.
Current row: k1
a : 1
b : 2
Current row: k2
a : 2.1
b : 2.2
All done.
Though the names involving “slice” and “range” may seem unusual at first, they turn out to be
innocuous. Just remember that slices mean sets of columns and ranges mean sets of keys. So in
this example, we're getting multiple columns for multiple row keys.
Multiget Slice
With get_slice , we saw how to get a set of column names for a single specified row key. mul-
tiget_slice lets you retrieve a subset of columns for a set of row keys based on a column
parent and a predicate. That is, given morethanonerow key, retrieve the value of the named
columns for each key. So a multiget slice is more than one named column for more than one row.
NOTE
There used to be a method called multiget , but it is now deprecated in favor of multiget_slice .
The operation looks like this:
Map<byte[],List<ColumnOrSuperColumn>> results =
client.multiget_slice(rowKeys, parent, predicate, CL);
You specify the parent and the predicate as usual, and also provide the operation with the set of
row keys you want to query. The row keys are just specified as a list of byte arrays, which are the
key names.
The results come back to us as a Map<byte[],List<ColumnOrSuperColumn>> . This may seem
like a complicated data structure, but it's actually simple. A map is a key/value pair, and in this
case the byte array key is the row key, so in this example there will be two keys: one for each
row key we get. Each byte[] key in the results map points to a list containing one or more
ColumnOrSuperColumn objects. This structure is used because Thrift does not support inherit-
ance. You have to know whether your column family is of type Standard or Super , and then
you just get the right one from the data structure. From the ColumnOrSuperColumn , you extract
the column (in this case, the super_column will be empty), and then use the column object to
get the name and value. You could also get the timestamp from it if you wanted to.
Search WWH ::




Custom Search