Cassandra:如何在超级列族中创建列? [英] Cassandra: How to create column in a super column family?

查看:612
本文介绍了Cassandra:如何在超级列族中创建列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在模式文件中定义我的数据库模型,以便轻松地从头创建键空间和列族。我查看了Cassandra发行版附带的schema-sample.txt,并展示了如何使用column_metadata来创建标准列族:

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.

推荐答案

要创建一个超级列,我将定义超级列的列名。 Column Family您只需要添加column_type属性:

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

在此超级列族中,名为'name'的任何子列都必须为UTF8,所谓的年龄就必须长。

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.

这篇关于Cassandra:如何在超级列族中创建列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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