UUID and timeuuid functions
About using Timeuuid functions.
Cassandra 2.0.7 and later includes the uuid() function. This function
takes no parameters and generates a random Type 4 UUID suitable for use in
INSERT or SET statements.
Several timeuuid() functions are designed for use with the
timeuuid() type:
dateOf()Used in a
SELECTclause, this function extracts the timestamp of atimeuuidcolumn in a result set. This function returns the extracted timestamp as a date. UseunixTimestampOf()to get a raw timestamp.now()In the coordinator node, generates a new unique
timeuuidin milliseconds when the statement is executed. The timestamp portion of thetimeuuidconforms to the UTC (Universal Time) standard. This method is useful for inserting values. The value returned bynow()is guaranteed to be unique.minTimeuuid()andmaxTimeuuid()Returns aUUID-like result given a conditional time component as an argument. For example:SELECT * FROM myTable WHERE t > maxTimeuuid('2013-01-01 00:05+0000') AND t < minTimeuuid('2013-02-02 10:00+0000')The min/maxTimeuuid example selects all rows where the
timeuuidcolumn,t, is strictly later than 2013-01-01 00:05+0000 but strictly earlier than 2013-02-02 10:00+0000. The t >= maxTimeuuid('2013-01-01 00:05+0000') does not select atimeuuidgenerated exactly at 2013-01-01 00:05+0000 and is essentially equivalent to t > maxTimeuuid('2013-01-01 00:05+0000').The values returned by
minTimeuuidandmaxTimeuuidfunctions are not trueUUIDs in that the values do not conform to the Time-BasedUUIDgeneration process specified by the RFC 4122. The results of these functions are deterministic, unlike thenow()function.unixTimestampOf()Used in a
SELECTclause, this functions extracts the timestamp in milliseconds of atimeuuidcolumn in a result set. Returns the value as a raw, 64-bit integer timestamp.
timeuuid and timestamp
functions to manipulate dates. The functions can be used in INSERT,
UPDATE, and SELECT statements.toDate(timeuuid)Converts
timeuuidtodatein YYYY-MM-DD format.toTimestamp(timeuuid)Converts
timeuuidtotimestampformat.toUnixTimestamp(timeuuid)Converts
timeuuidtoUNIX timestampformat.toDate(timestamp)Converts
timestamptodatein YYYY-MM-DD format.toUnixTimestamp(timestamp)Converts timestamp to UNIX timestamp format.
toTimestamp(date)Converts
datetotimestampformat.toUnixTimestamp(date)Converts
datetoUNIX timestampformat.
CREATE TABLE sample_times (a int, b timestamp, c timeuuid, d bigint, PRIMARY KEY (a,b,c,d));
INSERT INTO sample_times (a,b,c,d) VALUES (1, toUnixTimestamp(now()), 50554d6e-29bb-11e5-b345-feff819cdc9f, toTimestamp(now()));
SELECT toDate(c) FROM sample_times;
