Cassandra API相当于“SELECT ... FROM ... WHERE id IN('...','...','...');”

时间:2010-03-15 08:45:10

标签: nosql cassandra

假设以下数据集:

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

获得以下结果集..

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

..使用SQL会发出..

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

在一个命令中产生相同结果集的相应Cassandra API调用是什么?

3 个答案:

答案 0 :(得分:4)

你会做一个带有alfred,joe和molly的密钥的multiget_slice,以及带有id,age,phone的SlicePredicate column_names

答案 1 :(得分:2)

Cassandra等效物可以如下所述建模:

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...
}

其中“alfred”是你的(行)键,行有三列;年龄,城市和电话。 (省略了三列的时间戳字段(为简单起见))

答案 2 :(得分:1)

CQL(Cassandra的类SQL查询语言)现在支持:

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

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