Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative for OR condition after where clause in select statement Cassandra

Is it possible in Cassandra to use multiple conditions union ed together after the where clause in a select statement like in any of the RDBMS. Here is my code :

SELECT * from TABLE_NAME WHERE COND1= 'something' OR COND2 = 'something';  
like image 668
abhi Avatar asked Apr 13 '12 10:04

abhi


People also ask

How do you use in condition in Cassandra?

Using the SELECT command with the IN keyword. The IN keyword can define a set of clustering columns to fetch together, supporting a "multi-get" of CQL rows. A single clustering column can be defined if all preceding columns are defined for either equality or group inclusion.

How do I select distinct rows in Cassandra?

In cassandra you can only select the distinct records from Partition Key column or columns. If Partition key consists of multiple columns, you have to provide all of the columns otherwise you will get an error.

Can we use like operator in Cassandra?

Since Cassandra 3.4 (3.5 recommended), LIKE queries can be achieved using a SSTable Attached Secondary Index (SASI).

Which of the following are not allowed in a CQL query?

CQL does not support wildcard queries. CQL does not support Union, Intersection queries. Table columns cannot be filtered without creating the index. Greater than (>) and less than (<) query is only supported on clustering column.


2 Answers

Assuming COND is the name of your table's primary key, you can do:

SELECT * from TABLE_NAME WHERE COND1 in ('something', 'something');

So, there is no fully general OR operation, but it looks like this may be equivalent to what you were trying to do.

Remember, as you use CQL, that query planning is not meant to be one of its strengths. Cassandra code typically makes the assumption that you have huge amounts of data, so it will try to avoid doing any queries that might end up being expensive. In the RMDBS world, you structure your data according to intrinsic relationships (3rd normal form, etc), whereas in Cassandra, you structure your data according to the queries you expect to need. Denormalization is (forgive the pun) the norm.

Point is, CQL is intended to be a more familiar, friendly syntax for making Cassandra queries than the older Thrift RPC interface. It's not intended to be completely expressive and flexible the way that SQL is.

like image 113
the paul Avatar answered Oct 25 '22 07:10

the paul


Simple answer: there is no equivalent of OR

http://www.datastax.com/docs/0.8/dml/using_cql

Here is the command reference for v0.8:

http://www.datastax.com/docs/0.8/references/cql#cql-reference

SELECT [FIRST N] [REVERSED] FROM [USING ] [WHERE ] [LIMIT N];

..

The WHERE clause provides for filtering the rows that appear in results. The clause can filter on a key name, or range of keys, and in the case of indexed columns, on column values. Key filters are specified using the KEY keyword, a relational operator, (one of =, >, >=, <, and <=), and a term value. When terms appear on both sides of a relational operator it is assumed the filter applies to an indexed column. With column index filters, the term on the left of the operator is the name, the term on the right is the value to filter on.

like image 36
sdolgy Avatar answered Oct 25 '22 07:10

sdolgy