Search code examples
cassandracqldatastax-enterprise

CQL timeuuid comparison using maxTimeuuid / minTimeuuid


I am using Datastax cassandra distribution on Mac OS X (dsc-cassandra-1.2.6). I want to use timeuuid types, and was experimenting with queries against them.

Here is my table:

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

Now lets say I get a row.

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

Now, I want to delete this row. I don't see a good way of doing it, because there is no equality operator for the timeuuid type.

The nature of the data I am adding is such that I (possibly) wouldn't even mind doing this:

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') and t <= maxTimeuuid('2013-08-08 18:43:58-0700');

But according to the documentation (http://cassandra.apache.org/doc/cql3/CQL.html#usingdates), that will not work. Quoting: " 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').".

So.. how do I delete this row?


Solution

  • Your premise is mistaken -- minTimeuuid and maxTimeuuid do exist to allow inequality operations on timeuuids, but that does not mean that simple equality is not supported:

    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)