主键列表上的 Cassandra 分页不起作用
我在使用 python 连接器的 cassandra 中分页时遇到问题。我想对主键列表进行分页。
这是表的架构:
client_data.store (
id text PRIMARY KEY,
"additionalCols" text,
format text,
name text
)
这是我在数据库中的内容:
我会喜欢通过过滤 id 从 1 到 15 来获得 5 行的页面。
我进行第一个查询:
stores = (
Store.Cql.objects.all()
.filter(id__in=[str(x) for x in range(1, 15)])
.limit(5)
)
我得到带有 id 的列:
['1', '10', '11', '12', '13']
我取最后一个元素,在本例中为“13”,然后我
last_element_pk = '13'
token = Token(last_element_pk)
stores = (
Store.Cql.objects.all()
.filter(id__in=[str(x) for x in range(1, 15)], pk__token__gt=(token))
.limit(5)
)
得到:
['1', '10', '11', '12', '14']
我不明白为什么我有共同的ID?!
我使用 cassandra:4.0.1, cassandra-driver = "^3.25.0"
谢谢你的帮助
I have a problem with the pagination in cassandra with python connector. I would like to paginate on a list of primary keys.
Here is the schema of the table:
client_data.store (
id text PRIMARY KEY,
"additionalCols" text,
format text,
name text
)
Here is what I have in database:
I would like to have pages of 5 rows by filtering on id from 1 to 15.
I make a first query :
stores = (
Store.Cql.objects.all()
.filter(id__in=[str(x) for x in range(1, 15)])
.limit(5)
)
and I get the columns with id :
['1', '10', '11', '12', '13']
I take the last element, in this case '13' then I do
last_element_pk = '13'
token = Token(last_element_pk)
stores = (
Store.Cql.objects.all()
.filter(id__in=[str(x) for x in range(1, 15)], pk__token__gt=(token))
.limit(5)
)
and I get :
['1', '10', '11', '12', '14']
I don't understand why I have common ids?!
I use cassandra:4.0.1, and cassandra-driver = "^3.25.0"
Thank you for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简单的原因是令牌是哈希函数,它可以从分区键中计算哈希值。因此,请给我公式
gt> 13
给我钥匙,然后说给我带有公式gt> doken(13)
的令牌是不同的。您无法订购分区键,因为它们从未按顺序存储。因此,根据发布的查询,您得到的是正确的。您正在问给出键的令牌值大于13
和的令牌值,给出5个这样的键
。因此响应是正确的。分区键不能通过类型的普通分区键(int,long等)订购
Simple reason is that token is hash function which calculates a hash value from the partition key. So saying give me key with formula
gt>13
and saying give me tokens with formulagt>token(13)
is different thing. You cannot order partition keys as they are never stored in serial order. So what you are getting is correct as per the query issued. You are askinggive keys whose token value is greater than token value of 13
andgive 5 such keys
. So the response is correct.Partition keys cannot be ordered by normal partition keys of type(int,long etc)