Collections 使用cql3在cassandra中更新地图
我在cassandra有一个CF,它有一个coulmn类型的映射 该CF如下所示:Collections 使用cql3在cassandra中更新地图,collections,cassandra,cql,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) ); 但是它不可能工作,有人能帮忙吗?最好用例子来解释,所以我只考虑你的模式 现在我在这里插入一些数据,然后是输
CREATE TABLE word_cat (
word text,
doc_occurrence map <text, int >,
total_occurrence map <text, int >,
PRIMARY KEY (word)
);
但是它不可能工作,有人能帮忙吗?最好用例子来解释,所以我只考虑你的模式 现在我在这里插入一些数据,然后是输出
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}
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