I see what is going on. You are using now()
to generate a time-UUID. But when you convert that to a timestamp
using dateOf()
you are truncating the milliseconds off of it. Therefore querying for a received_time
equal to 2014-09-24 18:56:55+0400 will yield nothing, as the timestamp
type is still stored with the milliseconds (you just can't see it due to your dateOf()
).
The best way to go about this, is to store your times as timeuuid
s (NOTE: I left received_date
as a timestamp just for purposes of the example). Then use the dateOf
when you SELECT
, and use the minTimeuuid()
function for your WHERE
clause:
CREATE TABLE entity_data2 (
received_date timestamp,
entity text,
received_time timeuuid,
node int,
PRIMARY KEY ((received_date, entity), received_time));
INSERT INTO entity_data2 (received_date, entity, received_time , node)
VALUES ('2014-09-24 00:00:00+0400','NA',now(),0);
aploetz@cqlsh:stackoverflow> SELECT * FROM entity_data2
WHERE received_date = '2014-09-24 00:00:00+0400' AND entity = 'NA'
AND received_time>minTimeuuid('2014-10-08 08:13:53-0500')
AND received_time<minTimeuuid('2014-10-08 08:13:54-0500');
received_date | entity | received_time | node
--------------------------+--------+--------------------------------------+------
2014-09-23 15:00:00-0500 | NA | f3b548b0-4eec-11e4-9d05-7991a041665c | 0
(1 rows)
aploetz@cqlsh:stackoverflow> SELECT received_date, entity, dateof(received_time), node
FROM entity_data2 WHERE received_date = '2014-09-24 00:00:00+0400' AND entity = 'NA'
AND received_time>minTimeuuid('2014-10-08 08:13:53-0500')
AND received_time<minTimeuuid('2014-10-08 08:13:54-0500');
received_date | entity | dateof(received_time) | node
--------------------------+--------+--------------------------+------
2014-09-23 15:00:00-0500 | NA | 2014-10-08 08:13:53-0500 | 0
(1 rows)
Basically the dateOf()
function was designed to be used for querying data, not storing it. Here is a blog posting that describes (in more detail) how to make this work:
Time series based queries in Cassandra 1.2+ and CQL3