Monday, May 14, 2012

Executing where Condition in phpcasa

When I start learning about Cassandra, first thing in my mind is how to execute traditional where condition. It may be very simple but it took lot of my effort to figure out.

A very basic example is


$pool = new ConnectionPool('Keyspace1', array('localhost'));

$column_family = new ColumnFamily($pool, 'users');

$index_exp = CassandraUtil::create_index_expression('birth_date',1975);
$index_clause = CassandraUtil::create_index_clause(array($index_exp));
$rows = $column_family->get_indexed_slices($index_clause);

foreach($rows as $key => $columns) {

If this code works for you, you are lucky. If not then, you should learn what is Secondary indexes in cassandra. please go What’s new in Cassandra 0.7: Secondary indexes

No comments: