TimeUUID与Cassandra中的timestamp有什么区别?

5

如果我们可以从 TimeUUID 中提取时间,那么在 Cassandra 中使用 timestamp 作为另一列是否有意义?

另外,我们如何从 TimeUUID 中提取时间并对其进行范围查询(例如 2016 年 1 月到 2016 年 5 月)?

3个回答

1
我遇到了这个问题,并在查询期间进行了转换。
SELECT toTimestamp(uuid_timestamp) FROM table

这不是问题,因为我正在将数据插入到熊猫数据框中进行分析。


1
https://cassandra.apache.org/doc/4.0/cassandra/cql/cql_singlefile.html#timeuuidFun中:

Timeuuid functions

now

The now function takes no arguments and generates, on the coordinator node, a new unique timeuuid (at the time where the statement using it is executed). Note that this method is useful for insertion but is largely non-sensical in WHERE clauses. For instance, a query of the form

SELECT * FROM myTable WHERE t = now()

will never return any result by design, since the value returned by now() is guaranteed to be unique.

minTimeuuid and maxTimeuuid

The minTimeuuid (resp. maxTimeuuid) function takes a timestamp value t (which can be either a timestamp or a date string) and return a fake timeuuid corresponding to the smallest (resp. biggest) possible timeuuid having for timestamp t. So for instance:

SELECT * FROM myTable WHERE t > maxTimeuuid('2013-01-01 00:05+0000') AND t < minTimeuuid('2013-02-02 10:00+0000')

will select all rows where the timeuuid column t is strictly older than 2013-01-01 00:05+0000 but strictly younger than 2013-02-02 10:00+0000. Please note that t >= maxTimeuuid('2013-01-01 00:05+0000') would still not select a timeuuid generated exactly at 2013-01-01 00:05+0000 and is essentially equivalent to t > maxTimeuuid('2013-01-01 00:05+0000').

Warning: We called the values generated by minTimeuuid and maxTimeuuid fake UUID because they do no respect the Time-Based UUID generation process specified by the RFC 4122. In particular, the value returned by these 2 methods will not be unique. This means you should only use those methods for querying (as in the example above). Inserting the result of those methods is almost certainly a bad idea.

Time conversion functions

A number of functions are provided to “convert” a timeuuid, a timestamp or a date into another native type.

Functions table


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接