如何使用cassandra的timestamp列作为WHERE条件执行查询

Che*_*eng 1 cassandra

我有以下Cassandra表

cqlsh:mydb> describe table events;

CREATE TABLE mydb.events (
    id uuid PRIMARY KEY,
    country text,
    insert_timestamp timestamp
) WITH 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'}
    AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99.0PERCENTILE';
CREATE INDEX country_index ON mydb.events (country);
CREATE INDEX insert_timestamp_index ON mydb.events (insert_timestamp);
Run Code Online (Sandbox Code Playgroud)

如您所见,已在insert_timestamp列上创建索引.

我通过了/sf/answers/1308887051/

我虽然以下是正确的查询

cqlsh:mydb> select * from events where insert_timestamp >= '2016-03-01 08:27:22+0000';
InvalidRequest: code=2200 [Invalid query] message="No secondary indexes on the restricted columns support the provided operators: 'insert_timestamp >= <value>'"

cqlsh:mydb> select * from events where insert_timestamp >= '2016-03-01 08:27:22+0000' ALLOW FILTERING;
InvalidRequest: code=2200 [Invalid query] message="No secondary indexes on the restricted columns support the provided operators: 'insert_timestamp >= <value>'"
Run Code Online (Sandbox Code Playgroud)

但是,使用country列查询WHERE条件确实有效.

cqlsh:mydb> select * from events where country = 'my';

id                                   | country | insert_timestamp
--------------------------------------+---------+--------------------------
53167d6a-e125-46ff-bacf-f5b267de0258 |      my | 2016-03-01 08:27:22+0000
Run Code Online (Sandbox Code Playgroud)

任何想法为什么查询时间戳作为条件不起作用?我的查询语法有什么问题吗?

doa*_*hai 9

任何想法为什么查询时间戳作为条件不起作用?我的查询语法有什么问题吗?

Native Cassandra二级索引限于=谓词.要启用不等式谓词,您需要添加ALLOW FILTERING但它将执行完整的群集扫描 :-(

如果您能够等待几周,Cassandra 3.4将发布新的SASI二级索引,这对于范围查询更有效:https://github.com/apache/cassandra/blob/trunk/doc/ SASI.md