栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

Hive Lateral View

Hive Lateral View

目录

Hive explode介绍:

Hive posexplode介绍:

Lateral View介绍:

使用多个Lateral View:

outer关键字:


Hive explode介绍:

它会将一行数据转成多行,也就是将行数据转成列数据,它所接收的参数为array和map类型的数据,语法如下:

array参数:

select explode(array) as arr_name from tableName;

map参数:

select explode(map) as (map_key,map_value) from tableName;

Hive posexplode介绍:

与explode不同的是他会多生成一列索引值,从0开始。

Lateral View介绍:

Lateral view is used in conjunction with user-defined table generating functions such as explode(). As mentioned in Built-in Table-Generating Functions, a UDTF generates zero or more output rows for each input row. A lateral view first applies the UDTF to each row of base table and then joins resulting output rows to the input rows to form a virtual table having the supplied table alias.

Lateral View与用户定义的函数(如explode())结合使用。UDTF为每个输入行生成零个或多个输出行。Lateral View首先将UDTF应用于表的每一行,然后将生成的输出行与输入行连接起来,以形成具有提供的表别名的虚拟表。

这个虚拟表会和输入的行进行join,达到连接UDTF外的select字段的目的。

如下:

也可以使用posexplode:

也可以再进一步进行聚合:

使用多个Lateral View:

将上面表的page_id也改为多个用逗号隔开的形式,如下

将page_id和addid_list都拆分开:

如果想要不要重复数据,也可以使用posexplode,然后加一个where条件,上面的数据不太合适,但是效果是相同的,几front_page-1给1,front_page-2给2,contact_page-1给4,contact_page-2给5:

其实我们发现两个列拆分后就是进行了一个全连接。

outer关键字:

UDTF默认是忽略输出空的,outer关键字的作用是在UDTF转换列的时候将其中的空也给展示出来,显示为NULL,如下:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/698515.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号