Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any query for Cassandra as same as SQL:LIKE Condition?

The LIKE condition allows us to use wildcards in the where clause of an SQL statement. This allows us to perform pattern matching. The LIKE condition can be used in any valid SQL statement - select, insert, update, or delete. Like this

SELECT * FROM users WHERE user_name like 'babu%'; 

like the same above operation any query is available for Cassandra in CLI.

like image 588
BobDroid Avatar asked Mar 28 '12 10:03

BobDroid


People also ask

Is CQL like SQL?

CQL query language is a NoSQL interface that is intentionally similar to SQL, providing users who are comfortable with relational databases a familiar language that ultimately lowers the barrier of entry to Apache Cassandra.

Does Cassandra support SQL queries?

Cassandra provides a database query language called CQL (Cassandra Query Language) that is similar to SQL, but does not support the full set of SQL features supported by most relational database systems. Listed below are examples for how to write select, insert, update, and delete statements.

Which query language is used in Cassandra?

Cassandra Query Language (CQL) is a query language for the Apache Cassandra database. The Cassandra Query Language (CQL) is the primary language for communicating with the Apache Cassandra™ database. The most basic way to interact with Apache Cassandra is using the CQL shell, cqlsh.


1 Answers

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

For example:

CREATE TABLE cycling.cyclist_name (    id UUID PRIMARY KEY,    lastname text,    firstname text ); 

Creating the SASI as follows:

CREATE CUSTOM INDEX  fn_prefix ON cyclist_name (firstname) USING 'org.apache.cassandra.index.sasi.SASIIndex'; 

Then a prefix LIKE query is working:

SELECT * FROM cyclist_name WHERE firstname LIKE 'M%'; SELECT * FROM cyclist_name WHERE firstname LIKE 'Mic%'; 

These examples and more configuration options, like suffix queries, can be found in the documentation

A more in depth explanation about how SASI works can be found here.

like image 169
nstrelow Avatar answered Sep 19 '22 22:09

nstrelow