HIVE: How to include null rows in lateral view explode

扶醉桌前 提交于 2019-12-07 01:27:33

问题


I have a table as follows:

user_id email
u1      e1, e2
u2      null

My goal is to convert this into the following format:

user_id email
u1      e1
u1      e2
u2      null

So for this I am using the lateral view explode() function in Hive, as follows:

select *  FROM table LATERAL VIEW explode (  split (  email  ,','  ) ) email AS email_id 

But doing this the u2 row is getting skipped as it has null value in email. How can we include the nulls too in the output?

Edit: I am using a workaround doing an union of this table with the base table without explode, but I think the data will be scanned one more time because of this. I wanted to know if there is a better way to do it.


回答1:


include OUTER in the query to get rows with NULL values

something like,

select *  FROM table LATERAL VIEW OUTER explode (  split (  email  ,','  ) ) email AS email_id;

check this link -> https://cwiki.apache.org/confluence/display/Hive/LanguageManual+LateralView#LanguageManualLateralView-OuterLateralViews



来源:https://stackoverflow.com/questions/40715815/hive-how-to-include-null-rows-in-lateral-view-explode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!