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


<?php
require_once('phpcassa-0.8.a.2/connection.php');
require_once('phpcassa-0.8.a.2/columnfamily.php');

$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) {
  print($columns['full_name']);
}

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: