我在 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;
这按预期工作。我想在 Hector(在 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)
我似乎没有任何其他在复合主键下使用计数器的示例。甚至可能吗?