开发者

Cassandra time stamp

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 =>开发者_StackOverflow社区; $columns) {
    // Do stuff with $key and $columns
    Print_r($columns)
}

Anyone an idea?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜