How to retrieve the timestamp from cassandra?
Asked Answered
P

2

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, [email protected], timestamp=1335361733545850)
=> (column=age, value=23, timestamp=1335361733545850)
=> (column=password, value=MTIz, timestamp=1335361733545850)
Returned 4 results.
Elapsed time: 4 msec(s).
Parquetry answered 27/4, 2012 at 7:52 Comment(2)
Do you want to retrieve users by timestamp?Argillite
@ Fredrik LS: No in the UI i want to display the users detail with the Timestamp values.Parquetry
M
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.

Moynihan answered 2/5, 2012 at 22:34 Comment(3)
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.Moynihan
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 :)Moynihan
Update: this ticket was barely added, which proposes to make column timestamps and TTLs available to CQL: issues.apache.org/jira/browse/CASSANDRA-4217 . Not there yet, though.Moynihan
F
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;
Fortyfour answered 11/4, 2014 at 16:17 Comment(1)
Why it cant be possible to see timestamps for indexed columns?Chkalov
M
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.

Moynihan answered 2/5, 2012 at 22:34 Comment(3)
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.Moynihan
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 :)Moynihan
Update: this ticket was barely added, which proposes to make column timestamps and TTLs available to CQL: issues.apache.org/jira/browse/CASSANDRA-4217 . Not there yet, though.Moynihan

© 2022 - 2024 — McMap. All rights reserved.