【发布时间】:2013-09-30 22:01:08
【问题描述】:
短版:是否可以查询特定日期对应的所有timeuuid列?
更多细节:
我有一个表定义如下:
CREATE TABLE timetest(
key uuid,
activation_time timeuuid,
value text,
PRIMARY KEY(key,activation_time)
);
我已经用一行填充了它,如下(f0532ef0-2a15-11e3-b292-51843b245f21 是与日期 2013-09-30 22:19:06+0100 对应的 timeuuid):
insert into timetest (key, activation_time, value) VALUES (7daecb80-29b0-11e3-92ec-e291eb9d325e, f0532ef0-2a15-11e3-b292-51843b245f21, 'some value');
我可以按如下方式查询该行:
select activation_time,dateof(activation_time) from timetest where key=7daecb80-29b0-11e3-92ec-e291eb9d325e
结果如下(使用 cqlsh)
activation_time | dateof(activation_time)
--------------------------------------+--------------------------
f0532ef0-2a15-11e3-b292-51843b245f21 | 2013-09-30 22:19:06+0100
现在假设我的表中有很多数据,我想检索activation_time 对应于特定日期的所有行,比如2013-09-30 22:19:06+0100。
我本来希望能够查询 minTimeuuid('2013-09-30 22:19:06+0100') 和 maxTimeuuid('2013-09-30 22:19:06+0100') 之间所有 timeuuid 的范围,但这似乎不可能(以下查询返回零行):
select * from timetest where key=7daecb80-29b0-11e3-92ec-e291eb9d325e and activation_time>minTimeuuid('2013-09-30 22:19:06+0100') and activation_time<=maxTimeuuid('2013-09-30 22:19:06+0100');
看来我需要使用 hack 来增加查询中的第二个日期(增加一秒)来捕获行,即
select * from timetest where key=7daecb80-29b0-11e3-92ec-e291eb9d325e and activation_time>minTimeuuid('2013-09-30 22:19:06+0100') and activation_time<=maxTimeuuid('2013-09-30 22:19:07+0100');
这感觉不对。我错过了什么吗?有没有更清洁的方法来做到这一点?
CQL 文档讨论了 timeuuid functions,但它对带有 timeuuids 的 gte/lte 表达式非常短:
min/maxTimeuuid 示例选择 timeuuid 列 t 严格晚于 2013-01-01 00:05+0000 但严格早于 2013-02-02 10:00+0000 的所有行。 t >= maxTimeuuid('2013-01-01 00:05+0000') 不会选择恰好在 2013-01-01 00:05+0000 生成的 timeuuid,本质上等同于 t > maxTimeuuid('2013-01 -01 00:05+0000')。
附言以下查询也返回零行:
select * from timetest where key=7daecb80-29b0-11e3-92ec-e291eb9d325e and activation_time<=maxTimeuuid('2013-09-30 22:19:06+0100');
以下查询返回行:
select * from timetest where key=7daecb80-29b0-11e3-92ec-e291eb9d325e and activation_time>minTimeuuid('2013-09-30 22:19:06+0100');
【问题讨论】: