Search code examples
cql3cassandra-2.0

default sorting order of columns in cassandra?


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".


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