Unable to query timestamp column in Cassandra

1,676 views
Skip to first unread message

Priya Ch

unread,
Dec 10, 2015, 4:01:31 AM12/10/15
to spark-conn...@lists.datastax.com
Hi All,

   I have the following situation - 

 From my spark streaming job, I am inserting value into timestamp column (row_timestamp) as (2015-12-10 12:50:55+0530). I query as -

select * from <table> where row_timestamp = '2015-12-10 12:50:55'.

The above query doesn't return any rows.

I insert another row with timestamp value as 2015-12-10 00:00:00

now if i query as select * from <table> where row_timestamp = '2015-12-10 00:00:00'.
this would return return rows now.

Where does the difference lie ??

Regards,
padma CH

Shashwat Rastogi

unread,
Jan 12, 2016, 5:34:16 AM1/12/16
to spark-conn...@lists.datastax.com
Try giving the timezone also while querying data. Time internally is saved as a 64 bit long value, so whatever value you insert into Cassandra is converted and saved as a long number. When you query your data back, the query date parameter must be converted to the exactly same long value to fetch correct result. Hence, timezone is required too.

A similar example: Do not insert timestamp values as now() because when you will query back you will also have to give the precise millisecond value which will usually be lost unless you explicitly save it. Example:

Inline image 1

But, when you specify the exact value for timestamp then it works, because by default it takes 000 ms. 

Inline image 2

I am guessing, in your case a similar thing is happening when you don't give timezone value.

--
You received this message because you are subscribed to the Google Groups "DataStax Spark Connector for Apache Cassandra" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spark-connector-...@lists.datastax.com.



--
Shashwat Rastogi
Software Engineer
Amadeus Software Labs
Bangalore
+91-7022-25-0604
Reply all
Reply to author
Forward
0 new messages