Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

specify cqlsh output timezone

I have a table in cassandra with a datatype of timestamp. i am using cqlsh to get data out of the database and wanted to change the output format for how my timestamp column output looks like. I researched around and found that i can change the timestamp output format by making changes to the following file:

  • ~/.cassandra/cqlshrc

But i learnt that the only change i can make is the time elements, i cannot make the output to display my timestamps in a different timezone(say UTC). It always displays the timestamps in my local timezone.

I wanted to know if there is a way i could make cqlsh display timestamp in my desired time zone, or atleast in UTC zone.
Any help or pointers are appreciated.

I'm using the following versions:
cqlsh 4.1.1 | Cassandra 2.0.6 | CQL spec 3.1.1

Thanks

like image 782
Neeraj B. Avatar asked Oct 27 '14 19:10

Neeraj B.


2 Answers

You can change your environment variable to get show timezone:

TZ=America/Los_Angeles cqlsh -k mpj `hostname` -e 'select time from userbehavior limit 3'

 time
--------------------------
 2015-02-15 21:17:03-0800
 2015-02-15 18:16:21-0800
 2015-02-15 00:04:52-0800

(3 rows)

and:

TZ=UTC cqlsh -k mpj `hostname` -e 'select time from userbehavior limit 3'

 time
--------------------------
 2015-02-16 05:17:03+0000
 2015-02-16 02:16:21+0000
 2015-02-15 08:04:52+0000

(3 rows)
like image 171
C.B. Avatar answered Sep 28 '22 01:09

C.B.


The cqlshrc timeout option configures the output format of database objects using Python strftime syntax according to http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/cqlsh.html. I haven't verified that these strftime directives work, but if you're willing to experiment try using the strftime() directive %z (UTC offset in the form +HHMM or -HHMM and %Z (time zone name). See https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior.

like image 23
catpaws Avatar answered Sep 28 '22 01:09

catpaws