如何从多个行键的cassandra中的计数器列获取值?

时间:2014-04-02 09:04:50

标签: java scala hector cassandra-cli column-family

我有一个具有多个计数器列的列族。现在我想用不同的行键来表示它们的值,像RangeSlicesQuery或MultigetSliceQuery这样的意思,我想在计数器列上应用,请在计数器列中给我。

2 个答案:

答案 0 :(得分:9)

它为我工作在java

MultigetSliceCounterQuery<String, String> query=HFactory.createMultigetSliceCounterQuery(keyspace, se, se);
query.setColumnFamily("MyCounters").setKeys(list).setRange(null, null, false, 3);
CounterRows<String,String> resultRows1 = query.execute().get();

for (CounterRow<String, String> row : resultRows1) {
    System.out.println("Row Key "+ row.getKey());
    for (HCounterColumn<String> col : row.getColumnSlice().getColumns())
        System.out.println("column Name "+col.getName()+"column value "+col.getValue());
    }
}

答案 1 :(得分:0)

根据您的 scala 标记

,如何在Scala中执行此操作
    val query = HFactory.createMultigetSliceCounterQuery(keyspaceName, se, se)
    query.setColumnFamily("counterFamily").setKeys(list).setRange(null, null, false,3)
    val resultRows = query.execute().get
    resultRows.map{row=>
      var countStatus = new scala.collection.immutable.HashMap[S, S]()
      row.getColumnSlice.getColumns.map{col=>
        countStatus += (col.getName -> col.getValue)
      }
      println(row.getKey -> countStatus)
    }