我从示例中看到如何更新计数器列并插入到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);
}
}
答案 0 :(得分:0)
肯定有incrementCounterColumn方法。我的代码通常看起来更像这样:
batch.withRow( ... ).incrementCounterColumn( ... );