结构体
-- 创建结构体表
create table if not exists str1(
name string,
score struct<chinese:int,math:int,english:int>
)
row format delimited fields terminated by ' '
collection items terminated by ','
;
数据
goudan 60,20,10
mazi 90,30,20
haoge 15,9,20,16
cg 59,151
-- 加载数据
load data local inpath '/home/hivedata/str' into table str1;
--查询分数英语为空的
select
*
from str1 s
where s.score.english is not null
;
-- 查询英语不空的人的成绩个数
select
s.name,
size(s.score)
from str1 s
where s.score.english is not null
;
-- 创array表
create table if not exists arr(
name string,
score array<int>
)
row format delimited fields terminated by ' '
collection items terminated by ','
;
load data local inpath '/home/hivedata/arr' into table arr;
结构体和array的区别:
数组只能是某种类型的元素集合,但是结构体可以任意类型。
arr的函数较为丰富内部函数,strcut较少些
两者取值不一样,arr使用角标取值,而struct使用属性名取值