2012-06-11 27 views
3

中只有1行豬拉丁寬鬆等於==與null?

X.A=null 
X.B= "blahblah" 

的關係X現在我想做的事:

Y = FILTER X BY A != B ; 

我打算說的是,由於是零和B是沒有的,條件應該是真實的。 但實際結果是Y是空的,並且條件評估爲false。

這與SQL相同,任何涉及null的情況都是錯誤的。雖然SQL可以將NVL()函數翻譯爲 null,但PIG似乎並沒有這樣做,是否有一種乾淨的方式來進行上述比較?

回答

2

這有點破解,但您可以進行比較並將結果存儲在關係中,然後使用結果和原始比較進行篩選。

Y = foreach X generate *, 
     (((A is null and B is not null) or (A is not null and B is null) ? 'y' : 'n') as oneNull; 
Y = filter Y by (oneNull == 'y' or A != B); 
Y = foreach Y generate A, B; 

利用這一點,如果X是:

(,blahblah) 
(blah,blah) 
(,) 
(blah,) 
(abc,def) 

則Y爲:

(,blahblah) 
(blah,) 
(abc,def) 
0

我有豬版本0.12.1安裝;它的實際工作對我來說,直接寫條件:

Y = filter X by (A is null and B is not null) or (A is not null and B is null) or A != B; 

注意,對於空/空的情況下,表達式A = B的計算結果爲空,所以過濾器不包括元組,根據

http://pig.apache.org/docs/r0.12.1/basic.html#nulls