为包含元数据的超级列创建Cassandra模式 [英] Create a Cassandra schema for a super column with metadata

查看:149
本文介绍了为包含元数据的超级列创建Cassandra模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用cassandra -cli



在我的数据库中使用以下结构,例如我有一个地址包含邮政编码,housenumber等的人b $ b原理图如下:

  name:address,
value:{
城市:{name:city,value:San Francisco},
street:{name:street,value:555 Union Street},
zip:{name:zipcode ,value:94105},
}



我知道如何创建超列和正常列。但是我想使用column_metadata来指定超列中的列如何显示。
这样最终会得到这样的结果:

 创建列族person 
with comparator = UTF8Type
和key_validation_class = UTF8Type
和default_validation_class = UTF8Type
和compression_options =
{sstable_compression:SnappyCompressor,chunk_length_kb:64}
和column_metadata = [
{column_type: super,column_name:address,validation_class:UTF8Type
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}
];

这是否可能?



如果我可以把一个超级列放在另一个超级列中会更好。这样,超级列地址可以包含具有列街道,zip等的多个超列地址。

解决方案

超级列上的列元数据已应用于子列本身。在您的示例中,将super列的validation_class设置为UTF8Type。这不是真的有意义,因为超级列的值是列本身不是UTF8。超级列名称已根据您设置为UTF8Type的比较器类型进行验证和排序。



因此,您需要的是:



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}
];

值得注意的是,此元数据将应用于该行中的所有超级列。因此,如果您有多个超级列与一个名为城市的子列,验证将应用于所有的。



我还要注意,使用超级列一般不鼓励,因为它们有几个缺点。超级列中的所有子列需要在读取一个子列时反序列化,并且不能在超级列上设置二级索引。它们也只支持一级嵌套。



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



要实现任意嵌套级别,您可以使用CompositeType作为常规列族的列比较器。不幸的是,目前还没有很多关于CompositeType的文档。我建议查看源的更多信息src / java / org / apache / cassandra / db / marshal / CompositeType.java。


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 schematic it looks like this:

name: "address",
value: {
    city: {name: "city", value: "San Francisco"},
    street: {name: "street", value: "555 Union Street"},
    zip: {name: "zipcode", value: "94105"},
}

I know how to create a supercolumn and normal columns. But I want to use the column_metadata to specify how the colums in a supercolumn look like. So that would end up something like this:

Create column family person
with comparator = UTF8Type
and key_validation_class=UTF8Type
and default_validation_class = UTF8Type
and compression_options =
{sstable_compression:SnappyCompressor, chunk_length_kb:64}
and column_metadata = [
{column_type: super, column_name: address, validation_class: UTF8Type
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}
];

Is this at all possible?

It would be even better if I can put a super column in another super column. This way the super column "addresses" could contain multiple super columns "address" with columns: "street", "zip", etc.

解决方案

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.

这篇关于为包含元数据的超级列创建Cassandra模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆