Cassandra API equivalent to "SELECT ... FROM ... WHERE id IN (" ... "," ... "," ... ");

Assume the following:

id age city phone == === ==== ===== alfred 30 london 3281283 jeff 43 sydney 2342734 joe 29 tokyo 1283881 kelly 54 new york 2394929 molly 20 london 1823881 rob 39 sydney 4928381 

To get the next set of results.

 id age phone == === ===== alfred 30 3281283 joe 29 1283881 molly 20 1823881 

.. using SQL one will come out ..

 SELECT id, age, phone FROM dataset WHERE id IN ('alfred', 'joe', 'molly'); 

What is the corresponding Cassandra API call that will give the same result in the same command?

+4
source share
3 answers

CQL (Cassandra SQL-like query language) now supports this:

 SELECT ... WHERE keyalias IN ('key1', 'key2', 'key3', ...); 

http://cassandra.apache.org/doc/cql/CQL.html#Filteringrows

+1
source

you would do multiget_slice with keys alfred, joe and molly and SlicePredicate column_names id, age, phone

+4
source

The Cassandra equivalent can be modeled as described below:

 Users = { //this is a ColumnFamily "alfred": { //this is the key to this Row inside the CF "age":"30", "city":"london", "phone":"3281283" }, // end row // more rows... } 

where "alfred" is yours (row), and the row has three columns; age, city and phone. (We omit the timestamp field (for simplicity) for three columns)

+2
source

Source: https://habr.com/ru/post/1304122/


All Articles