I'm trying to retrieve the data which the partition key value is odd from cassandra database.
Now I have table t with primary key p.
I tried
Select * from t where token(p)%2=1;
but I got the error message:
SyntaxException: line 1:44 no viable alternative at input '%' (...from videos_by_tag where token(tag)[%]...)
What can I do?
Cassandra does not support that kind of arithmetic operations, it is usually expected that this kind of operations are solved in the client, as explained here
The query that you are attempting to achieve has very low cardinality (only 2 values expected) which poses a great deal, as you will be effectively retrieving one half of all the information contained. This has been a challenge for a long time
There are no silver bullets to get this done, one option will be to add an additional column indicating if it is odd or even, and include it as part of the composite primary key, other option will be to have 2 separate tables, one for odd tokens, the other for even values.