在cassandra cqlsh中,如何从表中选择map <ascii,ascii =“”>?

时间:2015-07-01 21:15:38

标签: cassandra cql3 cqlsh thrift-protocol

基本上这就是我的表格设置方式:

CREATE TABLE points (
  name ascii,
  id varint,
  attributes map<ascii, ascii>,
  PRIMARY KEY (name, id)
)

如果我运行以下SELECT语句,我会返回:

SELECT id, attributes from points limit 5;

   id | attributes
  ----+------------------------------------------
    1 | {STATION/Name: ABC, Type: 2, pFreq: 101}
    2 | {STATION/Name: ABC, Type: 1, pFreq: 101}
    3 | {STATION/Name: DEF, Type: 1, pFreq: 103}
    4 | {STATION/Name: GHI, Type: 2, pFreq: 105}
    5 | {STATION/Name: GHI, Type: 1, pFreq: 105}

我想要做的是能够根据属性内部的信息形成WHERE子句。类似于以下声明:

SELECT id FROM points WHERE name = 'NAME' AND attributes['pFreq'] = 101;

然而,当我运行此操作时,我收到以下错误:

Bad Request: line 1:56 no viable alternative at input '['

我看了this讨论,好像它还没有被支持,这是真的吗?或者有没有办法过滤属性信息?

以下是我正在使用的版本:

[cqlsh 4.1.1 | Cassandra 2.0.7 | CQL spec 3.1.1 | Thrift protocol 19.39.0]

1 个答案:

答案 0 :(得分:1)

是的,您可以使用CONTAINS:

SELECT * FROM points WHERE attributes CONTAINS 101;