Select Cassandra cql collation

If I define a table like this using cql:

CREATE TABLE scores ( name text, age int, score int, date timestamp, PRIMARY KEY (name, age, score) ); 

And do SELECT in cqlsh as follows:

 select * from mykeyspace.scores; 

The displayed result is always sorted by "age", then "rating" automatically in ascending order, regardless of the order of data entry (as expected, the return lines are not sorted by the key in the "name" section). I have the following questions:

  • SELECT automatically sorts returned rows with clustering keys?
  • If so , what is the purpose of using the ORDER BY when using SELECT ?
  • If not , how to get returned rows for sorting using clustering keys, since cql does not allow ORDER BY on select * ?
+7
cassandra cql cqlsh
source share
1 answer

Your clustering columns determine the order (in your case age , then score )

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

In a given physical node, the rows for a given partition key are stored in the order caused by the clustering columns, which makes finding rows in this clustering order particularly effective (see SELECT).

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

The ORDER BY parameter allows you to select the order of the returned results. The argument is a list of column names along with the order for the column (ASC for ascending and DESC for descendant, omitting the order equivalent to ASC). Currently, the possible orders are limited (which depends on the CLUSTERING ORDER table):

  • if the table was defined without any specific CLUSTERING ORDER, then the allowed orders are the order caused by the clustering columns and the reverse.
  • otherwise, the valid orders are the order of the CLUSTERING ORDER options and vice versa.
+10
source share

All Articles