chamibuddhika
chamibuddhika

Reputation: 1439

Fetching key range with common prefix in Cassandra

I want to fetch all rows having a common prefix using hector API. I played with RangeSuperSlicesQuery a bit but didn't find a way to get it working properly. Does key range parameters work with wild cards etc?

Update: I used ByteOrderedPartitioner instead of RandomPartitioner and it works fine with that. Is this the expected behavior?

Upvotes: 3

Views: 1844

Answers (2)

rs_atl
rs_atl

Reputation: 8985

To elaborate on the above answer, you should consider using column names as your "common prefix" instead of the key. Then you can either use a column slice to get all column names in a certain range, or you could use a secondary index then do an indexed slice for all keys with that column name.

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>    
  ...

Upvotes: 0

Tyler Hobbs
Tyler Hobbs

Reputation: 6932

Yes, that's the expected behavior. In RandomPartitioner, rows are stored in the order of the MD5 hash of their keys, so to get a meaningful range of keys, you need to use an order preserving partitioner like ByteOrderedPartitioner.

However, there are downsides to using ByteOrderedPartitioner or OrderPreservingPartitioner that you can usually avoid with a slightly different data model and RandomPartitioner.

Upvotes: 5

Related Questions