hive的复杂数据类型

阅读: 评论:0

hive的复杂数据类型

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] fromarr a wherea.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"] frommap1 m wherem.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 fromstruct1 s wheres.score.English > 90;

本文发布于:2024-02-02 00:10:03,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170680957440079.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:数据类型   hive
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23