行转多列lateral view explode详解
来源:互联网 发布:c语言的头文件是什么 编辑:程序博客网 时间:2024/05/19 23:04
行转多列lateral view explode详解:
lateral view用于和split、explode等UDTF一起使用的,能将一行数据拆分成多行数据,在此基础上可以对拆分的数据进行聚合,
lateral view首先为原始表的每行调用UDTF,UDTF会把一行拆分成一行或者多行,lateral view在把结果组合,产生一个支持别名表的虚拟表。
1.单个lateral view
源表(table1)数据{A:string B:array<BIGINT>}
A B
190 [1030,1031,1032,1033,1190]
191 [1030,1031,1032,1033,1190]
希望得到如下结果:
190 1030
190 1031
190 1032
190 1033
190 1190
191 1030
191 1031
191 1032
191 1033
191 1190
使用select A,B from table_1 lateral view explode(B) mytable as B 可以得到上述结果。
2.多个lateral view
Array<int> col1 Array<string> col2
[1, 2] ['a', 'b', 'c']
[3, 4] ['d', 'e', 'f']
转换目标:想同时把第一列和第二列拆开,类似做笛卡尔乘积。
结果如下:
myCol1 myCol2
1 'a'
1 'b'
1 'c'
2 'a'
2 'b'
2 'c'
3 'd'
3 'e'
3 'f'
4 'd'
4 'e'
4 'f'
select mycol1, mycol2 from basetable
lateral view explode(col1) mytable1 as mycol1
lateral view explode(col2) mytable2 as mycol2;
3.复杂方式:
select * from tb_split;
20141018 aa|bb 7|9|0|3
20141019 cc|dd 6|1|8|5
使用方式:select datenu,des,type from tb_split
lateral view explode(split(des,"//|")) tb1 as des
lateral view explode(split(type,"//|")) tb2 as type
执行过程是先执行from到as cloumn的列过程,再执行select 和where后边的语句。
lateral view用于和split、explode等UDTF一起使用的,能将一行数据拆分成多行数据,在此基础上可以对拆分的数据进行聚合,
lateral view首先为原始表的每行调用UDTF,UDTF会把一行拆分成一行或者多行,lateral view在把结果组合,产生一个支持别名表的虚拟表。
1.单个lateral view
源表(table1)数据{A:string B:array<BIGINT>}
A B
190 [1030,1031,1032,1033,1190]
191 [1030,1031,1032,1033,1190]
希望得到如下结果:
190 1030
190 1031
190 1032
190 1033
190 1190
191 1030
191 1031
191 1032
191 1033
191 1190
使用select A,B from table_1 lateral view explode(B) mytable as B 可以得到上述结果。
2.多个lateral view
Array<int> col1 Array<string> col2
[1, 2] ['a', 'b', 'c']
[3, 4] ['d', 'e', 'f']
转换目标:想同时把第一列和第二列拆开,类似做笛卡尔乘积。
结果如下:
myCol1 myCol2
1 'a'
1 'b'
1 'c'
2 'a'
2 'b'
2 'c'
3 'd'
3 'e'
3 'f'
4 'd'
4 'e'
4 'f'
select mycol1, mycol2 from basetable
lateral view explode(col1) mytable1 as mycol1
lateral view explode(col2) mytable2 as mycol2;
3.复杂方式:
select * from tb_split;
20141018 aa|bb 7|9|0|3
20141019 cc|dd 6|1|8|5
使用方式:select datenu,des,type from tb_split
lateral view explode(split(des,"//|")) tb1 as des
lateral view explode(split(type,"//|")) tb2 as type
执行过程是先执行from到as cloumn的列过程,再执行select 和where后边的语句。
阅读全文
0 0
- 行转多列lateral view explode详解
- hive lateral view 与 explode详解
- hive lateral view 与 explode详解
- hive lateral view 与 explode详解
- hive lateral view explode 使用
- hive:explode() 与 lateral view
- SQL 之 lateral view explode()
- Lateral View用法 与 Hive UDTF explode
- Lateral View用法 与 Hive UDTF explode
- hive行转列lateral view explode用法
- Lateral View用法 与 Hive UDTF explode
- hive常用UDF and UDTF函数介绍-lateral view explode()
- hive sql 中lateral view explode/json_tuple的使用
- hive collect_set,lateral view,explode 实现行列转换
- 关于lateral view 和 explode 很不错的讲解
- hive中的lateral view 用法详解上篇
- hive中的lateral view 用法详解下篇
- Lateral View
- 函数实例之数组应用(初始化,逆置,输出,清空)
- 在VS中添加lib库的三种方法
- python笔记1
- Python中的Lambda函数关键词的用法
- String操作
- 行转多列lateral view explode详解
- servlet中请求转发(forword)与重定向(sendredirect)的区别
- iOS中的静态库.a的制作
- 2.2.9同步静态方法与synchronized(class)
- Java day4
- <C语言经典100例>c42 去除字符串中的空格
- Centos7 VSCode 使用Python3 详解
- Liunx下memcache安装部署以及启动
- 一元线性回归