我在 cassandra 中有一个 CF,它有一个库类型映射
这个CF如下:
CREATE TABLE word_cat (
word text,
doc_occurrence map <text, int >,
total_occurrence map <text, int >,
PRIMARY KEY (word)
);
我想更新 doc_occurrence 以便键的值加上一个新数字。我想在一个查询中执行此操作。
我认为可以在这样的查询中完成:
UPDATE word_cat SET doc_occurrence ['key']=doc_occurrence ['key']+5 WHERE word='name';
但是它不起作用,任何人都可以帮忙吗?
最佳答案
最好用例子来解释,所以我只考虑你的模式。
现在我要插入一些数据,然后是输出
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
现在,如果您想覆盖 map 中已经存在的键(值为 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
更新:
您在评论中提到的功能是在 map 中包含一个计数器值。但不幸的是,集合中不允许使用计数器,我会说它还不受支持。 也许您可以有一个单独的计数器列系列来处理这些事情。
关于collections - 使用 cql3 在 cassandra 中更新 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16662052/