sirdan
sirdan

Reputation: 1028

Group by in CQL for Cassandra DB not working

I have this table in a Cassandra keyspace:

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

So I have text as partition key and frequence, id as clustering key. According to Cassandra documentation regarding the support for GROUP BY operations, I should be able to run this sort of query:

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

But I keep getting this error:

com.datastax.driver.core.exceptions.SyntaxError: line 2:0 no viable alternative at input 'group' (...text, sum(frequence) from [hashtags] group...)

Is there something I misunderstood from the guide? How can I run correctly this query? Thanks for helping.

Upvotes: 0

Views: 2557

Answers (1)

Arun Joy Thekkiniyath
Arun Joy Thekkiniyath

Reputation: 884

It worked for me on Apache Cassandra 3.10. I tried from 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

Upvotes: 1

Related Questions