谈一下使用hive udtf 函数lateral view explode(array()) array为空时遇到的坑,这个UDTF转换的Array为空的记录,自动被过滤掉了。大家用的时候注意一下,如果要保留记录,要把LATERAL VIEW explode转换成LATERAL VIEW OUTER explode,需要加上outer关键字。
1.不加outer,自动过滤为空的数据
hive> select
> *
> from (select null as arrive_vehicle_mark ) t
> lateral view explode(split(arrive_vehicle_mark,',')) x as arrive_vehicle_mark
> ;
OK
Time taken: 0.05 seconds
2.加上outer后,返回结果
hive> select
> *
> from (select null as arrive_vehicle_mark ) t
> lateral view outer explode(split(arrive_vehicle_mark,',')) x as arrive_vehicle_mark;
OK
NULL NULL
Time taken: 0.764 seconds, Fetched: 1 row(s)