【问题标题】:How to get cassandra to filter correctly?如何让 cassandra 正确过滤?
【发布时间】:2016-06-26 06:38:36
【问题描述】:

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

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 时,过滤不起作用并且仍然返回完整集:

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

我理解的条件有误吗?

【问题讨论】:

    标签: cassandra cql cqlsh


    【解决方案1】:

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

    aploetz@cqlsh:stackoverflow> 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 > 部分以包含 +0000 的 GMT 偏移量,您应该会看到预期的结果。

    【讨论】:

    • 感谢 Aaron :) 添加时区偏移 +xxxx 后,我终于让它工作了。一件奇怪的事情是,我已经将本地时区更改为 GMT,但我仍然需要将 +0000 附加到时间戳。
    猜你喜欢
    • 1970-01-01
    • 2017-05-13
    • 2019-03-06
    • 2019-09-07
    • 2015-06-28
    • 2018-10-04
    • 2020-08-29
    • 2011-03-04
    • 1970-01-01
    相关资源
    最近更新 更多