2017-04-22 42 views
0

我有兩個數據集,data1data2FLATTEN或子混亂加入豬

data2具有如下的數據,

a1:u:11#eve:f:6 
a1:u:12#eve:f:6 
a1:u2:13#eve:f:3 
a1:u1:12#eve:s:6 
a1:u1:11#eve:f:6 

這裏:以及#是分隔符。我產生data2終於爲,

LOAD '$data2' USING PigStorage(':') AS 
       (ad: chararray, 
        a_id: chararray, 
        cid_eve1: chararray, 
        name: chararray, 
        len: int); 

然後我第三列分成兩個,

FOREACH data2 GENERATE 
        ad AS ad, 
        a_id AS a_id, 
        FLATTEN(STRSPLIT(cid_eve1, '#')) AS (cid: int, eve1: chararray), 
        name AS name, 
        len AS len; 

現在,當我加入data2data1,我什麼也沒得到。

我也試過,

FOREACH data2 GENERATE 
        ad AS ad, 
        a_id AS a_id, 
        SUBSTRING(cid_eve1,0,INDEXOF(cid_eve1,'#',0)) AS cid: int, 
        name AS name, 
        len AS len; 

加入時,這還沒有返回。我參加的第3列,cid

我甚至傾倒data2這兩種情況下,看到的輸出。這是預期的。但是當我使用下面的文件爲data2

a1:u:11:eve:f:6 
a1:u:12:eve:f:6 
a1:u2:13:eve:f:3 
a1:u1:12:eve:s:6 
a1:u1:11:eve:f:6 

和負荷,

LOAD '$data2' USING PigStorage(':') AS 
      (ad: chararray, 
       a_id: chararray, 
       cid: int, 
       eve1: chararray, 
       name: chararray, 
       len: int); 

然後連接返回正確的結果。我不知道爲什麼會發生這種情況。有人可以幫助或提出任何建議。

data1,2nd col($1)是a_id並且最後一個col是cid。加入是對他們兩個。

1,u,true,true,4,1,1,1,1,1,11,21,31,11 
1,u,true,true,4,1,1,1,1,1,11,21,32,11 
1,u,true,true,4,1,1,1,1,1,11,21,33,11 
1,u,true,true,4,1,1,1,1,1,11,21,31,11 
1,u,true,true,4,1,1,1,1,1,11,21,32,11 
1,u,true,true,4,1,1,1,1,1,11,21,33,11 
2,u,true,true,4,1,1,1,1,1,12,22,34,12 
2,u,true,true,4,1,1,1,1,1,13,22,35,13 
2,u1,true,false,4,1,1,1,1,0,12,22,34,12 
2,u1,true,false,4,1,1,1,1,0,13,22,35,13 
2,u1,true,true,9,1,1,1,1,1,12,22,34,12 
2,u1,true,true,9,1,1,1,1,1,13,22,35,13 
3,u,false,false,4,1,0,1,0,0,14,24,31,14 
3,u,false,false,4,1,0,1,0,0,11,22,31,11 
4,u,true,NULL,0,1,1,0,0,0,11,22,33,11 
4,u1,false,NULL,0,1,0,0,0,0,11,22,33,11 
2,u,true,true,4,1,1,1,1,1,12,22,34,12 
2,u,true,true,4,1,1,1,1,1,13,22,35,13 
2,u2,true,true,7,1,1,1,1,1,12,22,34,12 
2,u2,true,true,7,1,1,1,1,1,13,22,35,13 

回答

0

我找到了答案。問題在於數據類型。我想讀chararrayint但沒有類型轉換它。

當我把它改成,

FOREACH data2 GENERATE 
       ad AS ad, 
       a_id AS a_id, 
       (int)SUBSTRING(cid_eve1,0,INDEXOF(cid_eve1,'#',0)) AS cid, 
       name AS name, 
       len AS len; 

它的工作。