J. Volkya
J. Volkya

Reputation: 1000

Cassandra: How to create column in a super column family?

I am defining my database model in a schema file in order to easily create the keyspace and column families from scratch later on. I looked at the schema-sample.txt that comes with the Cassandra distribution and it shows how to create standard column families using the column_metadata such as this:

create column family User
with comparator = UTF8Type
and default_validation_class = UTF8Type
and column_metadata = [
         {column_name : name, validation_class : UTF8Type}
         {column_name : username, validation_class : UTF8Type}
         {column_name : City, validation_class : UTF8Type}
];

But how can I use a similar syntax to create a super column family? I would like to define the column names of the super columns I will put in the super column family.

Upvotes: 4

Views: 7332

Answers (1)

nickmbailey
nickmbailey

Reputation: 3684

To create a Super Column Family you only need to add the column_type property:

create column family User
with column_type = 'Super' 
and comparator = UTF8Type
and default_validation_class = UTF8Type;

You can't define the names of the super columns in the metadata. The metadata is used for either validating column values or creating indexes. Since you can't validate the value of a super column (the value is more columns) and you can't create indexes on super columns, there is no reason to set metadata for them.

You can create metadata about the sub columns with super columns but it will apply to all super columns in the row. For example:

create column family User
with column_type = 'Super'
and comparator = UTF8Type
and default_validation_class = UTF8Type
and column_metadata = [
         {column_name : name, validation_class : UTF8Type}
         {column_name : age, validation_class : LongType}
];

In this super column family any sub column called 'name' will have to be UTF8 and any sub column called age will have to be a long.

Upvotes: 7

Related Questions