Reputation: 29
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) ?
Upvotes: 0
Views: 911
Reputation: 3633
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.
Upvotes: 2