侧视图在蜂巢中爆炸

时间:2013-03-22 01:29:00

标签: hive hiveql

我有一个名为exampleTable的表,其中包含两列字符串数组。

Array<string> col1  Array<string> col2
["a", "b" , "c" ]       ["x","y","z"]
["aa", "bb" , "cc" ]       ["xx","yy","zz"]

我的目标是制作一个像这样的表

col1                   col2
"a"                     "x"
"b"                     "y"
"c"                     "z"
"aa"                     "xx"
"bb"                     "yy"
"cc"                     "zz"

我想过使用LATERL VIEW,如:

SELECT myCol1, myCol2  FROM exampleTable
         LATERAL VIEW explode(col1) myTable1 AS myCol1
         LATERAL VIEW explode(col2) myTable2 AS myCol2;

但这会产生这个

col1                   col2
"a"                     "x"
"a"                     "y"
"a"                     "z"
"a"                     "xx"
"a"                     "yy"
"a"                     "zz"
"b"                     "x"
"b"                     "y"
"b"                     "z"
"b"                     "xx"
"b"                     "yy"
"b"                     "zz"
"c"                     "x"
"c"                     "y"
"c"                     "z"
"c"                     "xx"
"c"                     "yy"
"c"                     "zz"
"aa"                     "x"
"aa"                     "y"
"aa"                     "z"
"aa"                     "xx"
"aa"                     "yy"
"aa"                     "zz"
"bb"                     "x"
"bb"                     "y"
"bb"                     "z"
"bb"                     "xx"
"bb"                     "yy"
"bb"                     "zz"
"cc"                     "x"
"cc"                     "y"
"cc"                     "z"
"cc"                     "xx"
"cc"                     "yy"
"cc"                     "zz"

我该如何解决这个问题? 提前谢谢。

1 个答案:

答案 0 :(得分:1)

您可以使用爆炸UDTF或explode2 UDTF作为基础来编写UDTF。

Refer here使用explode2基础。