pig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dvrya...@apache.org
Subject svn commit: r1380095 - in /pig/trunk: ./ src/org/apache/pig/ src/org/apache/pig/builtin/ src/org/apache/pig/impl/io/ src/org/apache/pig/impl/plan/ src/org/apache/pig/newplan/ src/org/apache/pig/newplan/logical/expression/ src/org/apache/pig/newplan/log...
Date Sun, 02 Sep 2012 23:24:05 GMT
Author: dvryaboy
Date: Sun Sep  2 23:24:04 2012
New Revision: 1380095

URL: http://svn.apache.org/viewvc?rev=1380095&view=rev
Log:
PIG-2882: Use Deque instead of Stack

Modified:
    pig/trunk/CHANGES.txt
    pig/trunk/src/org/apache/pig/EvalFunc.java
    pig/trunk/src/org/apache/pig/PigServer.java
    pig/trunk/src/org/apache/pig/builtin/Utf8StorageConverter.java
    pig/trunk/src/org/apache/pig/impl/io/FileLocalizer.java
    pig/trunk/src/org/apache/pig/impl/plan/PlanVisitor.java
    pig/trunk/src/org/apache/pig/newplan/PlanVisitor.java
    pig/trunk/src/org/apache/pig/newplan/logical/expression/ExpToPhyTranslationVisitor.java
    pig/trunk/src/org/apache/pig/newplan/logical/relational/LOForEach.java
    pig/trunk/src/org/apache/pig/newplan/logical/relational/LogToPhyTranslationVisitor.java
    pig/trunk/src/org/apache/pig/newplan/logical/rules/ConstExpEvaluator.java
    pig/trunk/src/org/apache/pig/newplan/logical/rules/DNFPlanGenerator.java
    pig/trunk/src/org/apache/pig/newplan/optimizer/Rule.java

Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1380095&r1=1380094&r2=1380095&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Sun Sep  2 23:24:04 2012
@@ -24,6 +24,8 @@ INCOMPATIBLE CHANGES
 
 IMPROVEMENTS
 
+PIG-2882: Use Deque instead of Stack (mkhadikov via dvryaboy)
+
 PIG-2781: LOSort isEqual method (xalan via dvryaboy)
 
 PIG-2835: Optimizing the convertion from bytes to Integer/Long (jay23jack via dvryaboy)

Modified: pig/trunk/src/org/apache/pig/EvalFunc.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/EvalFunc.java?rev=1380095&r1=1380094&r2=1380095&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/EvalFunc.java (original)
+++ pig/trunk/src/org/apache/pig/EvalFunc.java Sun Sep  2 23:24:04 2012
@@ -21,8 +21,9 @@ package org.apache.pig;
 import java.io.IOException;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
+import java.util.Deque;
+import java.util.LinkedList;
 import java.util.List;
-import java.util.Stack;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -96,7 +97,7 @@ public abstract class EvalFunc<T>  {
         Class<?> superClass = getClass();
         Type superType = getClass();
         
-        Stack<Type> geneticsStack = new Stack<Type>();
+        Deque<Type> geneticsStack = new LinkedList<Type>();
         
         // Go up the hierachy of the class up to the EvalFunc
         while (!superClass.isAssignableFrom(EvalFunc.class))

Modified: pig/trunk/src/org/apache/pig/PigServer.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/PigServer.java?rev=1380095&r1=1380094&r2=1380095&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/PigServer.java (original)
+++ pig/trunk/src/org/apache/pig/PigServer.java Sun Sep  2 23:24:04 2012
@@ -30,6 +30,7 @@ import java.io.StringWriter;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Deque;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -40,7 +41,6 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.Queue;
 import java.util.Set;
-import java.util.Stack;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.commons.logging.Log;
@@ -132,7 +132,7 @@ public class PigServer {
      * on a new graph. After the nested script is done, the grunt
      * shell pops up the saved graph and continues working on it.
      */
-    protected final Stack<Graph> graphs = new Stack<Graph>();
+    protected final Deque<Graph> graphs = new LinkedList<Graph>();
 
     /*
      * The current Graph the grunt shell is working on.

Modified: pig/trunk/src/org/apache/pig/builtin/Utf8StorageConverter.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/builtin/Utf8StorageConverter.java?rev=1380095&r1=1380094&r2=1380095&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/builtin/Utf8StorageConverter.java (original)
+++ pig/trunk/src/org/apache/pig/builtin/Utf8StorageConverter.java Sun Sep  2 23:24:04 2012
@@ -22,10 +22,10 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.PushbackInputStream;
 import java.util.Arrays;
+import java.util.Deque;
 import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.Map;
-import java.util.Stack;
-import java.util.EmptyStackException;
 
 import org.joda.time.DateTime;
 import org.joda.time.DateTimeZone;
@@ -157,7 +157,7 @@ public class Utf8StorageConverter implem
         }
         else {
             // No inner schema, treat everything inside tuple as bytearray
-            Stack<Character> level = new Stack<Character>();  // keep track of
nested tuple/bag/map. We do not interpret, save them as bytearray
+            Deque<Character> level = new LinkedList<Character>();  // keep track
of nested tuple/bag/map. We do not interpret, save them as bytearray
             mOut = new ByteArrayOutputStream(BUFFER_SIZE);
             while (true) {
                 buf=in.read();
@@ -219,7 +219,7 @@ public class Utf8StorageConverter implem
             
             // Read value
             mOut.reset();
-            Stack<Character> level = new Stack<Character>(); // keep track of
nested tuple/bag/map. We do not interpret, save them as bytearray
+            Deque<Character> level = new LinkedList<Character>(); // keep track
of nested tuple/bag/map. We do not interpret, save them as bytearray
             while (true) {
                 buf=in.read();
                 if (buf==-1) {
@@ -232,12 +232,11 @@ public class Utf8StorageConverter implem
                     break;
                 else if (buf==']' ||buf=='}'||buf==')')
                 {
-                    try {
-                        if (level.peek()==findStartChar((char)buf))
-                            level.pop();
-                    } catch (EmptyStackException e) {
-                        throw new IOException("Malformed map");
-                    }
+                	if (level.isEmpty())
+                		throw new IOException("Malformed map");
+                	
+                    if (level.peek()==findStartChar((char)buf))
+                        level.pop();
                 } else if (buf==','&&level.isEmpty()) { // Current map item complete
                     break;
                 }

Modified: pig/trunk/src/org/apache/pig/impl/io/FileLocalizer.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/impl/io/FileLocalizer.java?rev=1380095&r1=1380094&r2=1380095&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/impl/io/FileLocalizer.java (original)
+++ pig/trunk/src/org/apache/pig/impl/io/FileLocalizer.java Sun Sep  2 23:24:04 2012
@@ -28,11 +28,12 @@ import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.net.URI;
 import java.util.ArrayList;
+import java.util.Deque;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Random;
-import java.util.Stack;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -427,11 +428,11 @@ public class FileLocalizer {
      * Thread local toDelete Stack to hold descriptors to be deleted upon calling
      * deleteTempFiles. Use the toDelete() method to access this stack.
      */
-    private static ThreadLocal<Stack<ElementDescriptor>> toDelete =
-        new ThreadLocal<Stack<ElementDescriptor>>() {
+    private static ThreadLocal<Deque<ElementDescriptor>> toDelete =
+        new ThreadLocal<Deque<ElementDescriptor>>() {
 
-        protected Stack<ElementDescriptor> initialValue() {
-            return new Stack<ElementDescriptor>();
+        protected Deque<ElementDescriptor> initialValue() {
+            return new LinkedList<ElementDescriptor>();
         }
     };
 
@@ -448,7 +449,7 @@ public class FileLocalizer {
      * Convenience accessor method to the toDelete Stack bound to this thread.
      * @return A Stack of ElementDescriptors that should be deleted.
      */
-    private static Stack<ElementDescriptor> toDelete() {
+    private static Deque<ElementDescriptor> toDelete() {
         return toDelete.get();
     }
 
@@ -484,7 +485,7 @@ public class FileLocalizer {
     }
 
     public static void deleteTempFiles() {
-        while (!toDelete().empty()) {
+        while (!toDelete().isEmpty()) {
             try {
                 ElementDescriptor elem = toDelete().pop();
                 elem.delete();

Modified: pig/trunk/src/org/apache/pig/impl/plan/PlanVisitor.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/impl/plan/PlanVisitor.java?rev=1380095&r1=1380094&r2=1380095&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/impl/plan/PlanVisitor.java (original)
+++ pig/trunk/src/org/apache/pig/impl/plan/PlanVisitor.java Sun Sep  2 23:24:04 2012
@@ -17,13 +17,8 @@
  */
 package org.apache.pig.impl.plan;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import java.util.Stack;
+import java.util.Deque;
+import java.util.LinkedList;
 
 /**
  * A visitor mechanism for navigating and operating on a plan of 
@@ -41,7 +36,7 @@ abstract public class PlanVisitor <O ext
      */
     protected PlanWalker<O, P> mCurrentWalker;
 
-    private Stack<PlanWalker<O, P>> mWalkers;
+    private Deque<PlanWalker<O, P>> mWalkers;
 
     /**
      * Entry point for visiting the plan.
@@ -62,7 +57,7 @@ abstract public class PlanVisitor <O ext
     protected PlanVisitor(P plan, PlanWalker<O, P> walker) {
         mPlan = plan;
         mCurrentWalker = walker;
-        mWalkers = new Stack<PlanWalker<O, P>>();
+        mWalkers = new LinkedList<PlanWalker<O, P>>();
     }
 
     /**
@@ -82,7 +77,7 @@ abstract public class PlanVisitor <O ext
      * this case the current walker is not reset.
      */
     protected void popWalker() throws VisitorException {
-        if (mWalkers.empty()) {
+        if (mWalkers.isEmpty()) {
             throw new VisitorException("No more walkers to pop.");
         }
         mCurrentWalker = mWalkers.pop();

Modified: pig/trunk/src/org/apache/pig/newplan/PlanVisitor.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/newplan/PlanVisitor.java?rev=1380095&r1=1380094&r2=1380095&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/newplan/PlanVisitor.java (original)
+++ pig/trunk/src/org/apache/pig/newplan/PlanVisitor.java Sun Sep  2 23:24:04 2012
@@ -18,9 +18,11 @@
 
 package org.apache.pig.newplan;
 
-import java.util.Stack;
+import java.util.Deque;
+import java.util.LinkedList;
 
 import org.apache.pig.impl.logicalLayer.FrontendException;
+import org.apache.pig.impl.plan.VisitorException;
 
 /**
  * A visitor mechanism for navigating and operating on a plan of 
@@ -40,7 +42,7 @@ public abstract class PlanVisitor {
      */
     protected PlanWalker currentWalker;
 
-    private Stack<PlanWalker> walkers;
+    private Deque<PlanWalker> walkers;
 
     /**
      * Entry point for visiting the plan.
@@ -61,7 +63,7 @@ public abstract class PlanVisitor {
     protected PlanVisitor(OperatorPlan plan, PlanWalker walker) {
         this.plan = plan;
         currentWalker = walker;
-        walkers = new Stack<PlanWalker>();
+        walkers = new LinkedList<PlanWalker>();
     }
 
     /**
@@ -81,7 +83,7 @@ public abstract class PlanVisitor {
      * this case the current walker is not reset.
      */
     protected void popWalker() throws FrontendException {
-        if (walkers.empty()) {
+        if (walkers.isEmpty()) {
             throw new FrontendException("No more walkers to pop.", 2221);
         }
         currentWalker = walkers.pop();

Modified: pig/trunk/src/org/apache/pig/newplan/logical/expression/ExpToPhyTranslationVisitor.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/newplan/logical/expression/ExpToPhyTranslationVisitor.java?rev=1380095&r1=1380094&r2=1380095&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/newplan/logical/expression/ExpToPhyTranslationVisitor.java
(original)
+++ pig/trunk/src/org/apache/pig/newplan/logical/expression/ExpToPhyTranslationVisitor.java
Sun Sep  2 23:24:04 2012
@@ -19,9 +19,10 @@ package org.apache.pig.newplan.logical.e
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Deque;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
-import java.util.Stack;
 
 import org.apache.pig.ComparisonFunc;
 import org.apache.pig.EvalFunc;
@@ -89,12 +90,12 @@ public class ExpToPhyTranslationVisitor 
         currentOp = op;
         logToPhyMap = map;
         currentPlan = phyPlan;
-        currentPlans = new Stack<PhysicalPlan>();
+        currentPlans = new LinkedList<PhysicalPlan>();
     }
     
     protected Map<Operator, PhysicalOperator> logToPhyMap;
 
-    protected Stack<PhysicalPlan> currentPlans;
+    protected Deque<PhysicalPlan> currentPlans;
 
     protected PhysicalPlan currentPlan;
 

Modified: pig/trunk/src/org/apache/pig/newplan/logical/relational/LOForEach.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/newplan/logical/relational/LOForEach.java?rev=1380095&r1=1380094&r2=1380095&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/newplan/logical/relational/LOForEach.java (original)
+++ pig/trunk/src/org/apache/pig/newplan/logical/relational/LOForEach.java Sun Sep  2 23:24:04
2012
@@ -18,8 +18,9 @@
 package org.apache.pig.newplan.logical.relational;
 
 import java.util.ArrayList;
+import java.util.Deque;
+import java.util.LinkedList;
 import java.util.List;
-import java.util.Stack;
 
 import org.apache.pig.impl.logicalLayer.FrontendException;
 import org.apache.pig.impl.util.Pair;
@@ -92,7 +93,7 @@ public class LOForEach extends LogicalRe
             		continue;
             	}
             	
-            	Stack<Operator> stack = new Stack<Operator>();
+            	Deque<Operator> stack = new LinkedList<Operator>();
                 List<Operator> succs = referred.getPlan().getSuccessors( src );
                 if( succs != null ) {
                 	for( Operator succ : succs ) {

Modified: pig/trunk/src/org/apache/pig/newplan/logical/relational/LogToPhyTranslationVisitor.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/newplan/logical/relational/LogToPhyTranslationVisitor.java?rev=1380095&r1=1380094&r2=1380095&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/newplan/logical/relational/LogToPhyTranslationVisitor.java
(original)
+++ pig/trunk/src/org/apache/pig/newplan/logical/relational/LogToPhyTranslationVisitor.java
Sun Sep  2 23:24:04 2012
@@ -20,10 +20,11 @@ package org.apache.pig.newplan.logical.r
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Deque;
 import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
-import java.util.Stack;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -98,12 +99,12 @@ public class LogToPhyTranslationVisitor 
         super(plan, new DependencyOrderWalker(plan));
         currentPlan = new PhysicalPlan();
         logToPhyMap = new HashMap<Operator, PhysicalOperator>();
-        currentPlans = new Stack<PhysicalPlan>();
+        currentPlans = new LinkedList<PhysicalPlan>();
     }
 
     protected Map<Operator, PhysicalOperator> logToPhyMap;
 
-    protected Stack<PhysicalPlan> currentPlans;
+    protected Deque<PhysicalPlan> currentPlans;
 
     protected PhysicalPlan currentPlan;
 

Modified: pig/trunk/src/org/apache/pig/newplan/logical/rules/ConstExpEvaluator.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/newplan/logical/rules/ConstExpEvaluator.java?rev=1380095&r1=1380094&r2=1380095&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/newplan/logical/rules/ConstExpEvaluator.java (original)
+++ pig/trunk/src/org/apache/pig/newplan/logical/rules/ConstExpEvaluator.java Sun Sep  2 23:24:04
2012
@@ -17,6 +17,8 @@
  */
 package org.apache.pig.newplan.logical.rules;
 
+import java.util.Deque;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Stack;
 
@@ -43,11 +45,11 @@ import org.apache.pig.impl.util.Pair;
  *
  */
 class ConstExpEvaluator extends LogicalExpressionVisitor {
-    Stack<ConstantExpression> result;
+    Deque<ConstantExpression> result;
 
     ConstExpEvaluator(OperatorPlan plan) throws FrontendException {
         super(plan, new ReverseDependencyOrderWalker(plan));
-        result = new Stack<ConstantExpression>();
+        result = new LinkedList<ConstantExpression>();
     }
 
     @SuppressWarnings("unchecked")

Modified: pig/trunk/src/org/apache/pig/newplan/logical/rules/DNFPlanGenerator.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/newplan/logical/rules/DNFPlanGenerator.java?rev=1380095&r1=1380094&r2=1380095&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/newplan/logical/rules/DNFPlanGenerator.java (original)
+++ pig/trunk/src/org/apache/pig/newplan/logical/rules/DNFPlanGenerator.java Sun Sep  2 23:24:04
2012
@@ -17,7 +17,8 @@
  */
 package org.apache.pig.newplan.logical.rules;
 
-import java.util.Stack;
+import java.util.Deque;
+import java.util.LinkedList;
 import org.apache.pig.impl.logicalLayer.FrontendException;
 import org.apache.pig.newplan.logical.expression.*;
 import org.apache.pig.newplan.ReverseDependencyOrderWalker;
@@ -35,15 +36,15 @@ import org.apache.pig.newplan.OperatorPl
  */
 class DNFPlanGenerator extends LogicalExpressionVisitor {
     private OperatorPlan dnfPlan = null;
-    Stack<LogicalExpression> result;
+    Deque<LogicalExpression> result;
 
     DNFPlanGenerator(OperatorPlan plan) throws FrontendException {
         super(plan, new ReverseDependencyOrderWalker(plan));
-        result = new Stack<LogicalExpression>();
+        result = new LinkedList<LogicalExpression>();
     }
 
     OperatorPlan getDNFPlan() {
-        if (dnfPlan == null) dnfPlan = (result.empty() ? plan : result.pop().getPlan());
+        if (dnfPlan == null) dnfPlan = (result.isEmpty() ? plan : result.pop().getPlan());
         return dnfPlan;
     }
 

Modified: pig/trunk/src/org/apache/pig/newplan/optimizer/Rule.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/newplan/optimizer/Rule.java?rev=1380095&r1=1380094&r2=1380095&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/newplan/optimizer/Rule.java (original)
+++ pig/trunk/src/org/apache/pig/newplan/optimizer/Rule.java Sun Sep  2 23:24:04 2012
@@ -19,11 +19,12 @@
 package org.apache.pig.newplan.optimizer;
 
 import java.util.ArrayList;
+import java.util.Deque;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Set;
-import java.util.Stack;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -238,7 +239,7 @@ public abstract class Rule {
             }
             
             for(int i=0; i<planOps.size(); i++) {
-                Stack<Operator> s = new Stack<Operator>();
+                Deque<Operator> s = new LinkedList<Operator>();
                 if (!check(planOps.get(i), patternOps.get(i), s)) {
                     return false;
                 }
@@ -266,7 +267,7 @@ public abstract class Rule {
          * if we are looking for join->load pattern, only one match will be returned instead
          * of two, so that the matched subsets don't share nodes.
          */ 
-        private boolean check(Operator planOp, Operator patternOp, Stack<Operator>
opers) throws FrontendException {
+        private boolean check(Operator planOp, Operator patternOp, Deque<Operator>
opers) throws FrontendException {
             if (!match(planOp, patternOp)) {
                 return false;
             }



Mime
View raw message