使用cql3在cassandra中更新映射

时间:2013-05-21 04:15:21

标签: collections cassandra cql

我有cassandra的CF,有一个coulmn类型的地图

这个CF如下:

CREATE TABLE word_cat ( 
   word text, 
   doc_occurrence map <text, int >,
   total_occurrence map <text, int >,   
   PRIMARY KEY (word)
);

我想更新doc_occurrence,以便使用新number.i的密钥值的值在一个查询中执行此操作。

我认为可以在这样的查询中完成:

UPDATE word_cat SET doc_occurrence ['key']=doc_occurrence ['key']+5 WHERE word='name';

但它不起作用,任何身体都能帮忙吗?

1 个答案:

答案 0 :(得分:0)

最好用示例来解释,所以我只考虑你的架构。

现在我在这里插入一些数据,然后输出

cqlsh:ks1> update word_cat set
           ...  doc_occurrence=
           ...  {'cassandra' : 1}
           ...  where word ='name';
cqlsh:ks1> SELECT * FROM word_cat ;

 word | doc_occurrence | total_occurrence
------+----------------+------------------
 name | {cassandra: 1} |             null

现在,如果您想在地图中覆盖已存在的密钥(值为5的cassandra),那么就转到

cqlsh:ks1> update word_cat set
           ...  doc_occurrence=
           ...  {'cassandra' : 5}
           ...  where word ='name';

cqlsh:ks1> SELECT * FROM word_cat ;

 word | doc_occurrence | total_occurrence
------+----------------+------------------
 name | {cassandra: 5} |             null

<强>更新

您在评论中引用的功能包括地图中的计数器值。但遗憾的是,在集合中不允许使用计数器,我会说它还不支持。 也许你可以有一个单独的计数器列系列来处理这些事情。