View RSS Feed


Cassandra Read Operation

Rate this Entry
by , 02-23-2012 at 07:17 PM (1152 Views)
For example we have a number of authors in the database and we want to read them in Java. Below code explains this operation in detail.
Java Code: This is the code to Cassandra Read Operation
import org.apache.cassandra.thrift.SlicePredicate;
import org.apache.cassandra.thrift.SliceRange;
import org.apache.cassandra.thrift.ColumnOrSuperColumn;
import org.apache.cassandra.thrift.ColumnParent;
import org.apache.cassandra.thrift.ConsistencyLevel;
SlicePredicate slicePredicate = new SlicePredicate();
SliceRange sliceRange = new SliceRange();
sliceRange.setStart(new byte[] {});
sliceRange.setFinish(new byte[] {});
List result = client.get_slice("Blog", "Ronald Mathies", new ColumnParent("Authors"), slicePredicate, ConsistencyLevel.ONE);
In the above code SlicePredicate is created that informs Cassandra about the data fetch. In the above code, a range of columns are fetched. setStart() and setFinish() use name attributes to fetch the data. An empty byte array is passed.

Submit "Cassandra Read Operation" to Facebook Submit "Cassandra Read Operation" to Digg Submit "Cassandra Read Operation" to Submit "Cassandra Read Operation" to StumbleUpon Submit "Cassandra Read Operation" to Google