本文介绍了卡桑德拉(Cassandra)按第二个聚类键排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在cassandra中有一个表,我想按第二个聚类列排序并离开第一个聚类列.它是表的定义:

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);

,但我想按唯一的value2(而不是value1)对它进行排序.是否可以?有什么办法可以做到这一点?

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

推荐答案

不可能是开箱即用的-数据在分区内按层次结构进行排序-首先按第一个聚类列对数据进行排序,然后在每个唯一值"内进行排序父列",等等.(CL-群集列)如下:

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

这篇关于卡桑德拉(Cassandra)按第二个聚类键排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 09:13