Sort by creation date in Kassandra

I have a problem with the ordering data in the cassandra database . this is my table structure:

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)

and when I ran this request , I received the following message:

Request :

 select * from posts order by created_at desc;

message

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

Or this query returns data without sorting:

select * from posts
+4
source share
2 answers

The error message is pretty clear: you cannot, ORDER BYwithout limiting the request, by using a sentence WHERE. This is by design.

, WHERE, , , , . , :

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

token PARTITION KEY.

, , / .

+2

, , "id", "created_at".

, "id" ( Murmur3), , "created_at".

, , , - , . .

WHERE, ( case).

, . ,

* WHERE id = 1 order by created_at desc;

:

ORDER BY , ( "ASCending/DESCending" ) CLUSTERING ORDER .

, ,

* WHERE id = 1

http://www.datastax.com/dev/blog/we-shall-have-order

+3

Source: https://habr.com/ru/post/1660340/


All Articles