1

我从示例中看到如何使用 Astyanax 更新计数器列并插入到复合列中。但我不知道如何做到这两点。

这是我在 CQL 3 中尝试做的事情

UPDATE column_family SET count = count + 1 WHERE col1='foo' AND col2='bar' AND col3='yo';

使用类似的架构

CREATE COLUMNFAMILY column_family (
   col1 varchar,
   col2 varchar,
   col3 varchar,
   count counter,
PRIMARY KEY (col1, col2, col3));

这是我必须更新复合列的要点

public void updateCount(String columnFamilyName , String rowKey , Counter rollup , int count) throws ConnectionException {


  try  {
  AnnotatedCompositeSerializer<Counter> entitySerializer = new AnnotatedCompositeSerializer<Counter>(Counter.class);
  MutationBatch mutation = keyspace.prepareMutationBatch();

   ColumnFamily<String, Counter> columnFamily
      = new ColumnFamily<String, Counter>(columnFamilyName, StringSerializer.get() , entitySerializer);
   mutation.withRow(columnFamily , rowKey).putColumn(rollup, count, null);

   mutation.execute();


  } catch (Throwable e){
    LOG.warn("update fail" , e);
  }

}
4

1 回答 1

0

肯定有一个 incrementCounterColumn 方法。我的代码通常看起来更像这样:

batch.withRow( ... ).incrementCounterColumn( ... );
于 2013-10-15T00:38:44.023 回答