You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by xu...@apache.org on 2011/04/21 18:28:52 UTC

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

Author: xuefu
Date: Thu Apr 21 16:28:52 2011
New Revision: 1095771

URL: http://svn.apache.org/viewvc?rev=1095771&view=rev
Log:
Pig gives incorrect error message dealing with scalar projection

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

Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1095771&r1=1095770&r2=1095771&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Thu Apr 21 16:28:52 2011
@@ -42,6 +42,8 @@ PIG-1876: Typed map for Pig (daijy)
 
 IMPROVEMENTS
 
+PIG-2000: Pig gives incorrect error message dealing with scalar projection (xuefu)
+
 PIG-2002: Regression: Pig gives error "Projection with nothing to reference!" for a valid query (xuefu)
 
 PIG-1921: Improve error messages in new parser (xuefu)

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=1095771&r1=1095770&r2=1095771&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/parser/LogicalPlanGenerator.g (original)
+++ pig/trunk/src/org/apache/pig/parser/LogicalPlanGenerator.g Thu Apr 21 16:28:52 2011
@@ -753,38 +753,52 @@ var_expr[LogicalExpressionPlan plan] ret
    ( dot_proj 
      {
          columns = $dot_proj.cols;
+         boolean processScalar = false;
          if( $expr instanceof ScalarExpression ) {
+             List<Operator> succs = plan.getSuccessors( $expr );
+             if( succs == null || succs.size() == 0 ) {
+                 // We haven't process this scalar projection yet. Set the flag so as to process it next.
+                 // This will handle a projection such as A.u.x, where we need to build ScalarExpression
+                 // for A.u, while for x, we need to treat it as a normal dereference (on the output of
+                 // the ScalarExpression.
+                 processScalar = true;
+             }
+         }
+         
+         if( processScalar ) {
              // This is a scalar projection.
              ScalarExpression scalarExpr = (ScalarExpression)$expr;
+             
              if( $dot_proj.cols.size() > 1 ) {
                  throw new InvalidScalarProjectionException( input, loc, scalarExpr );
-             } else {
-                 Object val = $dot_proj.cols.get( 0 );
-                 int pos = -1;
-                 LogicalRelationalOperator relOp = (LogicalRelationalOperator)scalarExpr.getImplicitReferencedOperator();
-                 LogicalSchema schema = null;
-                 try {
-                     schema = relOp.getSchema();
-                 } catch(FrontendException e) {
-                     throw new PlanGenerationFailureException( input, loc, e );
+             }
+             
+             Object val = $dot_proj.cols.get( 0 );
+             int pos = -1;
+             LogicalRelationalOperator relOp = (LogicalRelationalOperator)scalarExpr.getImplicitReferencedOperator();
+             LogicalSchema schema = null;
+             try {
+                 schema = relOp.getSchema();
+             } catch(FrontendException e) {
+                 throw new PlanGenerationFailureException( input, loc, e );
+             }
+             if( val instanceof Integer ) {
+                 pos = (Integer)val;
+                 if( schema != null && pos >= schema.size() ) {
+                     throw new InvalidScalarProjectionException( input, loc, scalarExpr );
                  }
-                 if( val instanceof Integer ) {
-                     pos = (Integer)val;
-                     if( schema != null && pos >= schema.size() ) {
-                         throw new InvalidScalarProjectionException( input, loc, scalarExpr );
-                     }
-                 } else {
-                     String colAlias = (String)val;
-                     pos = schema.getFieldPosition( colAlias );
-                     if( schema == null || pos == -1 ) {
-                         throw new InvalidScalarProjectionException( input, loc, scalarExpr );
-                     }
+             } else {
+                 String colAlias = (String)val;
+                 pos = schema.getFieldPosition( colAlias );
+                 if( schema == null || pos == -1 ) {
+                     throw new InvalidScalarProjectionException( input, loc, scalarExpr );
                  }
-                 ConstantExpression constExpr = new ConstantExpression( $plan, pos);
-                 plan.connect( $expr, constExpr );
-                 constExpr = new ConstantExpression( $plan, "filename"); // place holder for file name.
-                 plan.connect( $expr, constExpr );
              }
+             
+             ConstantExpression constExpr = new ConstantExpression( $plan, pos);
+             plan.connect( $expr, constExpr );
+             constExpr = new ConstantExpression( $plan, "filename"); // place holder for file name.
+             plan.connect( $expr, constExpr );
          } else {
              DereferenceExpression e = new DereferenceExpression( $plan );
              e.setRawColumns( $dot_proj.cols );

Modified: pig/trunk/test/org/apache/pig/parser/TestScalarVisitor.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/parser/TestScalarVisitor.java?rev=1095771&r1=1095770&r2=1095771&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/parser/TestScalarVisitor.java (original)
+++ pig/trunk/test/org/apache/pig/parser/TestScalarVisitor.java Thu Apr 21 16:28:52 2011
@@ -57,6 +57,18 @@ public class TestScalarVisitor {
         System.out.println( "New Logical Plan after scalar processing: " + plan );
     }
 
+    @Test // PIG-2000
+    public void test3() throws Exception, ParsingFailureException, IOException {
+        String query = "A = load 'x' as ( u:tuple(x:int, y:chararray), v:long, w:bytearray);\n" + 
+                       "B = load 'y';\n" +
+                       "C = foreach B generate $0, A.u.x;\n" +
+                       "D = store C into 'output';";
+        LogicalPlan plan = visit( query );
+        Assert.assertEquals( 2, plan.getSources().size() ); // There should be two LOLoad op in the plan.
+        Assert.assertEquals( 2, plan.getSinks().size() ); // There should be also two LOStore op in the plan.
+        System.out.println( "New Logical Plan after scalar processing: " + plan );
+    }
+
     @Test
     public void testNegative1() throws RecognitionException, ParsingFailureException, IOException {
         String query = "A = load 'x'; " +