1.创建复杂类型的表(array)
create table qq1(id int,name string,xingge array<string>)
row format delimited fields terminated by ' '
collection items terminated by ',';
2.数据源
101 zs haha,hehe,heihei
102 ls haha,gaga,wawa
3.载入数据
hive> load data local inpath '/home/hadoop/qq1.txt' into table qq1;
4.查看
> select * from qq1;
OK
101 zs ["haha","hehe","heihei"]
102 ls ["haha","gaga","wawa"]
查看数组字段中某一个值
hive> select name,xingge[0] from qq1;
------------------------
1.复杂类型map使用
create table qq2(id int,name string,score map<string,int>)
row format delimited fields terminated by ' '
collection items terminated by ','
map keys terminated by ':';
2.数据源
101 zs 'math':90,'china':99,'art':98
102 ls 'math':50,'china':30,'art':10
3。
hive> load data local inpath '/home/hadoop/qq2.txt' into table qq2;
4.查看
hive> select * from qq2;
OK
101 zs {"'math'":90,"'china'":99,"'art'":98}
102 ls {"'math'":50,"'china'":30,"'art'":10}
查看map中 某一个值
hive> select name,score['math'] from qq2;