Mateus Wolkmer
Mateus Wolkmer

Reputation: 735

Ordering in Cassandra

Yes, so I've been researching for some time and found out it is not uncommon for people to have problems with ordering data in Cassandra, but I still can't figure out why my selects are not being ordered in the right way. So here is my table creation query:

CREATE TABLE library.query1 (
    id int,
    gender text,
    surname text,
    email text,
    addinfo text,
    endid int,
    name text,
    phone int,
    PRIMARY KEY ((id), gender, surname, email)
) WITH CLUSTERING ORDER BY (gender DESC, surname DESC, email DESC);

As implicit, I want to order my data by gender > surname > email.

I then import data via CVN, as I'm importing data from PostgreSQL tables. Here's the SELECT I'm using:

SELECT id, gender, name, surname, phone, email
FROM library.query1;

Is there something I'm forgetting in the query for the ordering to be done, or is my modeling wrong?

Upvotes: 0

Views: 91

Answers (1)

Alex Tbk
Alex Tbk

Reputation: 2104

You could create a partition for male users for example. Then your ordering should work fine.

CREATE TABLE library.query1 (
    id int,
    gender text,
    surname text,
    email text,
    addinfo text,
    endid int,
    name text,
    phone int,
    PRIMARY KEY (gender, surname, email)
) WITH CLUSTERING ORDER BY (surname DESC, email DESC);

Upvotes: 1

Related Questions