Question

I was going through the tutorial where the instructor says that the default ordering of columns with in a row is UTF8-tye. But he does not touch upon it further.

I don't understand what it means. especially what if my columns are different types such as int, timestamp etc.

Also how would I specify the sort order on the columns to be something other than "UTF8-type".

Was it helpful?

Solution

He is talking about the columns names, not the columns values. In old cassandra versions you could use SuperColumns, which are collections of columns within a Row. Something like this:

{ RowKey: 
   { SuperColumn1Key: {c1:v, c2:v .... } },
   { SuperColumn2Key: {c1:v, c2:v .... } },
   { SuperColumn3Key: {c1:v, c2:v .... } }
}

It is something similar to what today is a wide row. The comparator could establish both the sorting of supercolumns within a row and also sorting of columns by their name (you could choose two differents comparator in a SuperColumnFamily, one for supercolumns sorting and another for columns sorting). For example using TimeUUID comparator for supercolumns you could retrieve them sorted by time while UTF8Type is an "alphabetic" sorting.

Imagine this row in an UTF8 Columns Comparator:

{ id: {"author":"john", "vote": 3} }

Now let's add a new column, say text. Since it's utf8, "text" ("a"<"t"<"v") will be between author and vote

{ id: {"author":"john", "text": "blablabla", "vote": 3} }

However I think what you've seen is an old video, since this concept is not used anymore in newer version

HTH, Carlo

OTHER TIPS

Short answer is: The default clustering order in Cassandra is ascending (ASC).

By default Cassandra tables with no clustering order specified are optimized for ascending SELECT queries. If you need to perform queries with descending queries you can specify a clustering order to store columns on disk in the reverse order of the DEFAULT.

The official documentation state this a little bit unclear for a quick reader (look out for the "default" magic keyword):

Ordering results

You can order query results to make use of the on-disk sorting of columns. You can order results in ascending or descending order. The ascending order will be more efficient than descending. If you need results in descending order, you can specify a clustering order to store columns on disk in the reverse order of the default. Descending queries will then be faster than ascending ones.

http://docs.datastax.com/en/cql/3.1/cql/cql_reference/create_table_r.html?scroll=reference_ds_v3f_vfk_xj__ordering-results

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top