Question

Why "SELECT DISTINCT" is not working in CQL3? What am I doing wrong here?

Please help me to resolve this issue. As per CQL3 documentation DISTINCT should work with partition keys.

[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>
Était-ce utile?

La solution

The version of CQLSH you are using is utilizing CQL 3.0.0 and distinct is not available until 3.1.1.

From the manual

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 ?).

http://cassandra.apache.org/doc/cql3/CQL.html

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top