cassandra - Strange behavior of timeuuid comparison -
cassandra - Strange behavior of timeuuid comparison -
i have cassandra 2.x cluster 3 nodes , db scheme this:
cqlsh> create keyspace test_ks replication = {'class': 'simplestrategy', 'replication_factor': 3} , durable_writes = true; cqlsh> create table if not exists test_ks.test_cf ( ... time timeuuid, ... user_id varchar, ... info varchar, ... primary key (time, user_id) ... ) compression = {'sstable_compression': 'lz4compressor'} , compaction = {'class': 'leveledcompactionstrategy'}; lets add together info (wait time betweeb inserts):
cqlsh> insert test_ks.test_cf (time, user_id, info) values (now(), 'user1', 'pythonista'); cqlsh> insert test_ks.test_cf (time, user_id, info) values (now(), 'user1', 'mr. haskell'); lets @ our data:
cqlsh> select dateof(time), user_id, info test_ks.test_cf; dateof(time) | user_id | info --------------------------+---------+------------- 2014-06-24 16:00:31+0700 | user1 | mr. haskell 2014-06-24 15:59:32+0700 | user1 | pythonista (2 rows) i unusual results while querying test_cf cf:
cqlsh> select dateof(time) test_ks.test_cf user_id='user1' , token(time) >= token(maxtimeuuid('2014-06-24 16:00:31+0700')) allow filtering; dateof(time) -------------------------- 2014-06-24 15:59:32+0700 (1 rows) cqlsh> select dateof(time) test_ks.test_cf user_id='user1' , token(time) >= token(maxtimeuuid('2014-06-24 16:00:32+0700')) allow filtering; dateof(time) -------------------------- 2014-06-24 15:59:32+0700 (1 rows) cqlsh> select dateof(time) test_ks.test_cf user_id='user1' , token(time) >= token(maxtimeuuid('2014-06-24 16:00:33+0700')) allow filtering; dateof(time) -------------------------- 2014-06-24 16:00:31+0700 2014-06-24 15:59:32+0700 (2 rows) as can see comparing gives wrong results, although, timeuuid must not greater maxtimeuuid , must greater 'mintimeuuid' (for same datetime, of course of study =) ). explain me unusual behavior?
tia!
first off, primary key backwards—if want perform queries this, create table statement should this:
create table if not exists test_ks.test_cf ( time timeuuid, user_id varchar, info varchar, primary key (user_id, time) ) compression = {'sstable_compression': 'lz4compressor'} , compaction = {'class': 'leveledcompactionstrategy'}; that makes user_id partition key , time clustering column, fits query pattern.
with change, no longer need utilize token function, needed create range queries on partition keys, meaningless clustering columns (and not correspond semantic ordering of column values). since time clustering column, need normal comparison:
select dateof(time) test_ks.test_cf user_id='user1' , time >= maxtimeuuid('2014-06-24 16:00:31+0700'); you can drop allow filtering, since you're doing standard range piece rather token comparison, required scanning rows , making comparison.
cassandra cql3 cassandra-2.0 cqlsh
Comments
Post a Comment