Amith Patil
Amith Patil

Reputation: 11

Cassandra: How to query primary key using mathematical operators like >,< which is of type text?

I have a table in Cassandra, whose primary key of type text(string) and stores only numbers. Now I want to perform CQL query on this column using mathematical operators like ><. Any idea on how to accomplish this?

select * from ynapanalyticsteam.df_tran_order_info where order_header_key>'2018';

Upvotes: 0

Views: 58

Answers (1)

Horia
Horia

Reputation: 2982

  1. why do you store it as text since your values are numbers?

  2. Cassandra has some important concepts: partition key and clustering key.

Let's say you have a table like this:

TABLE A (
  ...,
  PRIMARY KEY ((pk1, pk2), ck1, ck2, ck3, ck4, ck5)
)

pk1 and pk2 are the partition keys and your query must include them using =. The partition key it's used to determine the nodes to which the data belong.

The clustering columns (ck1, ck2, ..., ck5) are used for ordering the data and adding some other filtering using =, <, > operators. The clustering columns are used to control how data it's sorted in the partition.

You need to change your data model so order_header_key to be a clustering key and have another column to be your partition key.

Upvotes: 1

Related Questions