分区内的Cassandra分页 [英] Cassandra pagination inside partition

查看:108
本文介绍了分区内的Cassandra分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何对分区内的数据进行分页?我不能为此使用令牌,所以我用创建时间创建了微时间字段并通过它对记录进行了排序.现在,我使用'<'分割数据和>",这对我的查询有很多限制.有更好的方法吗?

解决方案

对于前向分页,大多数驱动程序(我对Java& Node.js绝对了解)都具有获取当前的分页状态" ,并将其设置为cookier(或页面的隐藏表单参数),并在用户单击下一步"按钮时将其还原,以便您可以检索下一页.

向后分页比较棘手,但也可行-基本上,您需要将聚簇键的值存储在上一页中输出的第一条记录的某个位置,然后执行类似select * from table where partition_key = value and clustering_column > value的查询. /p>

How can I paginate data inside partition? I can`t use token for this, so I made microtime field with creation time and ordered records by it. Now I am slicing data using '<' and '>' and it makes a lot of constraints for my queries. Is there better way to do this?

解决方案

For forward pagination, most of drivers (I definitely know about Java & Node.js) have notion of paging. You're basically execute your query, but set fetch size to value of number of entries that you want to have on page. You can grab current "paging state" and set it into cookier, or hidden form parameter of the page, and restore it when user clicks on "next" button, so you can retrieve next page.

Backward paging is more tricky, but is also doable - basically, you need to store somewhere the value of the clustering key(s) for first record that you output on previous page, and then execute query like select * from table where partition_key = value and clustering_column > value.

这篇关于分区内的Cassandra分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆