Charlie Parker
Charlie Parker

Reputation: 5189

How do you retrieve sorted values in a Cassandra table quickly?

I was going through the following tutorial:

http://www.ebaytechblog.com/2012/07/16/cassandra-data-modeling-best-practices-part-1/#terms

and in one of the explanation is the following picture:

enter image description here

It says that rows are sorted by row key and columns are sorted by column key.

Does that mean that the columns are sorted by column value and the row keys are sorted by row value? For example if I had the row 1 having values 10,2,30,4 (all ints), it would sort the columns for that key as 2, 4, 10, 30?

Similarly for the rows, if we had, 11, 22, 3, 44, it would sort the rows as, 3, 11, 22, 44?

I am just confused what it means that its sorted by columns.

The reason I am interested in clarifying this is because if I could have the values I am inserting sorted already, that would be very convenient for me, because I would not have to insert a sorted list in on of the columns.

Upvotes: 2

Views: 849

Answers (2)

Mikhail Stepura
Mikhail Stepura

Reputation: 3374

Rows (physical/internal) are generally not stored in the sorted order in the column family. It can be achieved by using OrderedPartitioner, but that's not advised for a production. So, rule of thumb - don't rely on the order of rows

The cells (internal columns) are physically stored in the sorted order within a physical row. They are ordered by their names, not values.

Or in terms of CQL: you can't order CQL rows by a partition key, but you can order CQL rows within a single partition using clustering columns

http://cassandra.apache.org/doc/cql3/CQL.html#createTablepartitionClustering

Upvotes: 0

Don Branson
Don Branson

Reputation: 13707

I take it to mean that the rows are sorted by the value of the row key, and the columns are sorted by the value of the key, not the value of what's stored. That is, for example in the case of columns, key1/value5, key2/value3, key3/value1, and so forth.

Upvotes: 1

Related Questions