Create two composite columns with cassandra-cli

吃可爱长大的小学妹 提交于 2019-12-12 13:03:41

问题


My column family needs two composite columns, the key data type is BytesType.

Here is the definition of table using CQL:

CREATE TABLE stats (
      gid          blob,
      period       int,
      tid          blob, 
      sum          int,
      uniques      blob,
      PRIMARY KEY(gid, period, tid)
     );

What I want to do is to create the column family but with Cassandra CLI. Here is my shot.

The structure of the first composite is:

CompositeType(Int32Type, BytesType, AsciiType)

and it will holds an integer.

The structure of the second composite is:

CompositeType(Int32Type, BytesType)

and will holds BytesType.

create column family stats with comparator = 'CompositeType(Int32Type, BytesType, AsciiType)';

I'm not sure how to define the second composite column in create column family command.

Of course I'm assuming that the table created with CQL will generate two composite columns.


回答1:


You can only have one comparator on a column family in cassandra. This means you can also only have one type of composite column in column family. The table created by the CQL statement you used would actually use the first composite type comparator that you mention:

CompositeType(Int32Type, BytesType, AsciiType)

That comparator can describe all of your schema because of the 'AsciiType' component at the end of your composite. This component of your column names will contain the literal string 'sum' or 'uniques', and the column value will match the type accordingly.

An example using a json style notation:

<bytes> : {                               # a row key in your stats column family
    (100, <bytes>, "sum") : 100,          # one column in your row
    (100, <bytes>, "uniques") : <bytes>,  
    (200, <bytes>, "sum") : 200,
    (200, <bytes>, "uniques") : <bytes>
}
<bytes> : {                               # another row in the cf
    ...
}


来源:https://stackoverflow.com/questions/11243825/create-two-composite-columns-with-cassandra-cli

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