You can do SUM( a.values is null ? 1 : 0) as totalvalue. Thanks Krishnan
On Mon, Apr 14, 2014 at 4:43 PM, Koppula, Abhilash Reddy < [email protected]> wrote: > 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 >
