hive的复杂数据类型

版权声明:版权声明中 https://blog.csdn.net/lds_include/article/details/88758085

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;

猜你喜欢

转载自blog.csdn.net/lds_include/article/details/88758085