2014-10-16 20 views
0

我正在使用posexplode在配置單元中將單個記錄分成多個記錄。 除了多個記錄作爲輸出,我需要爲每一行生成序列號。如何在配置單元中使用Posexplode功能

col1,col2,col3col4被定義爲字符串,因爲很少我們也獲得alpha數據。

col1 | col2| col3 | col4 
--------------------------- 
    7 | 9 | A | 3 
    5 | 6 | 9 

Seq | Col 
---------- 
1 | 7 
2 | 9 
3 | A 
4 | 3 
1 | 5 
2 | 6 
3 | 9 

我使用下面提到的查詢,但我得到的錯誤

-bash: syntax error near unexpected token (

我的查詢是:

SELECT 
    seq, col 
FROM 
    (SELECT array( col1, col2 , col3,col4) as arr_r FROM srctable) arrayrec 
LATERAL VIEW posexplode(arrayrec) EXPLODED_rec as seq, col 

這又如何解決

我能夠成功運行此查詢:

SELECT col FROM 
(SELECT array( col1, col2 , col3,col4) 
as arr_r FROM srctable) arrayrec 
LATERAL VIEW explode(arrayrec) EXPLODED_rec as col 

低於輸出

Col 
----- 
    7 
    9 
    A 
    3 
    5 
    6 
    9 

我檢查了鏈接主要生產:How to get first n elements in an array in Hive

回答

0

嘗試

SELECT Seq, col FROM 
(SELECT array( col1, col2 , col3,col4) 
as arr_r FROM srctable) arrayrec 
LATERAL VIEW posexplode(arrayrec.arr_r) EXPLODED_rec as Seq, col; 

還要檢查你的蜂巢版本。 posexplode()自Hive 0.13.0開始提供。

+0

我正在使用Hive 0.12.0。我可以使用posexplode(),如果是的話我怎麼能實現。我試過你的建議,它不起作用 – Raghunath 2014-10-20 10:25:08

+0

posexplode()未與配置單元0.12.0一起發貨。只有你可以使用posexplode()的方法是將它作爲自定義UDTF從hive 0.13.0源代碼編譯並導入到hive 0.12.0中。 – user3122114 2014-10-20 21:25:40

相關問題