Database Reference
In-Depth Information
SlicePredicate predicate = new SlicePredicate();
SliceRange sliceRange = new SliceRange();
sliceRange.setStart("age".getBytes());
sliceRange.setFinish("name".getBytes());
predicate.setSlice_range(sliceRange);
When executed with a get_slice operation, this query will return the two columns specified, as
well as any columns that a comparison operation would sort within that range (between them lex-
icographically, numerically, or whatever). For example, if this row also had an “email” column,
it would be returned in the results as well.
You must consider the column names according to their comparator, and specify start and finish
in the proper order. For example, trying to set a start of name and a finish of age will throw an
exception like this:
InvalidRequestException(why:range finish must come after start in the order of
traversal)
NOTE
Recall that “returning a column” doesn't mean that you get the value, as in SQL; it means that you get
the complete column data structure, which is the name, the value, and the timestamp.
Counts
You can limit the number of columns returned by your slice range by using the count attribute
of the Slice Range structure. Let's say we have a row with hundreds of columns. We could
specify a range that might include many of these columns, but limit our result set to only the first
10 columns like this:
SliceRange sliceRange = new SliceRange();
sliceRange.setStart("a".getBytes());
sliceRange.setFinish("d".getBytes());
sliceRange.count = 10;
Again, the “first” columns are those according to the order dictated by the column family's com-
parator.
Reversed
You can also reverse the order in which the columns are fetched by setting the reversed =
true attribute on the slice range. If you have columns age , email , and name , then setting re-
versed to true returns them in the order name , email , age .
Search WWH ::




Custom Search