【问题标题】:Group by in CQL for Cassandra DB not working在 CQL 中对 Cassandra DB 进行分组无法正常工作
【发布时间】:2017-06-18 09:34:49
【问题描述】:

我在 Cassandra 键空间中有这张表:

create table hashtags(
id uuid,
text text,
frequence int,
primary key ((text), frequence, id))
with clustering order by (frequence desc, id asc);

所以我有text 作为分区键和frequence, id 作为集群键。 根据Cassandra documentationGROUP BY 操作的支持,我应该能够运行这种查询:

select text, sum(frequence) from hashtags 
group by text;

但我不断收到此错误:

com.datastax.driver.core.exceptions.SyntaxError:第 2:0 行在输入“组”处没有可行的替代方案(...文本,来自 [hashtags] 组的总和(频率)...)

我对指南有什么误解吗?如何正确运行此查询? 感谢您的帮助。

【问题讨论】:

  • 你使用的是哪个 cassandra 版本?

标签: cassandra


【解决方案1】:

它在 Apache Cassandra 3.10 上对我有用。我从 cqlsh 尝试过。

cqlsh:test> select * from hashtags ;

 text  | frequence | id
-------+-----------+--------------------------------------
 hello |         5 | 07ef8ee4-6492-4112-babb-fc3ac2893701
 hello |         4 | 3f6f3b1d-4a33-4a07-ad60-2274a9dc5577
 hello |         1 | 4adf7e2a-f3b9-41eb-85cf-f4c4bdc5d322
    hi |         7 | 71718f46-455e-4012-a306-f31f1cb2454a

(4 rows)
cqlsh:test> select text, sum(frequence) from hashtags group by text;

 text  | system.sum(frequence)
-------+-----------------------
 hello |                    10
    hi |                     7

(2 rows)

Warnings :
Aggregation query used without partition key

【讨论】:

猜你喜欢
  • 2011-10-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-03
  • 2021-03-21
  • 2018-06-05
  • 2015-07-04
  • 1970-01-01
相关资源
最近更新 更多