3
votes

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

1 Answers

3
votes

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