我正在寻找代码示例来检索列族的所有行和所有列。就像是: SELECT * FROM MyTable 我看到这可以使用RangeSlicesQuery完成,但您仍然需要提供一定的范围。而且我想你也必须指定列名。有没有
SELECT * FROM MyTable
我看到这可以使用RangeSlicesQuery完成,但您仍然需要提供一定的范围。而且我想你也必须指定列名。有没有一个干净和安全的方式来做到这一点?
使用Hector 1.0和Cassandra 1.0。
尝试这样的东西:public class Dumper { private final Cluster cluster; private final Keyspace keyspace; public Dumper() { this.cluster = HFactory.getOrCreateCluster("Name", "hostname"); this.keyspace = HFactory.createKeyspace("Keyspace", cluster, new QuorumAllConsistencyLevelPolicy()); } public void run() { int row_count = 100; RangeSlicesQuery<UUID, String, Long> rangeSlicesQuery = HFactory .createRangeSlicesQuery(keyspace, UUIDSerializer.get(), StringSerializer.get(), LongSerializer.get()) .setColumnFamily("Column Family") .setRange(null, null, false, 10) .setRowCount(row_count); UUID last_key = null; while (true) { rangeSlicesQuery.setKeys(last_key, null); System.out.println(" > " + last_key); QueryResult<OrderedRows<UUID, String, Long>> result = rangeSlicesQuery.execute(); OrderedRows<UUID, String, Long> rows = result.get(); Iterator<Row<UUID, String, Long>> rowsIterator = rows.iterator(); // we'll skip this first one, since it is the same as the last one from previous time we executed if (last_key != null && rowsIterator != null) rowsIterator.next(); while (rowsIterator.hasNext()) { Row<UUID, String, Long> row = rowsIterator.next(); last_key = row.getKey(); if (row.getColumnSlice().getColumns().isEmpty()) { continue; } System.out.println(row); } if (rows.getCount() < row_count) break; } } public static void main(String[] args) { new Dumper().run(); } }
这将在100行的页面中查看列系列。它将只为每行提取10列(您也将要打印非常长的行)。
这是一个列系列,其中有uuids用于行键,用于列名称的字符串和值的长度。希望明白如何改变这一点。