12

In the below cassandra, "get result"..we can able to retrieve the column name and values. But how to retrieve the timestamp..Is there any better idea to get the values by using timestamp

[default@sample]get user[bob];                                        
=> (column=name, value=bobdroid, timestamp=1335361733545850)
=> (column=email, value=bob@gmail.com, timestamp=1335361733545850)
=> (column=age, value=23, timestamp=1335361733545850)
=> (column=password, value=MTIz, timestamp=1335361733545850)
Returned 4 results.
Elapsed time: 4 msec(s).
BobDroid
  • 1,898
  • 5
  • 19
  • 39

2 Answers2

34

Just ran across this thread, and found that the answer is out of date. CQL now exposes the internal timestamps using the writetime() function:

select key,columnfoo,writetime(columnfoo) from tablebar;
Prahalad Gaggar
  • 11,389
  • 16
  • 53
  • 71
Peter Fales
  • 341
  • 3
  • 2
5

It's not recommended to use column Cassandra timestamps directly in client code; ideally, you should add your own timestamps in whatever form is most appropriate to your schema. But if you really want to, it can be done through the thrift interface (and, by extension, certain libraries using the thrift interface).

For the pycassa case, you just need to add include_timestamp=True to the arguments for your .get() call. For the CQL, cqlsh, and cassandra-cli cases, I believe there's totally no way to get the timestamp, sorry.

the paul
  • 8,972
  • 1
  • 36
  • 53
  • Yes. Twissandra (at least, the current version) uses Pycassa, not CQL. But more importantly, the timestamps it stores and uses are just explicit columns inserted by the app, and not the internal column timestamps. In the Userline and Timeline columnfamilies, the app's timestamps make up the column names, and the column values are tweet_ids. – the paul May 03 '12 at 17:31
  • Oh, and on that CQL doc you referenced, it's talking about working with the timestamp data type for app data, not internal column timestamps. I wrote that particular section of that doc, so I'm pretty sure :) – the paul May 03 '12 at 17:33
  • 3
    Update: this ticket was *barely* added, which proposes to make column timestamps and TTLs available to CQL: https://issues.apache.org/jira/browse/CASSANDRA-4217 . Not there yet, though. – the paul May 04 '12 at 17:25