问题
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