开发者

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

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
==       ===  =====
a开发者_C百科lfred   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?


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


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)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜