【问题标题】:Hive json data explode option not exploding arrayHive json数据爆炸选项不爆炸数组
【发布时间】:2017-04-03 09:12:17
【问题描述】:

我正在将 Json 数据插入 Hive。这是格式 -

A1 Array <
struct <
        product array <
                     struct < 
                             dim1 array < struct <> >
                             dim2 array < struct <> >
                            >
                      >
       >>

在 from table 子句中,我使用explode as:

Lateral view outer explode(A1.product) t1 as prod Lateral view outer explode(prod.dim1) t2 as prod_d1 Lateral view outer explode(prod.dim2) t3 as prod_d2

样本数据:

A1["product":[{"productsku":"p_dmf_qs:click: page load","v2productname":"Quality Score - click: page load","v2productcategory":"DMF","productvariant":"(not set)","productbrand":"xxxx","productrevenue":"1000","localproductrevenue":null,"productprice":"100","productquantity":"1","productrefundamount":null,"productlistname":"(not set)","dim1":[],"dim2":[]}]]

当我在 select 语句中将 t2 和 t3 称为 prod_d1 和 prod_d2 时,我在结果中得到一个结构,而不是数组。 请帮我。它是一个嵌套结构。如果我没有第一个产品数组,我可以轻松地将其称为 A1.dim1 和 A1.dim2 作为两个爆炸函数。请帮帮我。

【问题讨论】:

  • 请添加表定义+小数据样本(几行)
  • 更新了我的问题中的示例数据。好心检查。谢谢

标签: arrays json hadoop hive explode


【解决方案1】:
select  t2.dim1,t2.dim2
...
Lateral view outer inline  (A1)         t1
Lateral view outer inline  (t1.product) t2

【讨论】:

  • 谢谢 Dudu.. 即使我使用 t2.dim1 和 t2.dim2,我也没有解决一个数组(dim1 和 dim2 数组)。在表中,我得到的结果为 [],这意味着一个数组被遗漏了。我们用 t1 寻址 A1 的数组,用 t2 寻址产品的数组,但是 dim1 和 dim2 的?这就是我卡住的地方
  • 如果你要分解两个数组,你会得到一个产品加入
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-08
  • 2021-06-03
  • 2019-07-26
  • 2016-02-08
  • 1970-01-01
相关资源
最近更新 更多