Hive复杂数据类型查询

时间:2018-06-06 03:39:27

标签: json hive hiveql beeline tez

我正在尝试从源表中查询数据,但我无法正确查看结果。

源表格结构

c1 string,
c2 string,
c3 string,
temp1 struct
<
s1 : string,
s2 : string,
s3 : string,
temp2 : array<struct<as1 string,as2 :string>>                 
>

我有 JSON 格式的数据。

我的JSON数据采用以下格式

{"c1":"123","c2":"XYZ","c3":"IIK",
"temp1":{"s1":"low","s2":"45","s3":"yes"},
"temp2":[{"as1":"16-05-1992","as2":"fail"}]
}

根据我的表结构,我应该在struct中有数组(struct)。但我所拥有的数据并非如此。我分别有struct和array(struct)。现在,当我查询此表时,我按预期得到了列c1,c2,c3,s1,s2的所有记录,但我没有得到as1和as2列,而是将 temp2 本身作为 null 。 我在这里遗漏了什么。我应该拥有struct<array<struct>>这样的数据,还是可以分割structarray<struct>,json serde在阅读时会小心

1 个答案:

答案 0 :(得分:0)

根据您的数据示例,它应该为structarray<struct>

c1 string,
c2 string,
c3 string,
temp1 struct
<
s1 : string,
s2 : string,
s3 : string
>,
temp2 : array<struct<as1 string,as2 :string>> 

单个JSON对象应该在一行中,不支持多行json:

{"c1":"123","c2":"XYZ","c3":"IIK","temp1":"s1":"low","s2":"45","s3":"yes"},"temp2":[{"as1":"16-05-1992","as2":"fail"}]}