如何让卡桑德拉正确过滤?

How to get cassandra to filter correctly?

我是 cassandra 的新手,目前正在试用 datastax 中的温度示例。 在示例中,我使用以下 DDL 创建了一个 table:

CREATE TABLE mykeyspace.temperature (
    weatherstation_id text,
    event_time timestamp,
    temperature text,
    PRIMARY KEY (weatherstation_id, event_time)
) WITH read_repair_chance = 0.0
   AND dclocal_read_repair_chance = 0.1
   AND gc_grace_seconds = 864000
   AND bloom_filter_fp_chance = 0.01
   AND caching = { 'keys' : 'ALL', 'rows_per_partition' : 'NONE' }
   AND comment = ''
   AND compaction = { 'class' : 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold' : 32, 'min_threshold' : 4 }
   AND compression = { 'chunk_length_in_kb' : 64, 'class' : 'org.apache.cassandra.io.compress.LZ4Compressor' }
   AND default_time_to_live = 0
   AND speculative_retry = '99PERCENTILE'
   AND min_index_interval = 128
   AND max_index_interval = 2048
   AND crc_check_chance = 1.0;

包含以下数据:

cqlsh> use mykeyspace;
cqlsh:mykeyspace> select * from temperature where weatherstation_id='1234ABCD'
              ... ;

 weatherstation_id | event_time               | temperature
-------------------+--------------------------+-------------
          1234ABCD | 2013-04-03 06:01:00+0000 |         72F
          1234ABCD | 2013-04-03 06:02:00+0000 |         73F
          1234ABCD | 2013-04-03 06:03:00+0000 |         73F
          1234ABCD | 2013-04-03 06:04:00+0000 |         74F
          1234ABCD | 2013-04-03 06:05:00+0000 |         72F
          1234ABCD | 2013-04-03 07:01:00+0000 |         72F

但是,当我 运行 以下 cql 时,过滤不起作用,仍然 return 完整集:

select * from temperature where weatherstation_id='1234ABCD' and event_time > '2013-04-03 06:05:00';

我是不是理解错了?

不,您理解正确。但是在使用时间戳时,Cassandra 假定您使用的是本地 GMT 偏移量。当我 运行 您的最后一个查询时,我根本没有返回任何行。但是当我指定 +0000 的 GMT 偏移量时,我得到一行。

aploetz@cqlsh:Whosebug> SELECT * FROM temperature 
    WHERE weatherstation_id='1234ABCD' AND event_time > '2013-04-03 06:05:00+0000';

 weatherstation_id | event_time               | temperature
-------------------+--------------------------+-------------
          1234ABCD | 2013-04-03 07:01:00+0000 |         72F

(1 rows)

改变您的 eventime > 部分以包括 GMT 偏移量 +0000,您应该会看到预期的结果。