Hive-行轉列(explode)


場景:通過parseHtml UDF解析一串HTML,返回一以 @@ 分割的字符串,使用split分割字符串進數組中,然后將數組的元素轉列。

開始的寫法

SELECT
id,
legal_person,
explode(split(parseHtml(legal_person_track_record),'@@')) as record,
amac_status
FROM db_amac.dc_amac_manager limit 10;

--問題
FAILED: SemanticException [Error 10081]: UDTF's are not supported outside the SELECT clause, nor nested in expressions

解決

select
id,
legal_person,
record,
amac_status
from db_amac.dc_amac_manager lateral view explode(split(parseHtml(legal_person_track_record),'@@')) recordTable as record;

Lateral View是Hive中提供給UDTF的conjunction,它可以解決UDTF不能添加額外的select列的問題。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM