default sorting order of columns in cassandra?

痞子三分冷 提交于 2019-12-10 20:24:59

问题


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


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/25086648/default-sorting-order-of-columns-in-cassandra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!