collections - 使用 cql3 在 cassandra 中更新 map

标签 collections cassandra cql

我在 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/

相关文章:

java - subList() 与其他类似的 Collections 方法有不同的行为,一旦 subList 被改变

cassandra - 没有足够的副本可用于一致性 ONE 查询(需要 1 个,但只有 0 个活着)

postgresql - 从 PostgreSQL 到 Cassandra - 不支持聚合函数

索引上的 Cassandra IN 子句

cassandra - 主键相关的CQL3查询排序时的情况和错误

c# - C# 中的 Java WeakHashMap 类是否有等效项?

java - 我应该使用哪个集合来检查一个值是否在 100K 元素的集合中?

java - 创建具有唯一键和值的 HashMap asArrayList

linux - cassandra 开发人员广泛使用哪个版本的 Linux 服务器?

Cassandra 因任意命令而挂起