加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

按创建日期排序在Cassandra

发布时间:2020-12-14 04:31:06 所属栏目:大数据 来源:网络整理
导读:我在cassandra数据库中订购数据有问题. 这是我的表结构: CREATE TABLE posts ( id uuid,created_at timestamp,comment_enabled boolean,content text,enabled boolean,meta maptext,text,post_type tinyint,summary text,title text,updated_at timestamp,u
我在cassandra数据库中订购数据有问题.
这是我的表结构:

CREATE TABLE posts (
    id uuid,created_at timestamp,comment_enabled boolean,content text,enabled boolean,meta map<text,text>,post_type tinyint,summary text,title text,updated_at timestamp,url text,user_id uuid,PRIMARY KEY (id,created_at)
) WITH CLUSTERING ORDER BY (created_at DESC)

当我运行此查询时,我收到以下消息:

查询:

select * from posts order by created_at desc;

信息:

ORDER BY is only supported when the partition key is restricted by an EQ or an IN.

或者此查询返回数据而不进行排序:

select * from posts

解决方法

错误消息非常明确:您不能在不使用WHERE子句限制查询的情况下进行ORDER BY.这是设计的.

在没有WHERE子句的情况下运行时获得的数据实际上是按顺序排序的,而不是使用群集密钥,而是将token function应用于分区键.您可以通过以下方式验证订单:

SELECT token(id),id,created_at,user_id FROM posts;

其中token函数参数与PARTITION KEY完全匹配.

我建议你阅读this和this以了解你能做什么/不能做什么.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读