You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by an...@apache.org on 2013/11/26 20:21:02 UTC

svn commit: r1545789 - in /pig/trunk: CHANGES.txt src/org/apache/pig/parser/LogicalPlanGenerator.g test/org/apache/pig/test/TestPigServer.java

Author: aniket486
Date: Tue Nov 26 19:21:01 2013
New Revision: 1545789

URL: http://svn.apache.org/r1545789
Log:
PIG-3581: Incorrect scope resolution with nested foreach (aniket486)

Modified:
    pig/trunk/CHANGES.txt
    pig/trunk/src/org/apache/pig/parser/LogicalPlanGenerator.g
    pig/trunk/test/org/apache/pig/test/TestPigServer.java

Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1545789&r1=1545788&r2=1545789&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Tue Nov 26 19:21:01 2013
@@ -54,6 +54,8 @@ OPTIMIZATIONS
  
 BUG FIXES
 
+PIG-3581: Incorrect scope resolution with nested foreach (aniket486)
+
 PIG-3285: Jobs using HBaseStorage fail to ship dependency jars (ndimiduk via cheolsoo)
 
 PIG-3582: Document SUM, MIN, MAX, and AVG functions for BigInteger and BigDecimal (harichinnan via cheolsoo)

Modified: pig/trunk/src/org/apache/pig/parser/LogicalPlanGenerator.g
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/parser/LogicalPlanGenerator.g?rev=1545789&r1=1545788&r2=1545789&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/parser/LogicalPlanGenerator.g (original)
+++ pig/trunk/src/org/apache/pig/parser/LogicalPlanGenerator.g Tue Nov 26 19:21:01 2013
@@ -1759,15 +1759,17 @@ alias_col_ref[LogicalExpressionPlan plan
            throw new PlanGenerationFailureException( input, loc, e );
        }
 
-       Operator op = builder.lookupOperator( alias );
-       if( op != null && ( schema == null || schema.getFieldPosition( alias ) == -1 ) ) {
-           $expr = new ScalarExpression( plan, op,
-               inForeachPlan ? $foreach_clause::foreachOp : $GScope::currentOp );
-           $expr.setLocation( loc );
+       // PIG-3581
+       // check within foreach scope before looking at outer scope for scalar
+       if( inForeachPlan && ($foreach_plan::operators).containsKey(alias)) {
+           $expr = builder.buildProjectExpr( loc, $plan, $GScope::currentOp,
+               $foreach_plan::operators, $foreach_plan::exprPlans, alias, 0 );
        } else {
-           if( inForeachPlan ) {
-               $expr = builder.buildProjectExpr( loc, $plan, $GScope::currentOp,
-                    $foreach_plan::operators, $foreach_plan::exprPlans, alias, 0 );
+           Operator op = builder.lookupOperator( alias );
+           if( op != null && ( schema == null || schema.getFieldPosition( alias ) == -1 ) ) {
+               $expr = new ScalarExpression( plan, op,
+                   inForeachPlan ? $foreach_clause::foreachOp : $GScope::currentOp );
+               $expr.setLocation( loc );
            } else {
                $expr = builder.buildProjectExpr( loc, $plan, $GScope::currentOp,
                    $statement::inputIndex, alias, 0 );

Modified: pig/trunk/test/org/apache/pig/test/TestPigServer.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestPigServer.java?rev=1545789&r1=1545788&r2=1545789&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestPigServer.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestPigServer.java Tue Nov 26 19:21:01 2013
@@ -500,6 +500,34 @@ public class TestPigServer {
         assertEquals(expectedSchema, dumpedSchema);
     }
 
+    private void registerScalarScript(boolean useScalar, String expectedSchemaStr) throws IOException {
+        pig.registerQuery("A = load 'adata' AS (a: int, b: int);");
+        //scalar
+        pig.registerQuery("C = FOREACH A GENERATE *;");
+        String overrideScalar = useScalar ? "C = FILTER A BY b % 2 == 0; " : "";
+        pig.registerQuery("B = FOREACH (GROUP A BY a) { " +
+                overrideScalar +
+                "D = FILTER A BY b % 2 == 1;" +
+                "GENERATE group AS a, A.b AS every, C.b AS even, D.b AS odd;" +
+                "};");
+        Schema dumpedSchema = pig.dumpSchema("B");
+        Schema expectedSchema = Utils.getSchemaFromString(
+                expectedSchemaStr);
+        assertEquals(expectedSchema, dumpedSchema);
+    }
+
+    // PIG-3581
+    @Test
+    public void testScalarPrecedence() throws Throwable {
+        registerScalarScript(true, "a: int,every: {(b: int)},even: {(b: int)},odd: {(b: int)}");
+    }
+
+    // PIG-3581
+    @Test
+    public void testScalarResolution() throws Throwable {
+        registerScalarScript(false, "a: int,every: {(b: int)},even: int,odd: {(b: int)}");
+    }
+
     @Test
     public void testExplainXmlComplex() throws Throwable {
         pig.registerQuery("a = load 'a' as (site: chararray, count: int, itemCounts: bag { itemCountsTuple: tuple (type: chararray, typeCount: int, f: float, m: map[]) } ) ;") ;