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

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

问题描述

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

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

我试着,我得到以下失败:

CassandraCQL :: Error :: InvalidRequestException:非交换列family的无效操作user_countework
我发现我必须使用比较器计数器,但我不能找到如何我可以设置与cassandra-cql宝石...有谁知道我可以得到这个工作吗?
下面是我的代码不工作...

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

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

  @@ 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)

您必须使用'update'来更改计数器值,没有计数器的插入语法(在CQL更新和插入中做同样的事情,所以你可以使用更新创建新行)。



目前,您不能在同一列系列中使用计数器和非计数器(来自 wiki :列族只包含计数器,或者根本没有计数器。)


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

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

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)

解决方案

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")

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).

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天全站免登陆