一.簡介
1.Lateral View 用於和UDTF函數【explode,split】結合來使用。
2.首先通過UDTF函數將數據拆分成多行,再將多行結果組合成一個支持別名的虛擬表。
3.主要解決在select使用UDTF做查詢的過程中查詢只能包含單個UDTF,不能包含其它字段以及多個UDTF的情況。
4.語法:LATERAL VIEW udtf(expression) tableAlias AS columnAlias (',' columnAlias)
5.案例:
select count(distinct(city)),count(distinct(name)) from user
LATERAL VIEW explode(like) myUser1 AS myCol1
LATERAL VIEW explode(age) myUser2 AS myCol2