【问题标题】:Hive complex data type queryingHive 复杂数据类型查询
【发布时间】:2018-06-06 03:39:26
【问题描述】:

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

源表结构

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 和 array(struct) 。现在,当我查询此表时,我按预期获取列 c1、c2、c3、s1、s2 的所有记录,但我没有得到 as1 和 as2 列,而是将 temp2 本身作为 null 在输出中。 我在这里有什么遗漏吗。我应该拥有struct&lt;array&lt;struct&gt;&gt; 之类的数据还是可以拆分structarray&lt;struct&gt; 并且json serde 在阅读时会小心

【问题讨论】:

    标签: json hive hiveql beeline tez


    【解决方案1】:

    根据您的数据示例,它应该是structarray&lt;struct&gt;

    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"}]}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-01
      • 1970-01-01
      • 2018-06-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多