Cassandra Offset

85 views
Skip to first unread message

codegger

unread,
Jul 13, 2010, 6:25:58 AM7/13/10
to pandra-dev
Hi,
I want to display some data of forum with cassandra, how to make a
pagination with cassandra class?

public function getSuperColumn($key_id, $column_family ,$output =
"array")
{
$this->extendClass('PandraSuperColumnFamily', $key_id, $this-
>cassa_keyspace, $column_family);
$ColumnFamily = $this->PandraSuperColumnFamily;
//echo var_dump($ColumnFamily);
if($this->getLimit() != NULL){
$ColumnFamily->limit($this->getLimit())-
>load(); //--------------> How to make offset of data called, like
in mysql LIMIT row_count OFFSET offset?
}else{
$ColumnFamily->load();
}

if($output == "array"){
return $ColumnFamily->toArray();
}else{
return $ColumnFamily->toJSON();
}
}

Thanks for response of my question!

mjpearson

unread,
Jul 13, 2010, 11:44:00 AM7/13/10
to pandra-dev
Hi,

The easiest way to do this is with the start() and finish() helpers:

$ColumnFamily->start('column')->finish('column')->load();

although behaviour may be different depending on the column family
etc. that you're querying (order preserving partitioner or timeuuid
secondary index would be ideal).

If you don't know what your page boundaries are in advance keep in
mind Thrift's start/finish are inclusive of the columns in the range,
so to paginate it's best to grab your page start/finish + 1 and pop
the +1 as the start for your next page.

eg a really simple example, something like:
// 10 to a page..
$ColumnFamily->start('column')->limit('11')->load();
$newStart = array_pop($ColumnFamily);
echo $ColumnFamiliy->toJSON();
// .. next page
$ColumnFamily->start($newStart)->limit('11')->load();
// ... etc


If this is too rigid PandraCore::getRangeKeys() may be another option
but a touch more complicated.

regards
-Michael

Nuris Kandar Musthafa

unread,
Jul 13, 2010, 10:20:32 PM7/13/10
to pandr...@googlegroups.com
Ok, I'll try it.
Thanks for the response of my question.

Josh

unread,
Jul 13, 2010, 10:57:37 PM7/13/10
to pandr...@googlegroups.com
got this error:
Fatal error: Call to undefined method PandraSuperColumnFamily::start()

Is it in 0.2 version?


Josh

2010/7/14 Nuris Kandar Musthafa <code...@gmail.com>

mjpearson

unread,
Jul 13, 2010, 11:00:11 PM7/13/10
to pandra-dev
Right sorry no - check out the latest head it may have been introduced
just after 0.2

-michael

On Jul 13, 7:57 pm, Josh <noisyw...@gmail.com> wrote:
> got this error:
> Fatal error: Call to undefined method PandraSuperColumnFamily::start()
>
> Is it in 0.2 version?
>
> Josh
>
> 2010/7/14 Nuris Kandar Musthafa <codeg...@gmail.com>
>
> > Ok, I'll try it.
> > Thanks for the response of my question.
>
Reply all
Reply to author
Forward
0 new messages