Question

Can you provide an example of batch_mutate() function in phpcassa?

Cant understand how to work with this function and didnt found any enough information.

Also i want to know how to use it with counters

Thanks in advance.

Was it helpful?

Solution

"delete data from multiple keys":

function batch_remove($key=null, $columns=null, $super_column=null, $write_consistency_level=null) {

    $timestamp = CassandraUtil::get_time();
    $deletion = new cassandra_Deletion();
    $deletion->timestamp = $timestamp;

    if ($super_column !== null) $deletion->super_column = $this->pack_name($super_column, true);
    else $deletion->super_column = null;

    if ($columns !== null) {
        $predicate = $this->create_slice_predicate($columns, '', '', false, self::DEFAULT_COLUMN_COUNT);
        $deletion->predicate = $predicate;
    }

    $mutation = new cassandra_Mutation();
    $mutation->deletion = $deletion;

    if (is_array($key) && count($key) >= 1) {

        $mut_map = array();
        foreach($key as $v) {
            $packed_key[$v] = $this->pack_key($v);
            $mut_map[$v] = array($this->column_family => array($mutation));
        }

        return $this->pool->call("batch_mutate", $mut_map, $this->wcl($write_consistency_level));

    } else return false;

}

//delete name1, name2, name3 from key1, key2 in a single call
$column_family->batch_remove(array(key1, key2), array(name1, name2, name3));

OTHER TIPS

  1. batch_mutate on counters is not available yet with PHPCassa: https://github.com/thobbs/phpcassa/issues/31
  2. batch_mutate in action, as per the tutorial: http://thobbs.github.com/phpcassa/tutorial.html

"inserting data":

 $row1 = array('name1' => 'val1', 'name2' => 'val2');
 $row2 = array('foo' => 'bar');
 $column_family->batch_insert(array('row1' => $row1, 'row2' => $row2);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top