Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to perform "not in" filter in cql3 query select?

Tags:

cassandra

cql3

I need to fetch rows without specific keys. for sample:

 select * from users where user_id not in ("mikko");

I have tried with "not in" and this is the response:

Bad Request: line 1:35 no viable alternative at input 'not'
like image 605
jezuz Avatar asked Aug 28 '13 21:08

jezuz


People also ask

How do you use not in clause in Cassandra?

"not in" is not a supported operation in CQL. Cassandra at its heart is still based on key indexed rows. So that query is basically the same as "select * from users", as you have to go through every row and figure out if it does not match the in.

How do I query NOT NULL in Cassandra?

How do I query in cassandra for != null columns. Select * from tableA where id != null; Select * from tableA where name !=

What is the use of allow filtering option in select query?

If your table contains for example a 1 million rows and 95% of them have the requested value, the query will still be relatively efficient and you should use ALLOW FILTERING. On the other hand, if your table contains 1 million rows and only 2 rows contain the requested value, your query is extremely inefficient.

How do I query NULL values in Cassandra?

You cannot query by nulls in Cassandra (like you can in a relational database), because: Cassandra requires all fields in the WHERE clause to be part of the primary key. Cassandra will not allow a part of a primary key to hold a null value.


1 Answers

"not in" is not a supported operation in CQL. Cassandra at its heart is still based on key indexed rows. So that query is basically the same as "select * from users", as you have to go through every row and figure out if it does not match the in. If you want to do that type of query you will want to setup a map reduce job to perform it.

When using Cassandra what you actually want to do is de-normalize your data model so that the queries you application performs end up querying a single partition (or just a few partitions) for their results.

Also find some great webinars and talks on Cassandra data modeling

  • http://www.youtube.com/watch?v=T_WRC_GjRd0&feature=youtu.be

  • http://youtu.be/x4Q9JeLIyNo

  • http://www.youtube.com/watch?v=HdJlsOZVGwM&list=PLqcm6qE9lgKJzVvwHprow9h7KMpb5hcUU&index=10

like image 66
Zanson Avatar answered Oct 19 '22 22:10

Zanson