Author: daijy
Date: Fri Oct  9 21:14:30 2009
New Revision: 823693

URL: http://svn.apache.org/viewvc?rev=823693&view=rev
Log:
PIG-995: Limit Optimizer throw exception 'ERROR 2156: Error while fixing 
projections'

Modified:
    hadoop/pig/trunk/CHANGES.txt
    
hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/optimizer/LogicalOptimizer.java
    hadoop/pig/trunk/test/org/apache/pig/test/TestLogicalOptimizer.java

Modified: hadoop/pig/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/CHANGES.txt?rev=823693&r1=823692&r2=823693&view=diff
==============================================================================
--- hadoop/pig/trunk/CHANGES.txt (original)
+++ hadoop/pig/trunk/CHANGES.txt Fri Oct  9 21:14:30 2009
@@ -60,6 +60,8 @@
 
 PIG-894: order-by fails when input is empty (daijy)
 
+PIG-995: Limit Optimizer throw exception "ERROR 2156: Error while fixing 
projections" (daijy)
+
 Release 0.5.0 - Unreleased
 
 INCOMPATIBLE CHANGES

Modified: 
hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/optimizer/LogicalOptimizer.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/optimizer/LogicalOptimizer.java?rev=823693&r1=823692&r2=823693&view=diff
==============================================================================
--- 
hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/optimizer/LogicalOptimizer.java
 (original)
+++ 
hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/optimizer/LogicalOptimizer.java
 Fri Oct  9 21:14:30 2009
@@ -168,6 +168,7 @@
         //the code that follows is a copy of the code in the
         //base class. see the todo note in the base class
         boolean sawMatch = false;
+        boolean initialized = false;
         int numIterations = 0;
         do {
             sawMatch = false;
@@ -180,22 +181,21 @@
                     for (List<LogicalOperator> match:matches)
                     {
                         if (rule.getTransformer().check(match)) {
-                            // The transformer approves.
-                            sawMatch = true;
-                            rule.getTransformer().transform(match);
                             try {
+                                // The transformer approves.
+                                sawMatch = true;
+                                if (!initialized)
+                                {
+                                    
((LogicalTransformer)rule.getTransformer()).rebuildSchemas();
+                                    
((LogicalTransformer)rule.getTransformer()).rebuildProjectionMaps();
+                                    initialized = true;
+                                }
+                                rule.getTransformer().transform(match);
                                 
((LogicalTransformer)rule.getTransformer()).rebuildSchemas();
-                            } catch (FrontendException fee) {
-                                int errCode = 2145;
-                                String msg = "Problem while rebuilding schemas 
after transformation.";
-                                throw new OptimizerException(msg, errCode, 
PigException.BUG, fee);
-                            }
-
-                            try {
                                 
((LogicalTransformer)rule.getTransformer()).rebuildProjectionMaps();
                             } catch (FrontendException fee) {
                                 int errCode = 2145;
-                                String msg = "Problem while rebuilding 
projection maps after transformation.";
+                                String msg = "Problem while rebuilding 
projection map or schema in logical optimizer.";
                                 throw new OptimizerException(msg, errCode, 
PigException.BUG, fee);
                             }
 

Modified: hadoop/pig/trunk/test/org/apache/pig/test/TestLogicalOptimizer.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/test/org/apache/pig/test/TestLogicalOptimizer.java?rev=823693&r1=823692&r2=823693&view=diff
==============================================================================
--- hadoop/pig/trunk/test/org/apache/pig/test/TestLogicalOptimizer.java 
(original)
+++ hadoop/pig/trunk/test/org/apache/pig/test/TestLogicalOptimizer.java Fri Oct 
 9 21:14:30 2009
@@ -241,6 +241,14 @@
         } catch(Exception e) {
             assertTrue(((OptimizerException)e).getErrorCode() == 2052);
         }
-    }    
+    }
+    
+    @Test
+    //See bug PIG-995
+    //We shall throw no exception here
+    public void testOPLimit11Optimizer() throws Exception {
+        LogicalPlan plan = planTester.buildPlan("B = foreach (limit (order 
(load 'myfile' AS (a0, a1, a2)) by $1) 10) generate $0;");
+        optimizePlan(plan);
+    }
 }
 


Reply via email to