How about re-projecting with:

( sumValue IS NULL ? 0.0 : sumValue) AS sumValue

You may want to cast sumValue to avoid cast warnings.


-----Original Message-----
From: Koppula, Abhilash Reddy [mailto:[email protected]] 
Sent: Monday, April 14, 2014 4:44 PM
To: [email protected]
Subject: Extending Pig SUM function

Hi All,
The built in Pig SUM eval function returns null if the bag is empty . How can I 
override this(as simple as possible ) to return 0 instead of null .
  public class CustomSum extends SUM{
   // Which methods to override.
}

Or Is there any way I can do it in script to check if SUM returned null then 
make it 0.

Eg : A = FOREACH (COGROUP OUTER) group as url , (1-$d)+$d*SUM(a.values) as 
totalValue .

I am doing a outer COGROUP . So there are some records in the group which 
doesn't have values and in that case I would like to return constant(1-$d) . 
However as SUM returns null , totalValues is becoming null.


Thanks,
Abhilash

Reply via email to