Database Reference
In-Depth Information
Slice Predicate
A slicepredicateis used in both read and write operations, acting as a limiting factor for specify-
ing a set of columns. You can specify the predicate one of two ways: with a list of column names
or with a slice range. If you know the names of a few columns that you want to retrieve, then
you can specify them explicitly by name. If you don't know their names, or for another reason
want to retrieve a range of columns, you use a slice range object to specify the range.
NOTE
I'm using contained examples to be concise. But it is not uncommon to see many, many columns defined
per row in Cassandra, so don't let these examples mislead you. It's a big data store and can hold two
billion columns per row in version 0.7.
To use the slice predicate, you create a predicate object populated with the column names you
want, and pass it to your read operation.
Getting Particular Column Names with Get Slice
If you want to get just the columns called “a” and “b” in a single row, you can use the predicate
with the column names specified.
You can get a set of columns contained in a column parent using a get_slice operation. It will
retrieve values by column name or a range of names, and will return either columns or super
columns. The get_slice operation has this signature:
List<ColumnOrSuperColumn> get_slice(byte[] key,
ColumnParent column_parent, SlicePredicate predicate, ConsistencyLevel cl)
This is shown in Example 7-3 .
Example7-3.SlicePredicate.java
package com.cassandraguide.rw;
// imports omitted
public class SlicePredicateExample {
public static void main(String[] args) throws Exception {
Connector conn = new Connector();
Cassandra.Client client = conn.connect();
SlicePredicate predicate = new SlicePredicate();
Search WWH ::




Custom Search