文章目錄
- 4.複雜資料類型
-
- 4.1 array
- 4.2 map
- 4.3 sturct
- 4.4 補充:嵌套
4.複雜資料類型
4.1 array
建立
create table if not exists tablename(
id int,name string,news array<string>)
row format delimited fields terminated by ' '
collection items terminated by ',';
查詢
select news from tablename;
select news[1] from tablename;
補充
array中預設分隔符為:ctrl+v+b
4.2 map
建立
create table if not exists tablename(
id int,name string,news map<string,string>)
row format delimited fields terminated by ' '
map keys terminated by ',';
查詢
select news['string1'] from tablename;
#根據key查value
補充
如果有多組鍵值對可以用(寫在map keys前面)
4.3 sturct
建立
create table if not exists tablename(
id int,name string,news struct<age:int,sex:string>)
row format delimited fields terminated by ' '
collection items terminated by ',';
查詢
select news.age from tablename;
#字段名.key
補充
中間符号 預設符為:^C (ctrl+v+c)
4.4 補充:嵌套
建立
create table if not exists tablename(
id int,name string,news array<struct<age:int,sex:string>>)
row format delimited fields terminated by '\t'
collection items terminated by ' '
map keys terminated by ',';
查詢
補充
文本如下:
1 name 18,male 19,female