一、map、struct、array 這3種的用法:
1、array的使用
建立資料庫表,以array作為資料型別
create table person(name string,work_locations array)
row format delimited
fields terminated by '\t'
collection items terminated by ',';
資料biansutao beijing,shanghai,tianjin,hangzhou
linan changchu,chengdu,wuhan
入庫資料
load data local inpath '/home/hadoop/person.txt' overwrite into table person;
查詢hive> select * from person;
biansutao ["beijing","shanghai","tianjin","hangzhou"]
linan ["changchu","chengdu","wuhan"]
time taken: 0.355 seconds
hive> select name from person;
linan
biansutao
time taken: 12.397 seconds
hive> select work_locations[0] from person;
changchu
beijing
time taken: 13.214 seconds
hive> select work_locations from person;
["changchu","chengdu","wuhan"]
["beijing","shanghai","tianjin","hangzhou"]
time taken: 13.755 seconds
hive> select work_locations[3] from person;
null
hangzhou
time taken: 12.722 seconds
hive> select work_locations[4] from person;
null
null
time taken: 15.958 seconds
2、map 的使用
建立資料庫表
create table score(name string, score map)
row format delimited
fields terminated by '\t'
collection items terminated by ','
map keys terminated by ':';
要入庫的資料
biansutao '數學':80,'語文':89,'英語':95
jobs '語文':60,'數學':80,'英語':99
入庫資料
load data local inpath '/home/hadoop/score.txt' overwrite into table score;
查詢hive> select * from score;
biansutao
jobs
time taken: 0.665 seconds
hive> select name from score;
jobs
biansutao
time taken: 19.778 seconds
hive> select t.score from score t;
time taken: 19.353 seconds
hive> select t.score['語文'] from score t;
6089
time taken: 13.054 seconds
hive> select t.score['英語'] from score t;
9995
time taken: 13.769 seconds
3、struct 的使用
建立資料表
create table test(id int,course struct)
row format delimited
fields terminated by '\t'
collection items terminated by ',';
資料1 english,80
2 math,89
3 chinese,95
入庫load data local inpath '/home/hadoop/test.txt' overwrite into table test;
查詢hive> select * from test;
ok1
2
3
time taken: 0.275 seconds
hive> select course from test;
time taken: 44.968 seconds
select t.course.course from test t;
english
math
chinese
time taken: 15.827 seconds
hive> select t.course.score from test t;
8089
95time taken: 13.235 seconds
4、資料組合 (不支援組合的複雜資料型別)
load data local inpath '/home/hadoop/test.txt' overwrite into table test;
create table test1(id int,a map>)
row format delimited fields terminated by '\t'
collection items terminated by ','
map keys terminated by ':';
Hive複雜資料型別之array
create table tablename colname array 基本型別 說明 下標從0開始,越界不報錯,以null代替測試資料 zhangsan 78,89 92,96 lisi 67,75 83,94 王五 23 12create table ifnot exists arr1 nam...
複雜資料型別
1 在c語言中,除了之前學到的基本資料型別 整型,浮點型,字元型 外,還有指標型別和構造型別 結構型,聯合型,列舉型 2 結構體型別,用於把不同型別的資料組合成乙個集合體,宣告格式 struct 結構名 例如 includestruct students void main 結構體的特點是 表示更豐...
複雜資料型別
1結構體 相當於是高階語言裡的類,但是他沒有方法,也就是行為,只有屬性,也就是成員,結構體相當於是自定義類 宣告struct students 當我們需要使用結要用結構體裡的類的屬性時,我們需要通過 運算子來進行呼叫,比如 students.age 2列舉它被用來存放固定的不可改變的型別,比如說,四...