Limitations explode function

UDF
outward
UDTF

Limitations explode (UDTF) function

  • Not associated with other fields of the original table.
  • Not with group by, cluster by, distribute by, sort by MS.
  • UDTF can not be nested.
  • Not allowed to select another expression.

Use and often combined with lateral view

-- hive中解析json数组

CREATE TABLE tmp_export.mobile_info AS

SELECT loan_account_id,
       user_id,
       name,
       t3.mobilePhoneNo,
       md5(t3.mobilePhoneNo) AS mobilePhoneNo_1
FROM
  (SELECT t1.loan_account_id,
          t1.user_id,
          get_json_object(ss.col,'$.name') AS name,
          get_json_object(ss.col,'$.mobilePhoneNo') AS mobilePhoneNo
   FROM
     (SELECT loan_account_id,
             user_id,
             split(regexp_replace(regexp_extract(get_json_object(allcontactinfo,'$.fullContactInfoList') -- 获取data数组,格式[{json},{json}]
 ,'^\\[(.+)\\]$',1) -- 删除字符串前后的[],格式{json},{json}
 ,'\\}\\,\\{', '\\}\\|\\|\\{') -- 将josn字符串中的分隔符代换成||,格式{json}||{json}
 ,'\\|\\|') AS str -- 按||分隔符切割成一个hive数组

      FROM tmp_export.friend_mobile_info) t1 LATERAL VIEW explode(t1.str) ss AS col)t2 -- 将hive数组转成行
 LATERAL VIEW explode(split(regexp_replace(regexp_replace(t2.mobilePhoneNo,'\\[|\\]',''),'\\"',''),',')) t3 AS mobilePhoneNo
WHERE length(t3.mobilePhoneNo) = 11;


SELECT json_tuple(json, 'website', 'name')
FROM
  (SELECT explode(split(regexp_replace(regexp_replace('[{"website":"www.iteblog.com","name":"过往记忆"},{"website":"carbondateblog.com","name":"carbondata 中文文档"}]', '\\}\\,\\{','\\}\\;\\{'),'\\[|\\]',''),'\\;')) AS json) iteblog;

Published 175 original articles · won praise 76 · Views 230,000 +

Guess you like

Origin blog.csdn.net/qq_29232943/article/details/103630479