hive中對複雜資料型別的支援

2021-06-22 23:22:32 字數 1609 閱讀 2987

hive提供了復合資料型別:

struct:struct內部的資料可以通過dot(.)來訪問,例如,表中一列c的型別為struct,可以通過c.a來訪問域a

map(key-value對):訪問指定域可以通過["指定網域名稱稱"]進行,例如,乙個map m包含了乙個group->gid的kv對,gid的值可以通過m['group']來獲取

array:array中的資料為相同型別,例如,array a中元素['a','b','c'],則a[0]的值為'a',a[1]的值為'b'

**hive中暫沒有支援list型別**

/*struct使用示例*/

建表:create table s1(id int,info struct) 

row format delimited //指定記錄按行劃分

fields terminated by ','//指定元組之間的分隔符 

collection items terminated by ':';//指定元組各個字段之間的分隔符 

匯入資料:

load data local inpath '/hivetest1' into table s1;

/hivetest1中資料格式如下:

1,zhou:30

2,yan:30

3,chen:20

查詢:select info.p1 from s1;

查詢結果為:

zhou

yanchen

/*array使用示例*/

建表:create table s2(id int,info array) 

row format delimited fields terminated by ',' 

collection items terminated by ':';

匯入資料:

load data local inpath '/hivetest2' into table s2;

/hivetest2中資料格式如下:

1,1:2:3:4

2,5:6

3,7:8:9:10

4,11

查詢:select info[1] from s2 ;

查詢結果為:26

8null

/*map使用示例*/

建表:create table s3(id int,info map) 

row format delimited fields terminated by '\t' 

collection items terminated by ','

map keys terminated by ':';//指定key-value分隔符

匯入資料:

load data local inpath '/hivetest3' into table s3;

/hivetest3中資料格式如下:

1job:80,team:60,person:70

2job:60,team:80

3job:90,team:70,person:100

查詢:select info['person'] from s3;

查詢結果為:

70null

100

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

複雜資料型別

1 在c語言中,除了之前學到的基本資料型別 整型,浮點型,字元型 外,還有指標型別和構造型別 結構型,聯合型,列舉型 2 結構體型別,用於把不同型別的資料組合成乙個集合體,宣告格式 struct 結構名 例如 includestruct students void main 結構體的特點是 表示更豐...