Search code examples
phpcassandraphpcassa

getting data from cassandra using clauses


Is there any way to get data from cassandra through phpcassa using a clauses?

I need to select all rows where sum<10. For example the function in phpcassa get_range() selects only rows which equals certain values.


Solution

  • Normally with PHPCassa, you would use indexes:

    As per http://thobbs.github.com/phpcassa/tutorial.html // slightly enhanced:

    <?php
    $column_family = new ColumnFamily($conn, 'Indexed1');
    $index_exp_eq = CassandraUtil::create_index_expression('gender', 'male', $op='EQ');
    $index_exp_gt = CassandraUtil::create_index_expression('sum', 10, $op='GT');
    $index_clause = CassandraUtil::create_index_clause(array($index_exp_eq, $index_exp_gt));
    $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)
    }
    ?>
    

    With your scenario, you cannot simply have a single index expression with sum<10 ... You must have the first index expression with an EQ operator and subsequent index expressions with other Operators.