Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cassandra IN query not working if table has SET type column

Tags:

cassandra

cql

I am new to Cassandra. I got a issue in CQL IN query ,if table has SET type column it works.

CREATE TABLE test (
    test_date bigint, 
    test_id bigint, 
    caption text,
    PRIMARY KEY(test_date,test_id)
);

select * from test where test_date = 2022015 and test_id IN (1,2);

but if I add tags set in above then it gives error

CREATE TABLE test1 (
    test_date bigint, 
    test_id bigint, 
    tags set<text>,
    caption text,
    PRIMARY KEY(test_date,test_id)
);

select * from test1 where test_date = 2022015 and test_id IN (1,2);

code=2200 [Invalid query] message="Cannot restrict column "test_id" by IN relation as a collection is selected by the query"

like image 640
Navrattan Yadav Avatar asked Feb 02 '15 12:02

Navrattan Yadav


People also ask

How do I change the datatype of a column in Cassandra?

Changing the data type of a column after it is defined or added to a table using ALTER TABLE. Using ALTER TABLE, you can change the data type of a column after it is defined or added to a table.

How do I get data from a table in Cassandra?

SELECT clause is used to read data from a table in Cassandra. Using this clause, you can read a whole table, a single column, or a particular cell. Given below is the syntax of SELECT clause.

Can you add column to Cassandra table?

You can add a column in the table by using the ALTER command. While adding column, you have to aware that the column name is not conflicting with the existing column names and that the table is not defined with compact storage option.


1 Answers

I'm not sure why this restriction should apply particulary for collections. But in your case you can get around this issue by making the test_id part of your partition key:

PRIMARY KEY((test_date,test_id))

This will allow you to do IN queries as long as you specify the first part of the composite key (test_date).

like image 144
Stefan Podkowinski Avatar answered Oct 03 '22 08:10

Stefan Podkowinski