Cassandra order by second clustering key

放肆的年华 提交于 2021-01-29 09:35:58

问题


I have a table in cassandra and I want to order by the second clustering column and leave the first clustering column. It is the table definition:

CREATE TABLE table1 (
key int,
value1 text,
value2 text,
value3 text,
comments text,
PRIMARY KEY (key, value1, value2, value3)
)WITH CLUSTERING ORDER BY (value2 DESC);

I know that the above script is wrong and I should change it below:

CREATE TABLE table1 (
key int,
value1 text,
value2 text,
value3 text,
comments text,
PRIMARY KEY (key, value1, value2, value3)
)WITH CLUSTERING ORDER BY (value1 DESC, value2 DESC);

but I want to sort it by the only value2(and not the value1). Is it possible? Is there any way to achieve this?


回答1:


It's not possible out of box - data is sorted hierarchically inside the partition - first they are sorted by first clustering column, then sorted inside every unique value of "parent column", etc. Something like this (CL - clustering column):

partition key:
  CL1 value 1:
    CL2 value 1
    CL2 value 2
  CL1 value 2
    CL2 value 1
    CL2 value 3
  ...


来源:https://stackoverflow.com/questions/64624304/cassandra-order-by-second-clustering-key

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