【问题标题】:map update in cassandra with cql3使用 cql3 在 cassandra 中更新地图
【发布时间】:2013-05-15 18:01:13
【问题描述】:

我在 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';

但它不起作用,任何机构可以帮忙吗?

【问题讨论】:

    标签: collections cassandra cql


    【解决方案1】:

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

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

    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
    

    更新:

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

    【讨论】:

    • 不,我想用新值加上现有键的值。在这个例子中,cassandra 的值变成 1+5=6 {cassandra:6}
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-28
    • 2015-05-06
    • 2013-06-30
    • 2013-07-13
    • 2013-04-11
    • 1970-01-01
    • 2013-11-03
    相关资源
    最近更新 更多