Database Reference
In-Depth Information
List<byte[]> colNames = new ArrayList<byte[]>();
colNames.add("a".getBytes());
colNames.add("b".getBytes());
predicate.column_names = colNames;
ColumnParent parent = new ColumnParent("Standard1");
byte[] key = "k1".getBytes();
List<ColumnOrSuperColumn> results =
client.get_slice(key, parent, predicate, ConsistencyLevel.ONE);
for (ColumnOrSuperColumn cosc : results) {
Column c = cosc.column;
System.out.println(new String(c.name, "UTF-8") + " : "
+ new String(c.value, "UTF-8"));
}
conn.close();
System.out.println("All done.");
}
}
In this example, only the specified columns will be retrieved, and the other columns will be ig-
nored. The query returns a list of ColumnOrSuperColumn objects. Because we know that we're
querying a regular column family, we get the column out of the ColumnOrSuperColumn data
structure returned by the underlying RPC mechanism (Thrift), and finally retrieve the names and
values from it in a loop.
The output is as follows:
a : 1
b : 2
All done.
Getting a Set of Columns with Slice Range
Sometimes you don't want to specify each and every column you want to retrieve, perhaps be-
cause you have a lot of columns to retrieve or because you don't know all of their names.
To read a rangeof the columns in a row, you can specify the start and finish columns, and Cas-
sandra will give you the start and finish columns as well as any columns in between, according
to the sorting order based on the comparator for that column family. Create your slice predicate,
then create your range, and then set the range into the predicate before passing the predicate to
your read operation. Here's an example:
Search WWH ::




Custom Search