hive一行数据中一列拆分成多行
2015-03-27 15:28
288 查看
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:
复杂方式:
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:
源表(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 * 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后边的语句;
相关文章推荐
- hive一行数据中一列拆分成多行
- hive一行数据中一列拆分成多行
- hive 导出数据之一列多行,转为一行多列
- Hive将一行记录拆分成多行
- Oracle一列的多行数据拼成一行显示字符
- T_SQL 将一列多行数据合并为一行
- SQL 将一列多行数据合并为一行 FOR XML PATH
- 数据量10亿级别的数据库表,多行存储成一行、一列扩展成多列之数据优化及迁移方案(一)
- SQL不重复查找数据及把一列多行内容拼成一行
- (转)Oracle一列的多行数据拼成一行显示字符
- 【数据平台】pandas将一列中的文本拆分成多行
- T_SQL 将一列多行数据合并为一行
- 模拟ORACLE wm_concat函数(把一列中的多行数据在一行显示)
- 数据量10亿级别的数据库表,多行存储成一行、一列扩展成多列之数据优化及迁移方案(三)
- Oracle一列的多行数据拼成一行显示字符
- [Hive]Hive将一行记录拆分成多行
- Oracle一列的多行数据拼成一行显示字符
- 用 SQL 语句对一行数据拆分成多行的方法
- T_SQL 将一列多行数据合并为一行
- 数据量10亿级别的数据库表,多行存储成一行、一列扩展成多列之数据优化及迁移方案(二)