【问题标题】:"ORDER BY is only supported when the partition key is restricted by an EQ or an IN." cassandra“仅当分区键受 EQ 或 IN 限制时,才支持 ORDER BY。”卡桑德拉
【发布时间】:2019-08-14 13:37:42
【问题描述】:

我已经创建了这样的表..

CREATE TABLE test1.mytest (
    id text,
    year text,
    time bigint,
    crtby text,
    data text,
    postid text,
    upby text,
    PRIMARY KEY ((id, year), time)
) WITH CLUSTERING ORDER BY (time DESC)


我想根据时间键对我的数据进行排序。


SELECT * FROM test1.mytest WHERE id ='b' ORDER BY time asc ALLOW FILTERING ;

当我尝试上面的命令时,我得到了

InvalidRequest: Error from server: code=2200 [Invalid query] message="ORDER BY is only supported when the partition key is restricted by an EQ or an IN."

【问题讨论】:

    标签: database-design cassandra


    【解决方案1】:

    错误清楚地描述了失败的原因。您的主键是 idyear,然后在 time 键上进行进一步的聚类。

    Cassandra 需要知道 idyear,然后才能在 time 之前下订单。

    由于您并不总是在查询中使用分区键(id、年份),因此要按时间排序,您将不得不使用物化视图。更多详细信息可以找到here

    【讨论】:

      猜你喜欢
      • 2018-04-05
      • 2021-11-22
      • 1970-01-01
      • 2017-10-30
      • 2012-03-29
      • 2014-12-28
      • 2017-05-08
      • 2015-10-19
      • 2015-03-04
      相关资源
      最近更新 更多