apache cassandra 中的分页
Pagination in apache cassandra
Cassandra中的分页是怎么实现的,我理解通过发送最后收到的timestamp我们就可以实现了。除此之外,还有其他方法可以在 Cassandra 中实现分页吗?
此外,使用时间戳的限制是它只能帮助我们按插入顺序分页。
$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();
}
执行查询时可以传递页面状态的概念,查询将 return 结果以 "known state" 开头。 NodeJS 驱动程序在执行查询后公开为结果 returned 的 pageState
属性 - 您可以将此状态存储在用户的会话(或网页本身)中,并重新用于下一个请求,通过将其放入选项中,例如(从文档中窃取):
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 - 我相信它有更多关于页面状态的细节。
还有一些注意事项,例如,您不能跳转到任意页面,Cassandra 版本之间的状态不能 "compatible"(如果您进行滚动升级)等
Cassandra中的分页是怎么实现的,我理解通过发送最后收到的timestamp我们就可以实现了。除此之外,还有其他方法可以在 Cassandra 中实现分页吗?
此外,使用时间戳的限制是它只能帮助我们按插入顺序分页。
$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();
}
执行查询时可以传递页面状态的概念,查询将 return 结果以 "known state" 开头。 NodeJS 驱动程序在执行查询后公开为结果 returned 的 pageState
属性 - 您可以将此状态存储在用户的会话(或网页本身)中,并重新用于下一个请求,通过将其放入选项中,例如(从文档中窃取):
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 - 我相信它有更多关于页面状态的细节。
还有一些注意事项,例如,您不能跳转到任意页面,Cassandra 版本之间的状态不能 "compatible"(如果您进行滚动升级)等