1

SELECT * FROM table_name WHERE date > 1309110123

How to do this in Phpcassa? I think there must be some way to modify this:

$column_family = new ColumnFamily($conn, 'Indexed1');
$index_exp = CassandraUtil::create_index_expression('birthdate', 1984);
$index_clause = CassandraUtil::create_index_clause(array($index_exp));
$rows = $column_family->get_indexed_slices($index_clause);
// returns an Iterator over:
//    array('winston smith' => array('birthdate' => 1984))

foreach($rows as $key => $columns) {
    // Do stuff with $key and $columns
    Print_r($columns)
}

Anyone an idea?

Writecoder
  • 613
  • 2
  • 8
  • 27
  • you should take a look at secondary index (supported since 0.7) – Schildmeijer Jun 26 '11 at 17:51
  • although secondary indexes are nice, i've found them to be not the greatest solution ... there are easier and less costly ways to achieve the same outcome, as listed below. **cost in a systems sense – sdolgy Jun 27 '11 at 10:41

1 Answers1

3

I would suggest an alternate approach to what you have above. The easiest way is to store a record of your row key in another row, as a column, as such:

$date = new DateTime();
$cf = new ColumnFamily(getCassandraConnection(), 'foobar');
$cf->insert('row1' => array('foo' => 'bar'));
$cf->insert('all_rows' => array($date->getTimestamp() => 'row1');

Now, when you want to do a select, like you have done above, using PHPCASSA, you can simply do a get with column_start / column_end:

$newerResults = $cf->get('all_rows', $columns=null, $column_start=1309110123);

In the case of birthdates, as ugly as it seems from an RDBMS world, create a new column in a row for 'user_birthdates' where each columname is birthday:uuid to keep things unique.

sdolgy
  • 6,963
  • 3
  • 41
  • 61