在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ 數(shù)據(jù)庫/ Cassandra集合
Cassandra批量
Cassandra與HBase比較(區(qū)別)
Cassandra截斷表
Cassandra刪除鍵空間
Cassandra刪除索引
Cassandra是什么?
Cassandra創(chuàng)建表
Cassandra數(shù)據(jù)類型
Cassandra修改鍵空間
Cassandra刪除表
Cassandra讀取數(shù)據(jù)
Cassandra數(shù)據(jù)模型
Cassandra教程
Cassandra刪除數(shù)據(jù)記錄
Cassandra更新數(shù)據(jù)
Cassandra修改表
Cassandra安裝與配置
Cassandra插入數(shù)據(jù)
Cassandra歷史
Cassandra的特點
Cassandra創(chuàng)建索引
Cassandra創(chuàng)建鍵空間(Keyspace)
Cassandra應(yīng)用場景(案例)
Cassandra與關(guān)系數(shù)據(jù)庫比較(區(qū)別)
Cassandra數(shù)據(jù)類型
Cassandra集合
Cassandra的架構(gòu)
Cassandra CQLsh

Cassandra集合

Cassandra集合用于處理任務(wù)。 您可以在集合中存儲多個元素。 Cassandra支持三種類型的集合:

  • Set
  • List
  • Map

Set集合

Set集合存儲查詢時返回排序元素的元素組。

語法:

Create table table_name  
(  
    id int,  
    Name text,  
    Email set<text>,  
    Primary key(id)  
);

示例:

下面舉個例子來展示Set集合。創(chuàng)建一個具有三列(id, nameemail)的表“employee”。

use yiibai_ks;

create table employee(
  id int,
  name text,
  email set<text>,
  primary key(id)
);

執(zhí)行上面語句創(chuàng)建表以后如下:

cqlsh:yiibai_ks> create table employee(
             ...   id int,
             ...   name text,
             ...   email set<text>,
             ...   primary key(id)
             ... );
cqlsh:yiibai_ks> describe employee;

CREATE TABLE yiibai_ks.employee (
    id int PRIMARY KEY,
    email set<text>,
    name text
) WITH bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';

cqlsh:yiibai_ks>

現(xiàn)在,向上面創(chuàng)建的employee表中插入一些值:

INSERT INTO employee (id, email, name)     
VALUES(1, {'yestouu@gmail.com'}, 'yestouu');    
INSERT INTO employee (id, email, name)     
VALUES(2,{'kanchan@qq.com'}, 'Kanchan');   
INSERT INTO employee (id, email, name)     
VALUES(3, {'maxsu@126.com'}, 'Maxsu');

執(zhí)行上面語句結(jié)果如下 -

cqlsh:yiibai_ks> INSERT INTO employee (id, email, name)
             ... VALUES(1, {'yestouu@gmail.com'}, 'yestouu');
cqlsh:yiibai_ks> INSERT INTO employee (id, email, name)
             ... VALUES(2,{'kanchan@qq.com'}, 'Kanchan');
cqlsh:yiibai_ks> INSERT INTO employee (id, email, name)
             ... VALUES(3, {'maxsu@126.com'}, 'Maxsu');
cqlsh:yiibai_ks> select * from employee;

 id | email                 | name
----+-----------------------+---------
  1 | {'yestouu@gmail.com'} | yestouu
  2 |    {'kanchan@qq.com'} | Kanchan
  3 |     {'maxsu@126.com'} |   Maxsu

(3 rows)
cqlsh:yiibai_ks>

List集合

當(dāng)元素的順序重要時,使用列表(List)集合。我們以擴展上面示例中的employee表并新增一列department為例。

alter table employee add department list<text>;

執(zhí)行結(jié)果如下 -

cqlsh:yiibai_ks> alter table employee add department list<text>;
cqlsh:yiibai_ks> select * from employee;

 id | department | email                 | name
----+------------+-----------------------+---------
  1 |       null | {'yestouu@gmail.com'} | yestouu
  2 |       null |    {'kanchan@qq.com'} | Kanchan
  3 |       null |     {'maxsu@126.com'} |   Maxsu

(3 rows)
cqlsh:yiibai_ks>

現(xiàn)在添加新列(department)。 在新列“department”中插入一些值。

INSERT INTO employee (id, email, name, department) VALUES(4, {'sweetsu@gmail.com'}, 'Sweetsu', ['IT Devopment']);

執(zhí)行上面語句結(jié)果如下 -

cqlsh:yiibai_ks> alter table employee add department list<text>;
cqlsh:yiibai_ks> select * from employee;

 id | department | email                 | name
----+------------+-----------------------+---------
  1 |       null | {'yestouu@gmail.com'} | yestouu
  2 |       null |    {'kanchan@qq.com'} | Kanchan
  3 |       null |     {'maxsu@126.com'} |   Maxsu

(3 rows)
cqlsh:yiibai_ks> INSERT INTO employee (id, email, name, department) VALUES(4, {'sweetsu@gmail.com'}, 'Sweetsu', ['IT Devopment']);
cqlsh:yiibai_ks> select * from employee;

 id | department       | email                 | name
----+------------------+-----------------------+---------
  1 |             null | {'yestouu@gmail.com'} | yestouu
  2 |             null |    {'kanchan@qq.com'} | Kanchan
  4 | ['IT Devopment'] | {'sweetsu@gmail.com'} | Sweetsu
  3 |             null |     {'maxsu@126.com'} |   Maxsu

(4 rows)
cqlsh:yiibai_ks>

Map集合

Map集合用于存儲鍵值對。它將一件事映射到另一件事。 例如,如果要將必備課程名稱來保存課程信息,則可以使用Map集合。

例子:

創(chuàng)建一個名為“course”的表。

create table course(
    id int,
    prereq map<text, text>,
    primary key(id)
);

-- 插入數(shù)據(jù)
INSERT into course(id,prereq) VALUES(1, {'Programming':'CPP&&Java', 'Network':'Artificail Intelligence'});

現(xiàn)在創(chuàng)建表,在Map集合類型中插入一些數(shù)據(jù)。

輸出:

cqlsh:yiibai_ks> create table course(
             ... id int,
             ... prereq map<text, text>,
             ... primary key(id)
             ... );
cqlsh:yiibai_ks> INSERT into course(id,prereq) VALUES(1, {'Programming':'CPP&&Java', 'Network':'Artificail Intelligence'});
cqlsh:yiibai_ks> select * from course;

 id | prereq
----+--------------------------------------------------------------------
  1 | {'Network': 'Artificail Intelligence', 'Programming': 'CPP&&Java'}

(1 rows)
cqlsh:yiibai_ks>