Does CQL3 require a schema for Cassandra now?

前端 未结 4 992
迷失自我
迷失自我 2021-02-08 18:39

I\'ve just had a crash course of Cassandra over the last week and went from Thrift API to CQL to grokking SuperColumns to learning I shouldn\'t use them and user Composite Keys

4条回答
  •  名媛妹妹
    2021-02-08 19:15

    Cassandra still allows using wide rows. This answer references that DataStax blog entry, written after the question was asked, which details the links between CQL and the underlying architecture.

    Legacy support

    A dynamic column family defined through Thrift with the following command (notice there is no column-specific metadata):

    create column family clicks
      with key_validation_class = UTF8Type
      and comparator = DateType
      and default_validation_class = UTF8Type
    

    Here is the exact equivalent in CQL:

    CREATE TABLE clicks (
      key text,
      column1 timestamp,
      value text,
      PRIMARY KEY (key, column1)
    ) WITH COMPACT STORAGE
    

    Both of these commands create a wide-row column family that stores records ordered by date.

    CQL Extras

    In addition, CQL provides the ability to assign labels to the row id, column and value elements to indicate what is being stored. The following, alternative way of defining this same structure in CQL, highlights this feature on DataStax's example - a column family used for storing users' clicks on a website, ordered by time:

    CREATE TABLE clicks (
      user_id text,
      time timestamp,
      url text,
      PRIMARY KEY (user_id, time)
    ) WITH COMPACT STORAGE
    

    Notes

    • a Table in CQL is always mapped to a Column Family in Thrift
    • the CQL driver uses the first element of the primary key definition as the row key
    • Composite Columns are used to implement the extra columns that one can define in CQL
    • using WITH COMPACT STORAGE is not recommended for new designs because it fixes the number of possible columns. In other words, ALTER TABLE ... ADD is not possible on such a table. Just leave it out unless it's absolutely necessary.

提交回复
热议问题