thobbs/phpcassa — Issue #51: Problem to get a slice of columns under super columns
Author: Andmag
Created: 2011-11-04 08:30:27+00:00
State: open

I have problem to read a slice with columns under a super column. The column family has Comparator Type = LongType and Subcomparator Type	= TimeUUIDType.
When i try to use get like this ($nextCol is a TimeUUID where to start read the columns.):
$columns = $this->family_feedsort->get($UserID, NULL, $nextCol, "", TRUE, $numberOfColumns, $Id);
I get the following error: TimeUUID should be 16 or 0 bytes (8)

When i do it on another column family with out super columns it works perfect.

I made a quick fix in columnfamily.php that solves it, but probably there is a better way to do it.
When getting a slice from columns under a super column, create_slice_predicate use the property is_super to determine if it is super or normal columns, but is_super tells if it is a super column family or not. So if you submit a $super_column parameter it is normal columns that are read under the super column.

public function get($key,
$columns=null,
$column_start="",
$column_finish="",
$column_reversed=False,
$column_count=self::DEFAULT_COLUMN_COUNT,
$super_column=null,
$read_consistency_level=null) {

$column_parent = $this->create_column_parent($super_column);
$predicate = $this->create_slice_predicate($columns, $column_start, $column_finish,
$column_reversed, $column_count, $super_column != NULL); //---- changed here

$resp = $this->pool->call("get_slice",
$this->pack_key($key),
$column_parent,
$predicate,
$this->rcl($read_consistency_level));

if (count($resp) == 0)
throw new cassandra_NotFoundException();

return $this->supercolumns_or_columns_to_array($resp);
}

private function create_slice_predicate($columns, $column_start, $column_finish,
$column_reversed, $column_count, $isSuper = NULL) { //---- changed here

if ($isSuper == NULL) //---- changed here
{
$isSuper = $this->is_super;
}
else
{
$isSuper = !$isSuper;
}

$predicate = new cassandra_SlicePredicate();
if ($columns !== null) {
$packed_cols = array();
foreach($columns as $col)
$packed_cols[] = $this->pack_name($col, $isSuper);//---- changed here
$predicate->column_names = $packed_cols;
} else {
if ($column_start != null and $column_start != '')
$column_start = $this->pack_name($column_start,
$isSuper, //---- changed here
self::SLICE_START);
if ($column_finish != null and $column_finish != '')
$column_finish = $this->pack_name($column_finish,
$isSuper, //---- changed here
self::SLICE_FINISH);

$slice_range = new cassandra_SliceRange();
$slice_range->count = $column_count;
$slice_range->reversed = $column_reversed;
$slice_range->start = $column_start;
$slice_range->finish = $column_finish;
$predicate->slice_range = $slice_range;
}
return $predicate;
}