Hive交叉数组中的数据产品

时间:2014-03-20 01:58:56

标签: hive hiveql

我有一个带有1列的hive表,看起来像这样

    mycol
    [1,2] 
    [5,4,9] 
    [1]
    [1,5,6,7,8] 

如果数组的大小没有修复 -

如何将数组中数据的交叉产品返回到具有以下内容的位置:

    col1, col2 
     1      1
     1      2 
     1      3 
     1      4 
     1      5 
     2      1
     2      1 
     5      4 
     5      5
     5      4
     5      9 

等..

目标是能够使用图表来运行jacard相似性。我在想这样的事情:

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

1 个答案:

答案 0 :(得分:0)

你可以这样做

CREATE VIEW test AS
SELECT myCol  FROM exampleTable
LATERAL VIEW explode(col1) myTable1 AS myCol;

然后

  

选择t1.myCol,t2.myCol从test t1 join test t2 on true;