0

我在 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)

我似乎没有任何其他在复合主键下使用计数器的示例。甚至可能吗?

4

2 回答 2

0

直接使用 cql 绝对是可能的(至少通过 CQLSH 和 C++):

cqlsh:goh_master> 描述表 daily_caps;
CREATE TABLE daily_caps (caps_type ascii, id ascii, value counter, PRIMARY KEY (caps_type, id) ) WITH COMPACT STORAGE AND comment='' AND
caching='KEYS_ONLY' AND read_repair_chance=0.100000 AND
gc_grace_seconds=864000 AND replicate_on_write='true' AND
compaction_strategy_class='SizeTieredCompactionStrategy' AND
compression_parameters:sstable_compression='SnappyCompressor';

cqlsh:goh_master> update daily_caps set value=value +1 where caps_type='xp' and id ='myid';

cqlsh:goh_master> select * from daily_caps;

大写字母 | 编号 | 价值

------------+------+------

经验 | 我的 | 1

于 2012-10-18T06:09:59.700 回答
0

CQL3 和 thrift API 不兼容。因此,使用 CQL3 创建列族并使用 Hector 或其他基于节俭的客户端访问它是行不通的。有关更多信息,请参阅:

https://issues.apache.org/jira/browse/CASSANDRA-4377

于 2012-10-18T15:19:41.493 回答