【问题标题】:CQL timeuuid comparison using maxTimeuuid / minTimeuuid使用 maxTimeuuid / minTimeuuid 比较 CQL timeuuid
【发布时间】:2015-08-28 18:06:05
【问题描述】:

我在 Mac OS X (dsc-cassandra-1.2.6) 上使用 Datastax cassandra 发行版。我想使用 timeuuid 类型,并且正在尝试对它们进行查询。

这是我的桌子:

CREATE TABLE test_t (
  canon_key text,
  t timeuuid,
  PRIMARY KEY (canon_key, t)
)

现在假设我得到了一条。

cqlsh:pagedb> select canon_key, t, dateOf(t), unixTimestampOf(t) from test_t where canon_key = 'xxx' and t >= minTimeuuid('2013-08-08 18:43:58-0700');                 
 canon_key | t                                    | dateOf(t)                | unixTimestampOf(t)

-----------+--------------------------------------+--------------------------+--------------------

       xxx | 287d3c30-0095-11e3-9268-a7d2e09193eb | 2013-08-08 18:43:58-0700 |      1376012638067

现在,我想删除这一行。我没有看到这样做的好方法,因为 timeuuid 类型没有相等运算符。

我添加的数据的性质是,我(可能)甚至不介意这样做:

cqlsh:pagedb> select canon_key, t, dateOf(t), unixTimestampOf(t) from test_t where canon_key = 'xxx' and t >= minTimeuuid('2013-08-08 18:43:58- 0700') 和 t

但根据文档 (http://cassandra.apache.org/doc/cql3/CQL.html#usingdates),这是行不通的。引用:“请注意 t >= maxTimeuuid('2013-01-01 00:05+0000') 仍然不会选择恰好在 '2013-01-01 00:05+0000' 生成的 timeuuid 并且基本上等同于t > maxTimeuuid('2013-01-01 00:05+0000')."。

那么..我该如何删除这一行?

【问题讨论】:

    标签: cassandra cql datastax-enterprise


    【解决方案1】:

    您的前提是错误的——minTimeuuidmaxTimeuuid 确实存在以允许在 timeuuids 上in进行相等操作,但这并不意味着不支持简单的相等:

    cqlsh:foo> insert into test_t (canon_key, t) values ('k', now());
    cqlsh:foo> select * from test_t;
    
     canon_key | t
    -----------+--------------------------------------
             k | 27609890-0209-11e3-b862-59d5a2b25b8f
    
    (1 rows)
    
    cqlsh:foo> delete from test_t where canon_key = 'k' and t = 27609890-0209-11e3-b862-59d5a2b25b8f;
    cqlsh:foo> select * from test_t;
    
    (0 rows)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-18
      • 2017-04-04
      • 1970-01-01
      • 2023-03-03
      • 2014-08-14
      • 2014-05-10
      • 1970-01-01
      相关资源
      最近更新 更多