2014-09-24 24 views
2

我有一個關係reflat1。以下是DESCRIBE和DUMP的輸出。PIG:無法將(key,(tuple_of_3_things))轉換爲(key,tupelement1,tupelement2,tupelement3)

reflat1: {cookie: chararray,tupofstuff: (category: chararray,weight: double,lasttime: long)} 
(key1,(613,1.0,1410155702) 
(key2,(iOS,1.0,1410155702) 
(key3,(G.M.,1.0,1410155702) 

是的,我注意到括號沒有關閉。我不知道爲什麼。也許沒有括號的原因是我所有問題的根源。

我想將它轉換成一個關係(我們稱之爲reflat2)有4場,這將理想樣子:

(key1, 613, 1.0,1410155702) 
(key2, iOS, 1.0,1410155702) 
(key3, G.M., 1.0,1410155702) 

但我的代碼是行不通的。以下是相關位。

reflat2 = foreach reflat1 { 
    GENERATE 
    cookie     as cookie, 
    tupofstuff.(category) as category, 
    tupofstuff.(weight)  as weight, 
    tupofstuff.(lasttime) as lasttime; 
}; 
r1 = LIMIT reflat2 100; 
dump r1; 

導致的模式,我期望:

DESCRIBE reflat2 
reflat2: {cookie: chararray,category: chararray,weight: double,lasttime: long} 

但在轉儲給出了一個錯誤:

Unable to open iterator for alias r1 

當我看到這些錯誤的失敗MapReduce作業,我看到:

java.lang.ClassCastException: java.lang.String cannot be cast to org.apache.pig.data.Tuple 

Whic h是很奇怪的,因爲如果有什麼我要將一個元組投射到一個字符串(以及一個雙精度和一個長精度),反之亦然。

+0

對於在尋找[錯誤1066:無法打開迭代器別名]時發現此帖子的人(http://stackoverflow.com/questions/34495085/error-1066-unable-to-open-iterator-for- alias-in-pig-generic-solution)這裏是一個[通用解決方案](http://stackoverflow.com/a/34495086/983722)。 – 2015-12-28 14:54:23

回答

0

在TUPLE上使用FLATTEN帶來了元組外的元素。你應該使用拼合如下:

reflat2 = foreach reflat1 GENERATE cookie, FLATTEN(tupofstuff); 

希望這會有所幫助。

+0

對不起,我也試過,它給了我完全相同的錯誤。 – jarfa 2014-09-26 15:39:14

+0

@jarfa您是否可以更新問題以包含您嘗試的內容,並直接確保您顯示具有適當輸入的可重複示例? (你給出的輸入看起來有點狡猾,所以從一些毫無疑問必須正確的事情開始) – 2015-12-28 14:56:10

相關問題