Hive Lateral View

一.简介

  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

原文地址:https://www.cnblogs.com/yszd/p/11025389.html