我在CQL3控制台中创建一个表(没有单一的主键成分是独一无二的,他们一起将):卡桑德拉/赫:添加计数器上的复合主键
CREATE TABLE aggregate_logs (
bpid varchar,
jid int,
month int,
year int,
value counter,
PRIMARY KEY (bpid, jid, month, year));
这才得以更新和查询使用:
UPDATE aggregate_logs SET value = value + 1 WHERE bpid='1' and jid=1 and month=1 and year=2000;
这符合预期。我想要做的赫克托相同的更新(Scala中):
val aggregateMutator:Mutator[Composite] = HFactory.createMutator(keyspace, compositeSerializer)
val compKey = new Composite()
compKey.addComponent(bpid, stringSerializer)
compKey.addComponent(new Integer(jid), intSerializer)
compKey.addComponent(new Integer(month), intSerializer)
compKey.addComponent(new Integer(year), intSerializer)
aggregateMutator.incrementCounter(compKey, LogsAggregateFamily, "value", 1)
,但我得到一个错误与消息:
...HInvalidRequestException: InvalidRequestException(why:String didn't validate.)
运行查询直接从赫克托有:
val query = new me.prettyprint.cassandra.model.CqlQuery(keyspace, compositeSerializer, stringSerializer, new IntegerSerializer())
query.setQuery("UPDATE aggregate_logs SET value = value + 1 WHERE 'bpid'=1 and jid=1 and month=1 and year=2000")
query.execute()
它给我的错误:
InvalidRequestException(why:line 1:59 mismatched input 'and' expecting EOF)
我似乎还没有其他例子在复合主键下使用计数器。它甚至有可能吗?