Cassandra中的列排序 [英] Columns ordering in Cassandra

查看:256
本文介绍了Cassandra中的列排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在CQL中创建表时,是否有必要对primary_key和 NOT 聚类列中 NOT 的列的顺序进行精确设置:

When I create a table in CQL, is it necessary to be exact for the order of column that are NOT in the primary_key and NOT clustering columns :

CREATE TABLE user (
    a ascii,
    b ascii,
    c ascii,
    PRIMARY KEY (a)
);

是否等于?

CREATE TABLE user (
    a ascii,
    c ascii, <-- switched
    b ascii, <-- switched
    PRIMARY KEY (a)
);

感谢您的帮助

推荐答案

这两个语句都将失败,因为:

Both of those statements will fail, because of:


  • 多余的逗号。

  • 您尚未提供主键定义。

假设您已修复了这些错误,则答案仍然是是的,他们是一样的。

Assuming you had those fixed, then the answer is still "yes they are the same."

Cassandra在表创建时将自己的顺序应用于您的列。在我键入该表时考虑它:

Cassandra applies its own order to your columns at table creation time. Consider this table as I have typed it:

CREATE TABLE testorder ( 
  acolumn text,
  jcolumn text,
  dcolumn text,
  bcolumn text,
  apkey text,
  bpkey text,
  ackey text,
  bckey text,
  PRIMARY KEY ((bpkey,apkey),bckey,ackey));

创建表后,我将描述该表,以便您可以看到Cassandra应用于的顺序

After creating it, I'll describe the table so you can see the order that Cassandra has applied to the columns.

aploetz@cqlsh:stackoverflow> desc table testorder ;

CREATE TABLE stackoverflow.testorder (
    bpkey text,
    apkey text,
    bckey text,
    ackey text,
    acolumn text,
    bcolumn text,
    dcolumn text,
    jcolumn text,
    PRIMARY KEY ((bpkey, apkey), bckey, ackey)
) WITH CLUSTERING ORDER BY (bckey ASC, ackey ASC)

本质上,Cassandra将对分区键和聚类键进行排序(按其优先级在PRIMARY KEY定义),然后各列以升序排列。

Essentially, Cassandra will order the partition keys and the clustering keys (ordered by their precedence in the PRIMARY KEY definition), and then the columns follow in ascending order.

这篇关于Cassandra中的列排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆