【发布时间】:2015-03-15 17:36:24
【问题描述】:
我想将 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。他们似乎都没有这种能力(尽管也许有一个可以针对模板运行的查询?)
【问题讨论】:
-
行由它们的键标识,列由它们的名称标识。也许您可以澄清“关键列”名称的含义?
-
包含 KEY 值的列的名称。例如,它可以是“id”或“UUID”——它不存在于我的命令生成的 HColumn 的值中。
标签: java json cassandra cql hector