Cassandra错误:“聚类密钥列必须按照指令”以聚类顺序与列完全匹配。
我正在运行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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
之所以发生这种情况,是因为您仅指定了一个主键。单主键默认为分区键。因此,这里有两个问题:
这里有几个选择。但是,由于您想通过
死亡
订购,您可能应该将另一列指定为分区键。也许通过country_name
分区?请注意,然后您还需要/始终/始终通过
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:
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 bycountry_name
?The caveat, is then you would need to also/always filter by
country_name
in yourWHERE
clause.卡桑德拉(Cassandra)的主要键由一个或多个分区键和零或更多群集键组成组成。这些组件的顺序始终将分区密钥放在首位,然后将群集密钥放在首位。
在这种情况下,死亡列是一个分区键,而不是群集键,
例如,在以下查询结构名称1中是一个分区键,而name2是群集键。
在此处找到更多信息 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.
Find more information here Cassandra keys