且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Cassandra:如何在超级列族中创建列?

更新时间:2023-11-17 14:55:16

要创建一个超级列,我将定义超级列的列名。 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.