我想使用 hector API 获取所有具有公共前缀的行。我玩了一下 RangeSuperSlicesQuery,但没有找到让它正常工作的方法。键范围参数是否适用于通配符等?
更新:我使用了 ByteOrderedPartitioner 而不是 RandomPartitioner,它可以正常工作。这是预期的行为吗?
是的,这是预期的行为。在 RandomPartitioner 中,行按其键的 MD5 散列顺序存储,因此要获得有意义的键范围,您需要使用像 ByteOrderedPartitioner 这样的顺序保留分区器。
但是,使用ByteOrderedPartitioner 或 OrderPreservingPartitioner有一些缺点,您通常可以通过稍微不同的数据模型和 RandomPartitioner 来避免这些缺点。
要详细说明上述答案,您应该考虑使用列名作为“公共前缀”而不是键。然后您可以使用列切片来获取特定范围内的所有列名,或者您可以使用二级索引然后为具有该列名的所有键执行索引切片。
Column slice example:
Key (without prefix)
<prefix1> : <data>
<prefix2> : <data>
...
Secondary index example:
Key (with or without prefix)
"prefix" : <the_prefix> <-- this column is indexed
otherCol1 : <data>
...