Table :
CREATE TABLE TEST_PAYLOAD
(
TIME_STAMP timestamp,
TYPE text,
PRIMARY KEY (TIME_STAMP)
);
time_stamp | type
--------------------------+----------
2013-05-15 00:00:00-0700 | sometext
2013-05-16 00:00:00-0700 | sometext
2013-05-17 00:00:00-0700 | sometext
SELECT * FROM TEST_PAYLOAD WHERE TIME_STAMP>='2013-05-15 00:00:00-0700';
code=2200 [Invalid query] message="Only EQ and IN relation are supported on the partition key (unless you use the token() function)"
it doesn't work for > or any range selection while it works for = as far index is concerned it has only one primary key there is no partition key.Why it asks for token().
i Would like to retrieve relative range can be only date or date with time not specific timestamp exist in db.
The Cassandra partition key's primary goal is to query data efficiently and evenly distribute data across a cluster. It is always the first value in the definition of the primary key. A composite partition key is used to combine more than one column value to form a single partition key.
In this article, we learned that Cassandra uses a partition key or a composite partition key to determine the placement of the data in a cluster. The clustering key provides the sort order of the data stored within a partition. All of these keys also uniquely identify the data.
Often, your first venture into using Cassandra involves tables with simple primary keys. Keep in mind that only the primary key can be specified when retrieving data from the table. If an application needs a simple lookup table using a single unique identifier, then a simple primary key is the right choice.
I guess you are bit confused about the Cassandra terminology.
Please refer here
partition key: The first column declared in the PRIMARY KEY definition
ie, when you create a table like this
CREATE TABLE table {
key1,
key2,
key3,
PRIMARY KEY (key1, key2, key3)
}
key1
is called the partition key and key2
, key3
are called clustering keys.
In your case you don't have clustering keys, so the single primary key which you declared became the partition key.
Also range queries ( < , >) should be performed on clustering keys.
If you don't have any other candidates for primary key, i think you should remodel your table like this
CREATE TABLE TEST_PAYLOAD
(
BUCKET varchar,
TIME_STAMP timestamp,
TYPE text,
PRIMARY KEY (BUCKET, TIME_STAMP)
);
For BUCKET you can provide the year or year&month combination. So your keys would look like these 2013, 2014, 06-2014, 10-2014 etc.
So while querying go to the desired bucket and do range scans like TIME_STAMP >= '2013-05-15 00:00:00-0700'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With