解析JSON数组并加载到hive表中

时间:2017-06-09 05:55:51

标签: json hive

我有一个Json数组,如下所示

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

我需要解析该数据并加载到hive表中,如下所示

Name    Machine

xxxx    Machine1
yyyy    Machine2
zzzz    Machine3
有人可以帮忙吗?

1 个答案:

答案 0 :(得分:3)

android {
    ....
    dataBinding {
        enabled = true;
    }
}
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
;