Hi Steve ,

Thanks for the suggestion it worked .  Below is the modified script .

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


 How can I change it so that SUM function can be avoided twice .  I am new to 
the PIG scripting and so I couldn't come up with better ways .

Thanks,
Akoppula


-----Original Message-----
From: Steve Bernstein [mailto:steve.bernst...@deem.com] 
Sent: Monday, April 14, 2014 7:55 PM
To: user@pig.apache.org
Subject: RE: Extending Pig SUM function

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:akopp...@indiana.edu] 
Sent: Monday, April 14, 2014 4:44 PM
To: user@pig.apache.org
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