4

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.

J. Volkya
  • 993
  • 3
  • 14
  • 33

1 Answers1

7

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.

nickmbailey
  • 3,674
  • 15
  • 14
  • I know I have to get my old relational way of thinking out of my head and I probably don't completely understand super columns. But in your 2nd example, this is not a super column family, right? But you say: "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.". So it is not possible to declare the names of super columns in a schema file? – J. Volkya Dec 02 '11 at 15:12
  • Oops, I forgot to add the column type to the create statement. I will edit the response and add that in. – nickmbailey Dec 02 '11 at 16:10
  • 2
    But yes, it is not possible to declare the names of the super columns. Cassandra only provides the ability to declare column names in order to either validate the column values or create an index on that column name. As I said before you can't do either of those things with super columns. – nickmbailey Dec 02 '11 at 16:12