SQL 之 lateral view explode()
来源:互联网 发布:app软件操作说明书 编辑:程序博客网 时间:2024/05/18 19:40
转自:http://www.cnblogs.com/judylucky/p/3713774.html
hive行转多列LATERAL VIEW explode
该文参考了:http://blog.sina.com.cn/s/blog_7e04e0d00101csic.html
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+LateralView
lateral view用于和split、explode等UDTF一起使用的,能将一行数据拆分成多行数据,在此基础上可以对拆分的数据进行聚合,lateral view首先为原始表的每行调用UDTF,UDTF会把一行拆分成一行或者多行,lateral view在把结果组合,产生一个支持别名表的虚拟表。
单个LATERAL VIEW:
源表(table1)数据{A:string B:array<BIGINT> C:string}
A B C
190 [1030,1031,1032,1033,1190] select id
191 [1030,1031,1032,1033,1190] select id
希望的结果是:
190 1030 select id
190 1031 select id
190 1032 select id
190 1033 select id
190 1190 select id
191 1030 select id
191 1031 select id
191 1032 select id
191 1033 select id
191 1190 select id
故使用select A,B,C from table_1 LATERAL VIEW explode(B) table1 as B得到上述结果
多个LATERAL VIEW的介绍:
LATERAL VIEW clauses are applied in the order that they appear. For example with the following base table:
Array<int> col1
Array<string> col2
[1, 2]
[a", "b", "c"]
[3, 4]
[d", "e", "f"]
SELECT
myCol1, myCol2
FROM
baseTable
LATERAL
VIEW
explode(col1) myTable1
AS
myCol1
LATERAL
VIEW
explode(col2) myTable2
AS
myCol2;
int myCol1
string 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 * 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后边的语句;
- SQL 之 lateral view explode()
- hive sql 中lateral view explode/json_tuple的使用
- hive lateral view explode 使用
- hive:explode() 与 lateral view
- 行转多列lateral view explode详解
- Lateral View用法 与 Hive UDTF explode
- hive lateral view 与 explode详解
- hive lateral view 与 explode详解
- Lateral View用法 与 Hive UDTF explode
- hive行转列lateral view explode用法
- hive lateral view 与 explode详解
- Lateral View用法 与 Hive UDTF explode
- Hive 之 Lateral View
- hive 之 lateral view
- hive常用UDF and UDTF函数介绍-lateral view explode()
- hive collect_set,lateral view,explode 实现行列转换
- 关于lateral view 和 explode 很不错的讲解
- Hive学习之Lateral View
- 基于SSM的RBAC权限系统(5)-利用ajax,JQuery实现动态搜索
- String--引用计数写时拷贝
- java从入门到放弃
- HDU6033 Add More Zero(取对数)
- RN面试要点
- SQL 之 lateral view explode()
- Angular移除不必要的$watch之性能优化
- MFC之CAsyncSocket详解
- HDU-6044 Limited Permutation(计数)
- leetcode 516. Longest Palindromic Subsequence 最大回文子序列
- Floyd(弗洛伊德)算法 详解+模板
- Windows 平台 Redmine 一键部署与邮箱配置
- session可以存储的方式有几种,如果程序采取分布式,怎么样实现session共享
- Handlebars.js if 功能扩展