Cassandra标准列和超级列

列(column)是Cassandra数据模型中的最基本的数据结构单元。列是一个由列名(key)、值(value)、时间戳(timestamp)构成的三元组。在关系型数据库中,你需要先定义列的名称和和列类型来组成表结构,在插入数据的时候,客户端只需要往预先定义好的表结构插入数值就行了,数据库提供表名称和列名,客户端负责插入数据;而在Cassandra中,数据库只负责提供表名称,列名和数值是由客户端提供的。在关系型数据库中,每行都有相同的列,但在Cassandra中,每行可以有相同的列,也可以有不同的列

标准列(Standard Columm)

标准列的数据结构

标准列
名称【】 【】时间戳【】

['CF']['Row Key']['Column']

列的实际存放例子

(name=age, value=18, timestamp=1527692421898000)

在上面的例子中,列名是年龄age,值是18。

[default@mytest] get users['zhangpeng'];
=> (name=age, value=18, timestamp=1527692421898000)
=> (name=birthday, value=19890507, timestamp=1529333838055000)
=> (name=first, value=zhang, timestamp=1527692409752000)
=> (name=last, value=peng, timestamp=1527692416150000)

在该例子中,标准列users中的用户“zhangpeng”作为该行数据区分其他行数据的唯一的row key(主键)。

超级列(Super Column)

超级列是一种特殊的列。两种列都是键/值对。但标准列的值是字节组,而超级列的值是一个子列的映射,超级列不能存储其他超级列的映射,也就是说,超级列仅允许使用一层,但是会它不并不限制列的数量。

超级列的数据结构包含它的名字和它存储的列,它的名字和标准列一样,但是存储的值是一个列的映射。

超级列
名称【】 col1:key1,col2:key2,col3:key3,col4:key4 【】时间戳【】

['CF']['Row Key']['SuperColumn']['SubColumn']

[default@mytest] create column family hg18
...    with column_type = Super
...    and comparator = UTF8Type
...    and key_validation_class=UTF8Type
...    and default_validation_class=UTF8Type
...    and subcomparator = UTF8Type
...    and column_metadata = [
...      {column_name:isExon, validation_class:UTF8Type}
...      {column_name:cons, validation_class:IntegerType}
...    ];
278c4430-bcea-3ae9-a845-079687db907d

[default@mytest] set hg18['chr1:000000004']['geneFeatures']['isExon'] = 'T';
Value inserted.
Elapsed time: 2.76 msec(s).
[default@mytest] set hg18['chr1:000000004']['conservation']['cons'] = '13';
Value inserted.
Elapsed time: 1.74 msec(s).
[default@mytest] list hg18;
Using default limit of 100
Using default cell limit of 100
-------------------
RowKey: chr1:000000004
=> (super_column=conservation,
     (name=cons, value=13, timestamp=1529817745740000))
=> (super_column=geneFeatures,
     (name=isExon, value=T, timestamp=1529817725916000))

1 Row Returned.
Elapsed time: 97 msec(s).
原文地址:https://www.cnblogs.com/ilifeilong/p/9219729.html