大数据技术Hive 侧视图lateral view的几种写法分享
Posted daydayup-2016
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了大数据技术Hive 侧视图lateral view的几种写法分享相关的知识,希望对你有一定的参考价值。
【大数据技术】Hive 侧视图lateral view的几种写法分享
- 第一种(单一lateral view)
select a.id
,b.host as host
,b.path as path
,b.query as query
from url_test a lateral view parse_url_tuple(a.url,'HOST','PATH','QUERY') b as host,path,query ;
- 第二种(多重lateral view)
select a.id
,b.host as host
,b.path as path
,c.query as query
,c.protocol as protocol
from url_test a lateral view parse_url_tuple(a.url,'HOST','PATH') b as host,path
lateral view parse_url_tuple(a.url,'PROTOCOL','QUERY') c as protocol ,query ;
- 第三种(侧视图为空的情况) !重要!
如下sql中array()生成了一个空的数组,explode炸裂之后依然是空,故该返回的结果集是空,前面的id,name等字段也失效
select id
,name
,col1
from tb_url
lateral view explode(array()) tmp as col1 ;
为避免出现上述id,name 等业务字段也连带失效的情况出现,在实际中应使用下述sql
select id
,name
,col1
from tb_url
lateral view outer explode(array()) tmp as col1 ;
以上是关于大数据技术Hive 侧视图lateral view的几种写法分享的主要内容,如果未能解决你的问题,请参考以下文章
hive中lateral view json_tuple的用法
hive函数之~hive当中的lateral view 与 explode
hadoop入门系列--hive中array(或map集合类型)的行转多列LATERAL VIEW explode用法