0

Is there a way for me to use a custom comparator function for sorting the clustering key in cassandra.

My table definition is similar to following:

CREATE TABLE temp (user_id text, data_id int, data text, PRIMARY KEY(user_id, data_id));

Here, data_id will be used as the clustering column. I was wondering if I can define a custom comparator to dictate the order of data_id when written to disk.

Thanks for your help in advance :).

user1855193
  • 123
  • 3
  • 10
  • Covered here http://stackoverflow.com/questions/21427716/use-of-order-by-clause-in-cassandra, looks like this didn't change in the meantime. Is there some specific use case to do this? What is your access pattern? – Marko Švaljek Jan 31 '17 at 21:38
  • In my use case the data_id on its own doesn't define the any sensible order by simply applying asc or desc function to it. The data_id is a composite id containing multiple pieces. The ordering needs to take in consideration some of the encoded information in the data_id. Moreover, ordering function of data_id in one column family may be different then in another column family. – user1855193 Jan 31 '17 at 21:51
  • 1
    Usually if this data is composite in some way it should be split up at the application level and then sent to cassandra as it's supposed to be saved. Saving multiple values in one field was the pattern with older cassandra varsions. It's all about the access pattern so you have to prepare the data as you are going to access them. – Marko Švaljek Feb 01 '17 at 03:55

1 Answers1

0

This currently is not supported in cassandra to the bes tof my knowledge.

Please do refer to comments posted above to get an idea of what is the right approach.

user1855193
  • 123
  • 3
  • 10