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

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

问题描述

我希望在我的数据库中使用 cassandra -cli 的以下结构

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"},
}

我知道如何创建超级列和普通列.但是我想使用 column_metadata 来指定超级列中的列的外观.所以最终会是这样的:

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

这可能吗?

如果我能把一个超级列放在另一个超级列中就更好了.这样超级列addresses"就可以包含多个超级列address"和列:street"、zip"等.

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.

推荐答案

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

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.

所以你需要的是:

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

值得注意的是,此元数据将应用于行中的所有超级列.因此,如果您有多个带有名为city"的子列的超级列,则验证将应用于所有这些.

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

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

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天全站免登陆