Hector查询列族中的所有数据

时间:2012-08-03 05:10:46

标签: cassandra hector

我想用hector api编写一个代码,它给我带来了一些像我得到select * from table的结果 是否有可能在Cassandra.please中尽快回复

2 个答案:

答案 0 :(得分:2)

取决于ColumnFamily

的结构

使用columSlice和StringSerializer的示例可能是:

ColumnSlice<String, String> result = HFactory.createSliceQuery(ksp, stringSerializer, stringSerializer, stringSerializer)
            .setKey(row)
            .setRange(startColumn, endColumn, false, limit)
            .setColumnFamily(columnFamily)
            .execute().get();

    List<HColumn<String, String>> columns = result.getColumns();

答案 1 :(得分:0)

SliceQuery不会在列家族中提供所有行,因为它需要行键。要获取列族的所有行,请使用rangeSliceQuery,其中键和范围为null

RangeSlicesQuery<Object, Object, Object> rangeQuery =    HFactory.createRangeSlicesQuery(keyspace, keySerializer,
            nameSerializer, valueSerializer);
rangeQuery.setColumnFamily(cf);
rangeQuery.setRange(null, null, false, MAX_COL);
rangeQuery.setKeys(null, null);
rangeQuery.setRowCount(rowCount);//Greater than count(*)
QueryResult<OrderedRows<Object, Object, Object>> result = rangeQuery.execute();