There are a couple options as I see it. You could always have the udf return touble, bag. This would be more like the grouping as is. You could also flatten the bag and then your command should work (foreach thing flatten(bah);). I am not sure if pig is smart enough to let you sort based on something like bagname.$0
Sent via BlackBerry -----Original Message----- From: Matt Tanquary <[email protected]> Date: Thu, 23 Dec 2010 09:46:19 To: <[email protected]> Reply-To: [email protected] Subject: How do I sort results from UDF? I wrote a UDF which produces the following DataBag with 2 tuples. I want to sort the results based on the first tuple but get an error. grunt>I2L2_f = FOREACH I2L2_grp_t GENERATE udfs.FormatBasketName($1); grunt>dump I2L2_f; ({(3L),(1634|1966)}) ({(2L),(1634|3845)}) ({(3L),(1787|7000)}) ({(2L),(1966|3845)}) ({(3L),(4703|4282)}) ({(3L),(7298|5844)}) grunt>I2L2 = ORDER I2L2_f BY $0 DESC; java.lang.ClassCastException: java.lang.Long cannot be cast to org.apache.pig.data.DataBag How can I sort the results from my UDF? Thanks! -M@
