Cassandra cql 比较器类型计数器 [英] Cassandra cql comparator type counter

查看:21
本文介绍了Cassandra cql 比较器类型计数器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用以下代码更新字段...

i want to use the following code for updating a field...

@@db.execute("UPDATE user_count SET counters = counters + #{val} WHERE cid = 1 ")

我第一次尝试时失败了:
CassandraCQL::Error::InvalidRequestException:非交换列族 user_count 的无效操作
我发现我必须使用比较器计数器,但我找不到如何使用 cassandra-cql gem 设置它......有人知道我如何让它工作吗?下面是我的代码不起作用......

First time i tried that i got the following fail:
CassandraCQL::Error::InvalidRequestException: invalid operation for non commutative columnfamily user_count
I found out that i have to use the comparator counter, but i cant find how i can setup that with the cassandra-cql gem... does anybody know how i can get this to work? below there is my code that does not work ...

@@db.execute("CREATE COLUMNFAMILY user_count(cid varchar PRIMARY KEY, counters counter) with comparator = counter " )
@@db.execute("INSERT INTO user_count (cid, counters) VALUES (?,?)", 1, 0)

推荐答案

您需要设置 default_validation=CounterColumnType 而不是比较器.

You need to set default_validation=CounterColumnType instead of comparator.

@@db.execute("CREATE COLUMNFAMILY user_count(cid varchar PRIMARY KEY, counters counter) with default_validation=CounterColumnType")
@@db.execute("update user_count set counters = counters + 1 where cid = 1")

您必须使用更新"来更改计数器值,计数器没有插入语法(在 CQL 更新和插入中执行相同的操作,因此您可以 使用更新创建新行).

You must use 'update' to change the counter value, there is no insert syntax for counters (in CQL update and insert do the same thing so you can create new rows using update).

目前您不能在同一个列族中拥有计数器和非计数器(来自 wiki: "一个列族要么只包含计数器,要么根本不包含计数器.")

Currently you cannot have counters and non-counters in the same column family (from the wiki: "A column family either contains only counters, or no counters at all.")

这篇关于Cassandra cql 比较器类型计数器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆