【问题标题】:Parse JSON Array and load into hive table解析 JSON 数组并加载到配置单元表中
【发布时间】:2017-06-09 05:55:50
【问题描述】:

我有一个如下的 Json 数组

[{"Name":"xxxx","Machine":"Machine1"},{"Name":"yyyy","Machine":"Machine2"},{"Name":"zzzz","Machine":"Machine3"}]

我需要解析该数据并加载到如下所示的配置单元表中

Name    Machine

xxxx    Machine1
yyyy    Machine2
zzzz    Machine3

有人可以帮忙吗?

【问题讨论】:

  • 我已经完成了使用regex_replace,拆分和爆炸。从 (select split(a.new,';') 作为 arr 从 (select regexp_replace(regexp_replace(jsonarray.json,"\\}\\,\\{","\\ }\\;\\{"),"\[|\]","") as new FROM jsonarray)as a)as b 有没有更好的解决方案?

标签: json hive


【解决方案1】:
select  j.Name,j.Machine

from    jsonarray t
        lateral view explode(split(substr(t.json,2),'(?<=\\}),(?=\\{)')) e
        lateral view json_tuple(e.col,'Name','Machine') j as Name,Machine
;

+------+----------+
| name | machine  |
+------+----------+
| xxxx | Machine1 |
| yyyy | Machine2 |
| zzzz | Machine3 |
+------+----------+

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-11
    相关资源
    最近更新 更多