Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

sguzzo avatar image
sguzzo asked Erick Ramirez answered

Why are rows out-of-order in the result set?

I don't understand why my rows are not ordered as I specified during table creation with the clustering columns. I have a table defined as

CREATE TABLE streaming_test.test_payload_by_sensor (
    sensor_id uuid,
    date date,
    timestamp timestamp,
    altitude decimal,
    ...
    ...
    ...
    PRIMARY KEY ((sensor_id, date), timestamp)
) WITH CLUSTERING ORDER BY (timestamp DESC)

However, I see the values:

sensor_id date timestamp
sensor001 2021-10-03 2021-10-03 11:55:00.000000+0000
sensor001 2021-10-12 2021-10-12 10:45:00.000000+0000
sensor001 2021-10-12 2021-10-12 10:35:00.000000+0000
sensor001 2021-10-12 2021-10-12 10:30:00.000000+0000

Shouldn't the first value be last?

clustering key
1 comment
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

The data posted comes from a query with `ALLOW FILTERING`, so withouth a partition specified. This is the reason of the "error"!

0 Likes 0 ·

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered

As you already worked out, the issue lies in the query filtered on the clustering column without the partition key.

Queries with ALLOW FILTERING uses a scatter-gather approach where all the partitions are checked the results are displayed in the order that replicas returned them. Cheers!

Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.