1

我在 Hive 表中有一个类型为:

array<array<struct<type:string,value:string,currency:string>>>

以下是列中的数据示例:

[
  [
    {
       "type": "PROFIT",
       "value": "100",
       "currency": "USD"
    },
    {
       "type": "NET",
       "value": "50",
       "currency": "USD"
    },
    {
       "type": "TOTAL",
       "value": "250",
       "currency": "USD"
    }
  ]
]

如何将每个“类型”查询到一列?

利润 全部的
4

1 回答 1

0

展开上层数组得到struct的内部数组,使用数组索引[]访问struct,使用dot访问struct元素:

select a1.inner_array[0].type as type1,
       a1.inner_array[1].type as type2,
       a1.inner_array[2].type as type3
  from yourtable t
       --explode upper array
       lateral view outer explode(col_name) a1 as inner_array
于 2021-05-06T06:34:41.630 回答