Create a Cassandra schema for a super column with metadata

前端 未结 1 995
别跟我提以往
别跟我提以往 2021-01-14 11:17

I want the following structure in my database with the cassandra -cli

for example I have a person with an address and the address contains a zipcode, housenumber etc

相关标签:
1条回答
  • 2021-01-14 11:36

    Column metadata on super columns already applys to the sub columns themselves. In your example you set a validation_class for the super column to UTF8Type. This doesn't really make sense since the values of the super column are columns themselves not UTF8. The super column names are already validated and sorted according to the comparator type which you have set to UTF8Type.

    So what you need is:

    column_metadata = [
      {column_name: city, validation_class: UTF8Type}
      {column_name: Street, validation_class: UTF8Type}
      {column_name: zip, validation_class: UTF8Type}
      {column_name: housnumber, validation_class: LongType}
    ];
    

    It's worth noting that this metadata will apply to all super columns in the row. So if you have multiple super columns with a sub column named 'city' the validation will apply to all of them.

    I'll also note that use of super columns is generally discouraged as they have several disadvantages. All subcolumns in a super column need to be deserialized when reading one sub column and you can not set secondary indexes on super columns. They also only support one level of nesting.

    http://www.datastax.com/docs/1.0/ddl/column_family#about-super-columns

    To achieve an arbitrary level of nesting you can use CompositeType as your column comparator on a regular column family. Unfortunately there isn't much documentation on CompositeType at the moment. I'd suggest looking over the source for more info src/java/org/apache/cassandra/db/marshal/CompositeType.java.

    0 讨论(0)
提交回复
热议问题