question

Tri avatar image
Tri asked Erick Ramirez answered

How are values in a timeUUIDs sorted?

From DS220 "Fundamentals Of An Apache Cassandra Table". A TimeUuid is a combination of 64 bits for the timestamp and 64 bits for an Uuid. I have also read about UUID Type 1 on https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_1_(date-time_and_MAC_address)

Q1: Let's assume a TIMEUUID column is used in a cluster key. What is the component (time or uuid) that drives the sorting? Is it ordered by time (chronologically) or ordered by the random Uuid?

Q2: From "Enough CQL To Get You Started" in DS220. It looks like video_id TIMEUUID contains bogus timestamp. `toTimestamp(video_id)` returns unrealistic data. Example below, row #3: a video_id value that contains a timestamp of 4319-02-17, which has no realistic meaning. Because the row has the column added_date = 2015-03-09. Does that mean TIMEUUID also generate a random timestamp?

SELECT video_id, toTimestamp(video_id), added_date, title FROM videos LIMIT 10;

video_id                             | system.totimestamp(video_id)    | added_date                      | title
--------------------------------------+---------------------------------+---------------------------------+---------------------------------------------------------------------------------------------------
 26461a70-14bd-11e5-ad08-8438355b7e3a | 2015-06-17 06:50:32.817000+0000 | 2014-05-06 19:00:00.000000+0000 |                                             Webinar: Building Blocks for the Future of Television
 2645e79c-14bd-11e5-a456-8438355b7e3a | 2015-06-17 06:50:32.815000+0000 | 2011-10-20 19:00:00.000000+0000 |            DataStax Cassandra Tutorials - Understanding partitioning and replication in Cassandra
 9056808b-ca65-1bfb-9957-3bea148dfdce | 4319-02-17 13:51:53.367004+0000 | 2015-03-09 00:00:02.000000+0000 |                                                                                Empire Promo - SNL
 264601a3-14bd-11e5-8c2e-8438355b7e3a | 2015-06-17 06:50:32.816000+0000 | 2011-12-29 19:00:00.000000+0000 |                Cassandra NYC 2011: Tyler Hobbs - Flexibility: Python Clients for Apache Cassandra
 fe3c4045-6f37-1223-81be-250dc60cffc8 | 2071-01-27 20:44:13.997000+0000 | 2015-01-16 22:46:44.000000+0000 |                                                      40 Years in the Making - Saturday Night Live
 2e8ecb4f-e92b-139b-8183-4df0e2a817bb | 2406-11-16 19:05:17.791000+0000 | 2015-04-24 00:00:41.000000+0000 |           Webinar: Don't leave your data in the dark - Optimize and simplify database performance
 2646123a-14bd-11e5-b9db-8438355b7e3a | 2015-06-17 06:50:32.816000+0000 | 2012-08-19 19:00:00.000000+0000 |                 C* 2012: Cassandra in Action - Solving Big Data Problems (Eddie Satterly, Splunk)
 bdb57288-e51c-1ff1-805d-c5f1e49c2c8b | 5223-09-01 17:39:16.080994+0000 | 2015-01-19 08:00:00.000000+0000 | Webinar | Streaming Big Data Analytics with Team Apache Spark & Spark Streaming, Kafka, Cassandra
 2646278f-14bd-11e5-88ea-8438355b7e3a | 2015-06-17 06:50:32.817000+0000 | 2012-04-26 19:00:00.000000+0000 |                             Webinar: Top 5 gotchas that prevent NoSQL from meeting business goals
 607df86e-2208-18a8-90aa-6d837c659f2f | 3559-06-27 11:59:36.475998+0000 | 2015-02-09 00:00:01.000000+0000 |                            Delegating User Authentication and Product Subscription to a 3rd Party


cassandra
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered

@Tri (1) Yes, you are correct. TimeUUIDs are sorted chronologically (based on the underlying timestamp), not the lexicographical order of the UUIDs.

(2) I see your point that they're not "real" data but video IDs just need to be random. But in the context of KillrVideo, the video ID is not used for time-based handling or sorting of any kind so there's nothing wrong with them being "bogus". Cheers!

Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.