Database Reference
In-Depth Information
Getting All Columns in a Row
To read allof the columns in a row, you still need the predicate using a slice range, but you pass
it empty byte arrays for the start and finish parameters, like this:
SlicePredicate predicate = new SlicePredicate();
SliceRange sliceRange = new SliceRange();
sliceRange.setStart(new byte[0]);
sliceRange.setFinish(new byte[0]);
predicate.setSlice_range(sliceRange);
Then, you can pass this populated predicate object to your get_slice operation along with the
other necessary parameters (such as consistency level and so on).
Get Range Slices
In the same way that you access a set of columns by using a range, you can also access a range
of keys or tokens. Using the get_range_slices operation, you can pass it a KeyRange object
that defines the range of keys you want.
One major distinction here is that you can get either keys or tokens in a range using the same
KeyRange data structure as the parameter to get_range_slices . Key ranges are start-inclusive,
whereas token ranges are start-exclusive; because of ring distribution, tokens can wrap around so
that the end token is less than the start token.
The API defines the operation get_range_slices for you to use. The operation is structured
like this:
List<KeySlice> results = client.get_range_slices(parent, predicate, keyRange,
ConsistencyLevel);
For a complete listing that shows using a range slice, see Example 7-4 .
Example7-4.GetRangeSliceExample.java
package com.cassandraguide.rw;
//imports omitted
public class GetRangeSliceExample {
public static void main(String[] args) throws Exception {
Connector conn = new Connector();
Cassandra.Client client = conn.connect();
System.out.println("Getting Range Slices.");
Search WWH ::




Custom Search