Hive 结构体

结构体

-- 创建结构体表
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使用属性名取值

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值