Pagination in apache cassandra

断了今生、忘了曾经 提交于 2019-12-25 01:55:47

问题


How is the pagination achieved in Cassandra, I understand by sending the last received timestamp we will be able to achieve it. Apart from that is there any other way to achieve the Pagination in Cassandra?

Also, Using timestamp has the limitation that it will help us paginate only in the insert order.


回答1:


There is a notion of page state that you can pass when executing query, and query will return results starting with "known state". NodeJS driver exposes as pageState property of the result returned after execution of query - you can store this state in user's session (or web page itself), and reuse for next request, by putting it into options, something like (stolen from documentation):

const options = { pageState : pageState, prepare : true, fetchSize :  200 };
client.eachRow(query, parameters, options, function (n, row) { // Row callback.
 }, function (err, result) {       // End callback.
    // Store the next paging state.
    pageState = result.pageState;
 }
);

NodeJS driver documentation provides more examples how to use it. You can also consult documentation for Java driver - I believe that it have more details about page state.

There are also some caveats, like, you can't jump to arbitrary page, state may not be "compatible" between Cassandra versions (if you do rolling upgrade), etc.




回答2:


$statement = new Cassandra\SimpleStatement("select * from tablename where id = ".$id); 
$result = $connection->execute($statement, new Cassandra\ExecutionOptions(array('page_size' => 5000)));

$result = $connection->execute($statement); 

while ($result) 
{ 
    foreach ($result as $row) 
    {
    } 
    if ($result->isLastPage()) 
    { 
        $page_size=$page_size+1; break; 
    }  
    $result = $result->nextPage(); 
}


来源:https://stackoverflow.com/questions/48334281/pagination-in-apache-cassandra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!