Tickon
Tickon

Reputation: 1068

How to list all unique components of a composite partition key - Cassandra

Given a table with a composite partition key like:

CREATE TABLE testtable (
column1 text,
column2 text,
column3 text,
column4 text,
column5 text,
column6 text,
PRIMARY KEY ((column1, column2, column3, column4))
)

How could I get all the unique values of only one partition column? Now, I know this doesn't work:

SELECT DISTINCT column2 from testtable;

However, I can do

SELECT DISTINCT column1, column2, column3, column4 from testtable;

So, is there a way (within CQL because the result of that query might be quite large) to query that query result like you would do in SQL? Something like this:

SELECT DISTINCT column2 FROM (SELECT DISTINCT column1, column2, column3, column4 from testtable);

Which doesn't work. Or do I really have to use Python (or other alternatives) for this?

Upvotes: 0

Views: 500

Answers (1)

Jan Dörrenhaus
Jan Dörrenhaus

Reputation: 6717

Simply put, there is no way to achieve this in CQL. The entirety of the partitioning key defines which Cassandra node is responsible for handling the data, and queries on it. Therefore, it always has to be given in its entirety.

Upvotes: 2

Related Questions