java Cassandra 2 Hector:复合行键上的范围切片查询返回空行
我们正在使用ByteOrderedPartitioner为一个新项目存储时间序列,cql3对我们来说只是暂时的好消息,然后我们选择Hector继续,但现在我们的范围查询不起作用
C*版本:2.0.7
赫克托版本:1.0-5
模式:
ColumnFamilyDefinition cfd = HFactory.createColumnFamilyDefinition(
keyspaceName, columnFamilyName,
ComparatorType.UTF8TYPE);
cfd.setComparatorTypeAlias("(IntegerType,IntegerType,IntegerType)");
cfd.setKeyValidationClass("CompositeType(IntegerType,IntegerType,IntegerType)");
cfd.setDefaultValidationClass(ComparatorType.UTF8TYPE.getClassName());
罗基:100:20:11
=>;(名称=列1,值=AAL,时间戳=1401745673543000)
=>;(名称=第2列,值=纽约市,时间戳=1401745673543002)
罗基:100:20:12
=>;(名称=列1,值=AAL,时间戳=1401745673543000)
=>;(名称=列2,值=TXA,时间戳=1401745673543002)
等等
查询以迭代cassandra列族的所有行
Composite startComposite = new Composite();
startComposite.addComponent(0,100,EQUAL);
startComposite.addComponent(1,20,EQUAL);
startComposite.addComponent(2,11,EQUAL);
Composite endComposite = new Composite();
endComposite.addComponent(0,100,EQUAL);
endComposite.addComponent(1,20, EQUAL);
endComposite.addComponent(2,18,GREATER_THAN_EQUAL);
int rowCount = 100;
RangeSlicesQuery<Composite, String, String> rangeSlicesQuery = HFactory
.createRangeSlicesQuery(ksp, CompositeSerializer.get(), StringSerializer.get(), StringSerializer.get())
.setColumnFamily(columnFamilyName)
.setRange("", "", false, rowCount);
rangeSlicesQuery.setKeys(startComposite, endComposite);
QueryResult<OrderedRows<Composite, String, String>> result = rangeSlicesQuery.execute();
System.out.println(result.get());
获取空行:
行({})
# 1 楼答案
这是一个卡桑德拉反模式。使用ByteOrderedPartitioner几乎没有什么好的理由,而这种模式不是其中之一。最终,所有写入和查询实际上都会命中一个节点(或少量节点,具体取决于集群大小)
Cassandra中有许多时间序列数据模型的好例子Here is one from Datastax