为什么“SELECT DISTINCT”在CQL3中不起作用?我在这里做错了什么?
请帮我解决此问题。根据CQL3文档,DISTINCT应该使用分区键。
[root@ip-10-12-75-197 /]# cqlsh
Connected to Test Cluster at localhost:9160.
[cqlsh 3.1.7 | Cassandra 1.2.11.2 | CQL spec 3.0.0 | Thrift protocol 19.36.1]
Use HELP for help.
cqlsh> use acks;
cqlsh:acks> describe table actest1;
CREATE TABLE actest1 (
id int,
phone int,
name text,
PRIMARY KEY (id, phone)
) WITH
bloom_filter_fp_chance=0.010000 AND
caching='KEYS_ONLY' AND
comment='' AND
dclocal_read_repair_chance=0.000000 AND
gc_grace_seconds=864000 AND
read_repair_chance=0.100000 AND
replicate_on_write='true' AND
populate_io_cache_on_flush='false' AND
compaction={'class': 'SizeTieredCompactionStrategy'} AND
compression={'sstable_compression': 'SnappyCompressor'};
cqlsh:acks> select * from actest1;
id | phone | name
----+-------+------
1 | 111 | ac1
2 | 111 | ac2
3 | 333 | ac2
cqlsh:acks> select distinct id from actest1;
Bad Request: line 1:16 no viable alternative at input 'id'
cqlsh:acks>
答案 0 :(得分:4)
您使用的CQLSH版本使用的是CQL 3.0.0,在3.1.1之前不能使用distinct。
来自手册
3.1.1
SELECT statement now allows listing the partition keys (using the DISTINCT modifier). See CASSANDRA-4536.
The syntax c IN ? is now supported in WHERE clauses. In that case, the value expected for the bind variable will be a list of whatever type c is.
It is now possible to use named bind variables (using :name instead of ?).