Create a Cassandra schema for a super column with metadata

余生长醉 提交于 2019-12-01 08:25:05

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.

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