Cassandra错误:“聚类密钥列必须按照指令”以聚类顺序与列完全匹配。

发布于 2025-01-27 08:07:29 字数 465 浏览 6 评论 0原文

我正在运行Cassandra查询,实际上是以前这样做的。但是现在我无法执行查询,它会引发错误:

    Cassandra error: InvalidRequest: Error from server: code=2200 [Invalid query] message="Clustering key columns must exactly match columns in CLUSTERING ORDER BY directive"

我的查询是:

    CREATE TABLE statistics(country_name text, dt date, confirmed_cases bigint, deaths bigint, 
    PRIMARY KEY(deaths))with clustering order by (deaths DESC);

请帮助!

I am running a cassandra query, actually previously done this. but now i can't execute the query, it throws error:

    Cassandra error: InvalidRequest: Error from server: code=2200 [Invalid query] message="Clustering key columns must exactly match columns in CLUSTERING ORDER BY directive"

My query is:

    CREATE TABLE statistics(country_name text, dt date, confirmed_cases bigint, deaths bigint, 
    PRIMARY KEY(deaths))with clustering order by (deaths DESC);

Please Help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

秋心╮凉 2025-02-03 08:07:29

之所以发生这种情况,是因为您仅指定了一个主键。单主键默认为分区键。因此,这里有两个问题:

  • 您需要定义聚类键。
  • 您正在尝试通过分区密钥执行订单。

这里有几个选择。但是,由于您想通过死亡订购,您可能应该将另一列指定为分区键。也许通过country_name分区?

...
PRIMARY KEY (country_name,deaths))
WITH CLUSTERING ORDER BY (deaths DESC);

请注意,然后您还需要/始终/始终通过country_name在中子句中的。

This is happening because you have only specified a single PRIMARY KEY. Single PRIMARY KEYs default to become partition keys. So two problems here:

  • You need to define a clustering key.
  • You're trying to enforce order by your partition key.

There are a couple of options here. But as you want to order by deaths, you probably should specify a different column as your partition key. Maybe partition by country_name?

...
PRIMARY KEY (country_name,deaths))
WITH CLUSTERING ORDER BY (deaths DESC);

The caveat, is then you would need to also/always filter by country_name in your WHERE clause.

纵性 2025-02-03 08:07:29

卡桑德拉(Cassandra)的主要键由一个或多个分区键和零或更多群集键组成组成。这些组件的顺序始终将分区密钥放在首位,然后将群集密钥放在首位。

在这种情况下,死亡列是一个分区键,而不是群集键,

例如,在以下查询结构名称1中是一个分区键,而name2是群集键。

 CREATE TABLE IF NOT EXISTS
 table(column name1 data type,
 column name2 data type,
 column name3 data type,   
 PRIMARY KEY(name1,name2))
 with clustering order by (name2 DESC);

在此处找到更多信息 cassandra keys

A primary key in Cassandra consists of one or more partition keys and zero or more clustering key components. The order of these components always puts the partition key first and then the clustering key.

deaths column in this case is a partition key and not a clustering key

For example in below query structure name1 is a partition key and name2 is the clustering key.

 CREATE TABLE IF NOT EXISTS
 table(column name1 data type,
 column name2 data type,
 column name3 data type,   
 PRIMARY KEY(name1,name2))
 with clustering order by (name2 DESC);

Find more information here Cassandra keys

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