Author: pisong
Date: Tue Jul  8 04:56:47 2008
New Revision: 674780

URL: http://svn.apache.org/viewvc?rev=674780&view=rev
Log:
PIG-288: NPE in Optimizer

Modified:
    
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOCogroup.java
    
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/optimizer/LogicalTransformer.java
    
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/optimizer/SchemaCalculator.java
    incubator/pig/branches/types/src/org/apache/pig/impl/plan/MultiMap.java

Modified: 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOCogroup.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOCogroup.java?rev=674780&r1=674779&r2=674780&view=diff
==============================================================================
--- 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOCogroup.java
 (original)
+++ 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOCogroup.java
 Tue Jul  8 04:56:47 2008
@@ -273,4 +273,23 @@
         v.visit(this);
     }
 
+    /***
+     *
+     * This does switch the mapping
+     *
+     * oldOp -> List of inner plans
+     *         to
+     * newOp -> List of inner plans
+     *
+     * which is useful when there is a structural change in LogicalPlan
+     *
+     * @param oldOp the old operator
+     * @param newOp the new operator
+     */
+    public void switchGroupByPlanOp(LogicalOperator oldOp,
+                                    LogicalOperator newOp) {
+        Collection<LogicalPlan> innerPlans = mGroupByPlans.removeKey(oldOp) ;
+        mGroupByPlans.put(newOp, innerPlans);
+    }
+
 }

Modified: 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/optimizer/LogicalTransformer.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/optimizer/LogicalTransformer.java?rev=674780&r1=674779&r2=674780&view=diff
==============================================================================
--- 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/optimizer/LogicalTransformer.java
 (original)
+++ 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/optimizer/LogicalTransformer.java
 Tue Jul  8 04:56:47 2008
@@ -130,7 +130,7 @@
      * successors and reconnecting them to the new node as well as rebuilding
      * all of the schemas.
      * @param after Node to insert the new node after
-     * @param newnode New node to insert
+     * @param newNode New node to insert
      * @param before Node to insert this node before
      * @param projectionMapping A map that defines how projections in after
      * relate to projections in newnode.  Keys are the projection offsets in
@@ -148,6 +148,12 @@
         mPlan.add(newNode);
         mPlan.insertBetween(after, newNode, before);
 
+        // Fix up COGroup internal wiring
+        if (before instanceof LOCogroup) {
+            LOCogroup cg = (LOCogroup) before ;
+            cg.switchGroupByPlanOp(after, newNode);
+        }
+
         // Visit all the inner plans of before and change their projects to
         // connect to newNode instead of after.
         // Find right inner plan(s) to visit
@@ -181,7 +187,7 @@
      * all of the schemas.  This function
      * assumes that the node has only one predecessor.
      * @param after Node to insert the new node after
-     * @param newnode New node to insert
+     * @param newNode New node to insert
      * @param projectionMapping A map that defines how projections in after
      * relate to projections in newnode.  Keys are the projection offsets in
      * after, values are the new offsets in newnode.  If this field is null,

Modified: 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/optimizer/SchemaCalculator.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/optimizer/SchemaCalculator.java?rev=674780&r1=674779&r2=674780&view=diff
==============================================================================
--- 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/optimizer/SchemaCalculator.java
 (original)
+++ 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/optimizer/SchemaCalculator.java
 Tue Jul  8 04:56:47 2008
@@ -186,7 +186,7 @@
      * 
      * @param regexp
      *            the logical regexp operator that has to be visited
-     * @throws ParseException
+     * @throws VisitorException
      */
     protected void visit(LORegexp regexp) throws VisitorException {
         try {
@@ -207,12 +207,7 @@
     }
     
     protected void visit(LOStore store) throws VisitorException{
-        try {
-            store.getSchema();
-            super.visit(store);
-        } catch (FrontendException fe) {
-            throw new VisitorException(fe);
-        }
+        // We don't calculate schema of LOStore
     }
     
     protected void visit(LOConst c) throws VisitorException{

Modified: 
incubator/pig/branches/types/src/org/apache/pig/impl/plan/MultiMap.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/plan/MultiMap.java?rev=674780&r1=674779&r2=674780&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/impl/plan/MultiMap.java 
(original)
+++ incubator/pig/branches/types/src/org/apache/pig/impl/plan/MultiMap.java Tue 
Jul  8 04:56:47 2008
@@ -114,6 +114,15 @@
     }
 
     /**
+     * Remove all the values associated with the given key
+     * @param key the key to be removed
+     * @return list of all value being removed
+     */
+    public Collection<V> removeKey(K key) {
+        return mMap.remove(key) ;
+    }
+
+    /**
      * Get a set of all the keys in this map.
      * @return Set of keys.
      */


Reply via email to