cassandra - 按主分区分组
问题描述
我无法在主分区上执行 Group by。我正在使用 Cassandra 3.10。当我分组时,我收到以下错误。
InvalidReqeust: Error from server: code=2200 [Invalid query] message="Group by currently only support groups of columns following their declared order in the Primary Key
. 即使我仍然面临问题,我的列也是主键。
我的架构是
Table trends{
name text,
price int,
quantity int,
code text,
code_name text,
cluster_id text
uitime timeuuid,
primary key((name,price),code,uitime))
with clustering order by (code DESC, uitime DESC)
我运行的命令是:select sum(quantity) from trends group by code;
解决方案
首先,您的架构无效。您不能在代码上设置聚类顺序,因为它是分区键。顺序将由它的哈希确定(除非使用字节顺序分区器 - 但不要这样做)。
不过,您谈论的查询和事情确实有效。例如,您可以运行
> SELECT keyspace_name, sum(partitions_count) AS approx_partitions FROM system.size_estimates GROUP BY keyspace_name;
keyspace_name | approx_partitions
--------------------+-------------------
system_auth | 128
basic | 4936508
keyspace1 | 870
system_distributed | 0
system_traces | 0
他们的架构在哪里:
CREATE TABLE system.size_estimates (
keyspace_name text,
table_name text,
range_start text,
range_end text,
mean_partition_size bigint,
partitions_count bigint,
PRIMARY KEY ((keyspace_name), table_name, range_start, range_end)
) WITH CLUSTERING ORDER BY (table_name ASC, range_start ASC, range_end ASC)
您提供的伪模式可能与实际模式不同。describe table xxxxx
你能在你的问题中提供输出吗?
推荐阅读
- java - 清洁架构设计模式
- perl - 合并两个制表符分隔的文本文件
- android - 小部件没有出现,因为我在 android studio 中安排了它
- mysql - Codeigniter 3 对多列使用 db->like 会导致 SQL 相关错误
- python - Python:如何组合来自两个不同数据帧的特定列
- java - 将二进制资源传递给 JNI 层
- javascript - 错误:输入末尾的语法错误 - Nodejs 和 PostgreSQL (Heroku)
- hyperledger-fabric - 查询 Hyperledger Historian 的问题
- pycharm - 在 PyCharm 中可视化点文件
- c++ - 使用 stl 反转链表