Hive的三種複雜資料型別

2021-10-07 17:56:10 字數 2096 閱讀 6023

hive的複雜資料型別主要分為3類:arraymapstruct

測試資料: 列間用 \t 分隔,第二列用逗號分隔。

zhangsan	chengdu,shanghai,beijing

lisi tianjin,taiyuan,chongqing

wangwu xian,nanning,beijing

建表:

create table hive_array(

name string,

locations array

) row format delimited fields terminated by '\t'

collection items terminated by ','

;

查詢:

//取出陣列的第乙個元素

select name, locations[0] from hive_array;

//返回陣列長度

select name, size(locations) from hive_array;

//包含返回true,否則false

select * from hive_array where array_contains(locations,'tianjin'

);

測試資料:

1

,zhangsan,father:xiaoming#mother:xiaohuang,282

,lisi,father:xiaoxi#mother:xiaofang#brother:xiaoli,223

,wangwu,father:xiaoqiang#mother:xiaohong#brother:xiaowang,

35

建表:

create table hive_map(

id int,

name string,

members map,

age int

) row format delimited fields terminated by ','

collection items terminated by '#' //組間分隔符

map keys terminated by ':'

; //組內分隔符

查詢:

select name, members[

'father'

], members[

'mother'

] from hive_map;

select name, map_keys(members) from hive_map;

select name, size(members) from hive_map;

select name, members[

'brother'

] from hive_map where array_contains(map_keys(members),'brother');

//擁有兄弟的人及兄弟名稱

測試資料:

192.168

.1.1#zhangsan:

40192.168

.1.2#lisi:

25192.168

.1.3#wangwu:

38

建表:

create table hive_struct(

ip string,

userinfo struct,

) row format delimited fields terminated by '#'

collection items terminated by ':'

; //組間分隔符

查詢:

select ip, userinfo.name, userinfo.age from hive_struct;

hive高階 分割槽表與三種複雜資料型別

在大資料中,最常用的一種思想就是分治,我們可以把大的檔案切割劃分成乙個個的小的檔案,這樣每次操作乙個小的檔案就會很容易了,同樣的道理,在hive當中也是支援這種思想的,就是我們可以把大的資料,按照每天,或者每小時進行切分成乙個個的小的檔案,這樣去操作小的檔案就會容易得多了。建立分割槽表語法 crea...

hive複雜資料型別 a29

一 map struct array 這3種的用法 1 array的使用 建立資料庫表,以array作為資料型別 create table person name string,work locations array row format delimited fields terminated b...

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...