繁体   English   中英

如何使用Hector在Cassandra键空间/列家族中检索键列的名称?

[英]How do I retrieve the name of the key column in a Cassandra keyspace/columnfamily using Hector?

我想将Cassandra键空间/列家族行转换为JSON字符串。 我当前的代码(片段):

RangeSlicesQuery<K, N, V> rangeSlicesQuery = HFactory
    .createRangeSlicesQuery(this.keyspace, this.kSerializer, this.nSerializer, this.vSerializer)
    .setColumnFamily(this.columnFamily)
    .setRange(null, null, false, 100)
    .setRowCount(1000);

this.results = this.rangeSlicesQuery.execute();
this.resultRows = this.results.get();
this.resultRowsIterator = this.resultRows.iterator();

Row<K, N, V> row = this.resultRowsIterator.next();

从行中,我可以轻松获取所有列名称/值(我正在使用Jackson JSON API创建JSON):

List<HColumn<N, V>> columns = row.getColumnSlice().getColumns();

for(HColumn<N, V> column : columns) {
    node.put(column.getName().toString(), column.getValue().toString());
}
System.out.println(node.toString());

我的问题是,如何获取键列名称? 我知道我可以通过执行以下操作来获取行的键值:

row.getKey();

但是我还没有找到任何获取键列名称的方法,例如row.getKeyColumnName() 我尝试查看KeySpaceDefinition,ColumnFamilyDefinition,ColumnDefinition和ColumnFamilyTemplate。 他们似乎都不具备此功能(尽管也许可以针对模板运行查询?)

Thrift列族的行键没有显式名称。

如果您使用的是CQL表,则构成主键的列都有名称,但是Hector可能不适合访问它们,因为它是在CQL成为建模数据的主要方法之前开发的。 无论哪种情况,如果您使用的是Cassandra 1.2+,我都强烈建议您查看https://github.com/datastax/java-driver上的Datastax驱动程序。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM