卡桑德拉SELECT查询的错误,排序依据

时间:2018-10-10 07:07:19

标签: cassandra

现在我正在使用Cassandra 3.11,遇到错误。

在SCHEMA下面是由Cassandra python驱动程序创建的我的cassandra模型。

CREATE TABLE motosense.collection (
    id uuid,
    created_at timestamp,
    accel_data blob,
    model_name text,
    rssi int,
    sensor_id int,
    sensor_version text,
    PRIMARY KEY (id, created_at) ) WITH CLUSTERING ORDER BY (created_at DESC)
    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 crc_check_chance = 1.0
    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 = '99PERCENTILE';
CREATE INDEX collection_sensor_id_idx ON motosense.collection (sensor_id);

创建上表并执行以下查询后,

SELECT id, created_at FROM calculated_collection WHERE sensor_id = 1 ORDER BY created_at DESC;

我收到此错误:

  

code = 2200 [Invalid query] message =“ ORDER BY with 2ndary index is not   支持。”

当我在没有order by的情况下执行查询时,会得到无序的数据查询集。 我该如何解决这个问题。

1 个答案:

答案 0 :(得分:1)

  

二级索引的设计不允许在   同一张桌子。您应该建立另一个满足您需求的表格   查询。作为二级索引查询,它可以从多个索引中提取数据   分区,它可能会排序,也可能不会排序(这就是为什么   二级索引查询不允许使用ORDER BY。

以上引用来自下面的链接。

您应该看一下,是同样的问题-ORDER BY with 2ndary indexes is not supported

这也与-Why Secondary Index ( = ?) and Clustering Columns (order by) CANNOT be used together for CQL Query?

有关