Columns ordering in Cassandra

大兔子大兔子 提交于 2019-12-10 17:22:42

问题


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

Is it equivalent to ?

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

Thank you for your help


回答1:


Both of those statements will fail, because of:

  • The extra comma.
  • You have not provided a primary key definition.

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

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

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)

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.



来源:https://stackoverflow.com/questions/34635744/columns-ordering-in-cassandra

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