Cassandra API equivalent of “SELECT … FROM … WHERE id IN ('…', '…', '…');”

时光总嘲笑我的痴心妄想 提交于 2019-12-07 09:08:44

问题


Assume the following data set:

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 following result set ..

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

.. using SQL one would issue ..

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

What is the corresponding Cassandra API call that would yield the same result set in one command?


回答1:


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

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

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




回答2:


you would do a multiget_slice w/ keys of alfred, joe, and molly, and SlicePredicate column_names of id, age, phone




回答3:


A Cassandra equivalent could be modelled 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 your (row) key and the row has three columns; age, city and phone. (Omitted the timestamp field (for simplicity) for the three columns)



来源:https://stackoverflow.com/questions/2445878/cassandra-api-equivalent-of-select-from-where-id-in

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!