Author: gates Date: Fri May 23 15:31:28 2008 New Revision: 659695 URL: http://svn.apache.org/viewvc?rev=659695&view=rev Log: PIG-159 Santhosh's fix to bug that prevented instantiation of UDFs.
Modified: incubator/pig/branches/types/src/org/apache/pig/FilterFunc.java incubator/pig/branches/types/src/org/apache/pig/builtin/IsEmpty.java incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt incubator/pig/branches/types/test/org/apache/pig/test/TestLogicalPlanBuilder.java Modified: incubator/pig/branches/types/src/org/apache/pig/FilterFunc.java URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/FilterFunc.java?rev=659695&r1=659694&r2=659695&view=diff ============================================================================== --- incubator/pig/branches/types/src/org/apache/pig/FilterFunc.java (original) +++ incubator/pig/branches/types/src/org/apache/pig/FilterFunc.java Fri May 23 15:31:28 2008 @@ -22,19 +22,7 @@ import org.apache.pig.data.Tuple; -public abstract class FilterFunc { - - /** - * This callback method must be implemented by all subclasses. This - * is the method that will be invoked on every Tuple of a given dataset. - * Since the dataset may be divided up in a variety of ways the programmer - * should not make assumptions about state that is maintained between - * invocations of this method. - * - * @param input the Tuple to be processed. - * @throws IOException - */ - abstract public boolean exec(Tuple input) throws IOException; +public abstract class FilterFunc extends EvalFunc<Boolean> { /** * Placeholder for cleanup to be performed at the end. User defined functions can override. Modified: incubator/pig/branches/types/src/org/apache/pig/builtin/IsEmpty.java URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/builtin/IsEmpty.java?rev=659695&r1=659694&r2=659695&view=diff ============================================================================== --- incubator/pig/branches/types/src/org/apache/pig/builtin/IsEmpty.java (original) +++ incubator/pig/branches/types/src/org/apache/pig/builtin/IsEmpty.java Fri May 23 15:31:28 2008 @@ -30,7 +30,7 @@ public class IsEmpty extends FilterFunc { @Override - public boolean exec(Tuple input) throws IOException { + public Boolean exec(Tuple input) throws IOException { try { Object values = input.get(0); if (values instanceof DataBag) Modified: incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt?rev=659695&r1=659694&r2=659695&view=diff ============================================================================== --- incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt (original) +++ incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt Fri May 23 15:31:28 2008 @@ -48,6 +48,7 @@ import org.apache.pig.data.Tuple; import org.apache.pig.data.BagFactory; import org.apache.pig.data.DataBag; +import org.apache.pig.EvalFunc; public class QueryParser { @@ -2048,13 +2049,11 @@ if(null == userFunc) { //TODO //Commented out the code for instaniateFunc as it's failing - /* try{ - LOUserFunc ef = (LOUserFunc) pigContext.instantiateFuncFromAlias(funcName); + EvalFunc ef = (EvalFunc) pigContext.instantiateFuncFromAlias(funcName); }catch (Exception e){ throw new ParseException(e.getMessage()); } - */ } log.trace("Exiting EvalFunction"); Modified: incubator/pig/branches/types/test/org/apache/pig/test/TestLogicalPlanBuilder.java URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/test/org/apache/pig/test/TestLogicalPlanBuilder.java?rev=659695&r1=659694&r2=659695&view=diff ============================================================================== --- incubator/pig/branches/types/test/org/apache/pig/test/TestLogicalPlanBuilder.java (original) +++ incubator/pig/branches/types/test/org/apache/pig/test/TestLogicalPlanBuilder.java Fri May 23 15:31:28 2008 @@ -35,7 +35,7 @@ import org.apache.pig.LoadFunc; //TODO //Not able to include PigServer.java -//import org.apache.pig.PigServer; +import org.apache.pig.PigServer; import org.apache.pig.builtin.PigStorage; import org.apache.pig.data.DataBag; import org.apache.pig.data.Tuple; @@ -72,7 +72,7 @@ buildPlan(query); } - /* TODO FIX + // TODO FIX Query3 and Query4 @Test public void testQuery3() { String query = "foreach (cogroup (load 'a') by $1, (load 'b') by $1) generate org.apache.pig.builtin.AVG($1) ;"; @@ -84,7 +84,6 @@ String query = "foreach (load 'a') generate AVG($1, $2) ;"; buildPlan(query); } - */ @Test public void testQuery5() { @@ -113,7 +112,7 @@ buildPlan(query); } - /* TODO FIX + // TODO FIX Query11 and Query12 @Test public void testQuery11() { String query = " foreach (group (load 'a') by $1, (load 'b') by $2) generate group, AVG($1) ;"; @@ -125,7 +124,6 @@ String query = "foreach (load 'a' using " + PigStorage.class.getName() + "()) generate AVG($1) ;"; buildPlan(query); } - */ @Test public void testQuery13() { @@ -203,13 +201,12 @@ * User generate functions must be in default package Bug 831620 - fixed */ - /* TODO FIX + // TODO FIX Query17 @Test public void testQuery17() { String query = "foreach (load 'A')" + "generate " + TestApplyFunc.class.getName() + "($1);"; buildPlan(query); } - */ static public class TestApplyFunc extends org.apache.pig.EvalFunc<Tuple> { @@ -333,7 +330,7 @@ buildPlan(query); } - /* TODO FIX + // TODO FIX Query27 and Query28 @Test public void testQuery27() { String query = "foreach (load 'a'){" + @@ -348,7 +345,6 @@ String query = "foreach (load 'a') generate " + TestApplyFunc.class.getName() + "($2, " + TestApplyFunc.class.getName() + "($2.$3));"; buildPlan(query); } - */ @Test public void testQuery29() { @@ -482,25 +478,34 @@ } - /* TODO FIX + // TODO FIX Query39 and Query40 @Test - // TODO: Schemas don't quite work yet public void testQuery39(){ buildPlan("a = load 'a' as (url, host, rank);"); buildPlan("b = group a by (url,host); "); LogicalPlan lp = buildPlan("c = foreach b generate flatten(group.url), SUM(a.rank) as totalRank;"); buildPlan("d = filter c by totalRank > '10';"); - buildPlan("e = foreach d generate url;"); - + buildPlan("e = foreach d generate totalRank;"); + } + + @Test + public void testQueryFail39(){ + buildPlan("a = load 'a' as (url, host, rank);"); + buildPlan("b = group a by (url,host); "); + LogicalPlan lp = buildPlan("c = foreach b generate flatten(group.url), SUM(a.rank) as totalRank;"); + buildPlan("d = filter c by totalRank > '10';"); + try { + buildPlan("e = foreach d generate url;");//url has been falttened and hence the failure + } catch(AssertionFailedError e) { + assertTrue(e.getMessage().contains("Exception")); + } } - @Test public void testQuery40() { buildPlan("a = FILTER (load 'a') BY IsEmpty($2);"); buildPlan("a = FILTER (load 'a') BY (IsEmpty($2) AND ($3 == $2));"); } - */ @Test public void testQuery41() { @@ -548,7 +553,6 @@ //TODO //Commented out testQueryFail44 as I am not able to include org.apache.pig.PigServer; -/* @Test public void testQueryFail44() throws Throwable { PigServer pig = null; @@ -565,7 +569,6 @@ } assertTrue(false); } -*/ /* // Select @@ -782,14 +785,14 @@ @Test public void testQuery66() { - buildPlan("define myFunc = com.mycompany.myudfs.myfunc(int i, chararray c);"); + buildPlan("define myFunc = " + TestApplyFunc.class.getName() + "(int i, chararray c);"); buildPlan("a = load 'input1' as (name, age, gpa);"); buildPlan("b = foreach a generate myFunc($0, $1);"); } @Test public void testQueryFail66() { - buildPlan("define myFunc = com.mycompany.myudfs.myfunc(int i, chararray c);"); + buildPlan("define myFunc = " + TestApplyFunc.class.getName() + "(int i, chararray c);"); buildPlan("a = load 'input1' as (name, age, gpa);"); try { buildPlan("b = foreach a generate myFunc($0, $1, $2);");