我是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';
我是否理解错误的情况?
答案 0 :(得分:1)
不,你正确了解情况。但是在使用时间戳时,Cassandra假设您正在使用当地的GMT偏移量。当我运行您的上一个查询时,我根本不会返回任何行。但是当我指定GMT偏移量+0000
时,我得到一行。
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 >
部分,将GMT偏移量包含在+0000中,你应该看到预期的结果。