主键列表上的 Cassandra 分页不起作用

发布于 2025-01-18 20:27:18 字数 1032 浏览 5 评论 0原文

我在使用 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:

database content

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

韶华倾负 2025-01-25 20:27:18

简单的原因是令牌是哈希函数,它可以从分区键中计算哈希值。因此,请给我公式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 formula gt>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 asking give keys whose token value is greater than token value of 13 and give 5 such keys. So the response is correct.

Partition keys cannot be ordered by normal partition keys of type(int,long etc)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文