如果我们可以从 TimeUUID 中提取时间,那么在 Cassandra 中使用 timestamp 作为另一列是否有意义?
另外,我们如何从 TimeUUID 中提取时间并对其进行范围查询(例如 2016 年 1 月到 2016 年 5 月)?
SELECT toTimestamp(uuid_timestamp) FROM table
这不是问题,因为我正在将数据插入到熊猫数据框中进行分析。
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 inWHERE
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
andmaxTimeuuid
The
minTimeuuid
(resp.maxTimeuuid
) function takes atimestamp
valuet
(which can be either a timestamp or a date string) and return a faketimeuuid
corresponding to the smallest (resp. biggest) possibletimeuuid
having for timestampt
. 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
columnt
is strictly older than2013-01-01 00:05+0000
but strictly younger than2013-02-02 10:00+0000
. Please note thatt >= maxTimeuuid('2013-01-01 00:05+0000')
would still not select atimeuuid
generated exactly at2013-01-01 00:05+0000
and is essentially equivalent tot > maxTimeuuid('2013-01-01 00:05+0000')
.Warning: We called the values generated by
minTimeuuid
andmaxTimeuuid
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
, atimestamp
or adate
into another native type.