Hive数据类型(基本数据类型+集合数据类型)

基本数据类型

在这里插入图片描述

集合数据类型

在这里插入图片描述

案例实操

1.Hive 上创建测试表 test

create table test(
name string,
friends array<string>,
children map<string, int>,
address struct<street:string, city:string>
)
row format delimited fields terminated by ','
collection items terminated by '_'
map keys terminated by ':'
lines terminated by '\n';

2.创建本地测试文件 test.txt

songsong,bingbing_lili,xiao song:18_xiaoxiao song:19,hui long
guan_beijing
yangyang,caicai_susu,xiao yang:18_xiaoxiao yang:19,chao yang_beijing

3.导入文本数据到测试表

load data local inpath '/opt/module/hive/datas/test.txt' into table test;

4.访问三种集合列里的数据,以下分别是 ARRAY,MAP,STRUCT 的访问方式

hive (default)> select friends[1],children['xiao song'],address.city from test
where name="songsong";
OK
_c0 _c1 city
lili 18 beijing
Time taken: 0.076 seconds, Fetched: 1 row(s)

猜你喜欢

转载自blog.csdn.net/CharlesCFA/article/details/113840728