简体   繁体   中英

How can I get all rows in Cassandra between a given Composite key range?

My data storage format is:

RowKey: a:b:c
=> ( counter=d:e:f:g, value=1)
where,
 a: Timestamp (Format : YYYYMMDDHH, HH varies from 00 - 23)
 b: encoded Url
 c: id (Varies from 0 - 9)

 d: string type
 e: floating value
 f: floating value
 g: integer type

I want't to fetch all such rows (with their included columns), where url = given value from entire column family where c is from 00 - 23.

How can accomplish that in Java (Preferably with Hector client) ?

This is not possible in Cassandra. The CompositeKeys are quite simple and basically just turn the separate parts into one key. As such, the data is stored (and sorted) in cassandra in order of its Keys and this is how it is retrieved.

You will only be able to do range/slice queries on the whole of the composite key (a:b:c) and this is sorted firstly by a, then by b, then c. If you want to be able to do range queries on c, then you will need to store your data with the composite key in the form c:a:b - in this case you will not be able to do range queries on a and b alone.

You have two options here:

1) Use a relational database (probably not a good solution here) 2) Duplicate the data. So have two rows for your data - one where the CompositeKey is a:b:c, and the other where the CompositeKey is c:a:b (and a third b:c:a if you need to do range/slice queries sorting on b only). The data itself will be the same for all two (/three) of these rows, and you can search the appropriate row based on the query that you want. Unfortunately this is one of the drawbacks of Cassandra, but necessary to accomplish the BigData model.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM