Search code examples
cassandradatastaxdatastax-enterprise

DSE (Cassandra) - Range search on int data type


I am a beginner using Cassandra. I created a table with below details and when I try to perform range search using token, I am not getting any results. Am I doing something wrong or is it my understanding of data model?

enter image description here

enter image description here

Query select * from test where token(header)>=2 and token(header)<=4;


Solution

  • the token function calculates the token from the value based on the configured partitioner. The calculated value is the hash that is used to identify the node where the data is located, this is not a data itself.

    Cassandra can perform range search on values only on clustering columns (only for some designs) only inside the single partition. If you need to perform range on arbitrary column (also for partition keys), there is a DSE Search that allows you to index the table and perform different types of search, including range... But take into account that it will be much slower than traditional Cassandra queries.

    In your situation, you can run 3 queries in parallel (to cover values 2,3,4), like this:

    select * from test where header = value;
    

    and then combine results in your code.

    I recommend to take DS201 & DS220 courses on DataStax Academy to understand how Cassandra performs queries, and how to model data to make this possible.