pig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From knogu...@apache.org
Subject svn commit: r1831606 - in /pig/trunk: CHANGES.txt src/org/apache/pig/newplan/logical/expression/ProjectExpression.java test/org/apache/pig/test/TestProjectRange.java
Date Tue, 15 May 2018 04:20:52 GMT
Author: knoguchi
Date: Tue May 15 04:20:52 2018
New Revision: 1831606

URL: http://svn.apache.org/viewvc?rev=1831606&view=rev
Log:
PIG-5335: Error message from range projection completely misleading (knoguchi)

Modified:
    pig/trunk/CHANGES.txt
    pig/trunk/src/org/apache/pig/newplan/logical/expression/ProjectExpression.java
    pig/trunk/test/org/apache/pig/test/TestProjectRange.java

Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1831606&r1=1831605&r2=1831606&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Tue May 15 04:20:52 2018
@@ -65,6 +65,9 @@ PIG-5251: Bump joda-time to 2.9.9 (dbist
 OPTIMIZATIONS
  
 BUG FIXES
+
+PIG-5335: Error message from range projection completely misleading (knoguchi)
+
 PIG-5333: LoadCaster sometimes not set for complex type (knoguchi)
 
 PIG-5328: expressionOperator Divide.equalsZero(DataType.BIGDECIMAL) is invalid (michaelthoward
via knoguchi)

Modified: pig/trunk/src/org/apache/pig/newplan/logical/expression/ProjectExpression.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/newplan/logical/expression/ProjectExpression.java?rev=1831606&r1=1831605&r2=1831606&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/newplan/logical/expression/ProjectExpression.java (original)
+++ pig/trunk/src/org/apache/pig/newplan/logical/expression/ProjectExpression.java Tue May
15 04:20:52 2018
@@ -372,9 +372,20 @@ public class ProjectExpression extends C
                         }
                     }
                 }
-                if (index==-1) {
-                    if (alias!=null) {
-                        index = schema.getFieldPosition(alias);
+                if (index==-1 && alias != null) {
+                    index = schema.getFieldPosition(alias);
+                    if( index == -1 ) {
+                        // Return a place holder for this invalid field reference.
+                        // If this relation is used, error will be caught in the
+                        // LogicalPlan.validate phase.
+                        // New uid is assigned to this fake field so that invalid script
+                        // like the one on
+                        // TestColumnAliasConversion.testInvalidNestedProjection
+                        // would not fail at LogicalPlanBuilder phase
+                        // but fail at LogicalPlan.validate phase.
+                        // (PIG-5335 for more details)
+                        return new LogicalSchema.LogicalFieldSchema(alias, null, DataType.BYTEARRAY,
+                                                                   LogicalExpression.getNextUid());
                     }
                 }
                 if (index==-1)

Modified: pig/trunk/test/org/apache/pig/test/TestProjectRange.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestProjectRange.java?rev=1831606&r1=1831605&r2=1831606&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestProjectRange.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestProjectRange.java Tue May 15 04:20:52 2018
@@ -19,6 +19,7 @@
 package org.apache.pig.test;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 import java.io.File;
 import java.io.IOException;
@@ -33,6 +34,7 @@ import org.apache.pig.data.Tuple;
 import org.apache.pig.impl.logicalLayer.FrontendException;
 import org.apache.pig.impl.logicalLayer.schema.Schema;
 import org.apache.pig.impl.logicalLayer.schema.Schema.FieldSchema;
+import org.apache.pig.impl.plan.PlanValidationException;
 import org.apache.pig.impl.util.Utils;
 import org.apache.pig.newplan.logical.expression.LogicalExpressionPlan;
 import org.apache.pig.newplan.logical.relational.LOCogroup;
@@ -373,6 +375,37 @@ public class TestProjectRange  {
     }
 
     /**
+     * -ve test cases
+     * @throws IOException
+     * @throws ParserException
+     */
+    @Test
+    public void testNegativeForeachFollowedByRange() throws IOException, ParserException
{
+        String query =
+            "A = load '" + INP_FILE_5FIELDS + "'  as (a0,a1,a2,a3,a4);"
+            + "B = FOREACH A GENERATE a0, b1, a2, a3, a4;"
+            + "C = FOREACH B GENERATE a0..a2;";
+
+        // In PIG-5335, above query was failing at parsing time
+        // and error message didn't even mention "b1".
+        // (below generateLogicalPlan was throwing ParserException)
+        LogicalPlan lp = generateLogicalPlan(query);
+
+        // After PIG-5335, we moved the error to be caught
+        // at validation phase AND have proper error message
+        // pointing to an invalid fieldname, b1.
+        boolean exceptionCaught = false;
+        try {
+            lp.validate(pigServer.getPigContext(), "test", false);
+        } catch (PlanValidationException ex) {
+            Util.checkMessageInException(ex,
+             "Projected field [b1] does not exist in schema: a0:bytearray,a1:bytearray,a2:bytearray,a3:bytearray,a4:bytearray");
+            exceptionCaught = true;
+        }
+        assertTrue("No exception was thrown from an invalid script", exceptionCaught);
+    }
+
+    /**
      * Test foreach without schema
      * @throws IOException
      * @throws ParserException



Mime
View raw message