【问题标题】:need a counter query which give all counter for a primary key using hector API需要一个计数器查询,它使用 hector API 为主键提供所有计数器
【发布时间】:2013-11-01 04:59:44
【问题描述】:

我正在为 cassandra 使用 hector API。

我创建一个如下所示的计数器表

 private void addColumnFamilyCounter(ThriftCluster cluster, String cfName, int rowCacheKeysToSave) {
    String cassandraKeyspace = this.env.getProperty("cassandra.keyspace");

    ThriftCfDef cfd =
            new ThriftCfDef(cassandraKeyspace, cfName, ComparatorType.UTF8TYPE);

    cfd.setRowCacheKeysToSave(rowCacheKeysToSave);
    cfd.setDefaultValidationClass(ComparatorType.COUNTERTYPE.getClassName());
    cluster.addColumnFamily(cfd);
}

然后像下面这样调用上面的方法

        addColumnFamilyCounter(cluster, COUNTER_CF, 0);

表格格式如下

        Primary key             columns
         Munich                 jingle : 1
                                mingle : 2
                                tingle : 1
                                pingle : 5

现在我想执行一个查询来获取慕尼黑下的所有列及其值。有什么办法可以得到所有的列。

到目前为止我所知道的是以下查询,但它只为我提供了主键和列键组合的值。

       @Override
public long getTagCounter(String domain, String tag) {
    CounterQuery<String, String> counter =
            new ThriftCounterColumnQuery<String, String>(keyspaceOperator,
                    StringSerializer.get(),
                    StringSerializer.get());

    counter.setColumnFamily(TAG_COUNTER_CF).setKey("p_key").setName("name");
    return counter.execute().get().getValue();
}

【问题讨论】:

    标签: cassandra hector


    【解决方案1】:

    好的,我自己找到了答案。希望对其他人有所帮助

    CounterSlice<String> query = HFactory.createCounterSliceQuery(keyspaceOperator , StringSerializer.get(), StringSerializer.get())
                .setColumnFamily("CF")
                .setKey("PK")
                .setRange(null, null, false, Integer.MAX_VALUE).execute().get();
    
        for(HCounterColumn<String> col : query.getColumns()){
                   log.info(col.getName());
                   log.info(col.getvalue());
         }
    

    【讨论】:

      猜你喜欢
      • 2012-10-08
      • 1970-01-01
      • 2016-05-30
      • 1970-01-01
      • 1970-01-01
      • 2012-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多