hive的复杂数据类型

hive常见的复杂数据类型

数组Array类型

创建复杂类型的表

  • 数组array
luodesong	90,100,100
xiaoming	90,90,90
  • 创建表
create table if not exists arr(
	name string,
	score Array<double>
)
row format delimited fields terminated by'\t'
collection items terminated by','
;
说明:
  • row format delimited fields terminated by’\t’是确定列分割符。
  • collection items terminated by’,'是确定数组中元素与元素(90,100,100)之间的分割符。

查询数据

  • 查询所有的
select * from arr
  • 查询数组中的元素
select a.name, a.score[0], a.score[3] from
	arr a where
	a.score[1] > 90;

集合map类型

创建复杂类型的表

  • 集合map
luodesong	Chinese:90,Math:100,English:100
xiaoming	Chinese:90,Math90,English90
  • 创建表
create table if not exists map1(
	name string,
	score map<String,double>
)
row format delimited fields terminated by'\t'
collection items terminated by','
map keys terminated by':'
;
说明:
  • row format delimited fields terminated by’\t’是确定列分割符。
  • collection items terminated by’,'是确定map中每个map元素与map元素(Chinese:90,Math:100,English:100)之间的分割符。
  • map keys terminated by’:'是指map中key-value(Chinese:90)的分隔符

查询数据

  • 查询所有的
select * from map1
  • 查询map中的元素
select m.name, m.score["Chinese"], m.score["Math"] from
	map1 m where
	m.score["English"] > 90;

结构体struct数据类型

创建复杂类型的表

  • 结构体struct
luodesong	90,100,100
xiaoming	90,90,90
  • 创建表
create table if not exists struct1(
	name string,
	score struct<Chinese:double,Math:double,English:double>
)
row format delimited fields terminated by'\t'
collection items terminated by','
;
说明:
  • row format delimited fields terminated by’\t’是确定列分割符。
  • collection items terminated by’,'是确定struct中每个元素与元素(90,100,100)之间的分割符。

查询数据

  • 查询所有的
select * from struct1
  • 查询struct中的元素
select s.name, s.score.Chinese, s.score.Math from
	struct1 s where
	s.score.English > 90;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值