asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject [16/51] [partial] incubator-asterixdb-hyracks git commit: Change folder structure for Java repackage
Date Tue, 25 Aug 2015 16:41:29 GMT
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/AbstractIntroduceCombinerRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/AbstractIntroduceCombinerRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/AbstractIntroduceCombinerRule.java
deleted file mode 100644
index 67b2d0c..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/AbstractIntroduceCombinerRule.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * Copyright 2009-2013 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.hyracks.algebricks.rewriter.rules;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.commons.lang3.mutable.Mutable;
-import org.apache.commons.lang3.mutable.MutableObject;
-
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.common.utils.Pair;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.IOptimizationContext;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalVariable;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.functions.IFunctionInfo;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator.ExecutionMode;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.NestedTupleSourceOperator;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-public abstract class AbstractIntroduceCombinerRule implements IAlgebraicRewriteRule {
-
-    @Override
-    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) {
-        return false;
-    }
-
-    /**
-     * Replace the original aggregate functions with their corresponding global aggregate function.
-     */
-    protected void replaceOriginalAggFuncs(Set<SimilarAggregatesInfo> toReplaceSet) {
-        for (SimilarAggregatesInfo sai : toReplaceSet) {
-            for (AggregateExprInfo aei : sai.simAggs) {
-                AbstractFunctionCallExpression afce = (AbstractFunctionCallExpression) aei.aggExprRef.getValue();
-                afce.setFunctionInfo(aei.newFunInfo);
-                afce.getArguments().clear();
-                afce.getArguments().add(new MutableObject<ILogicalExpression>(sai.stepOneResult));
-            }
-        }
-    }
-
-    protected Pair<Boolean, Mutable<ILogicalOperator>> tryToPushAgg(AggregateOperator initAgg,
-            GroupByOperator newGbyOp, Set<SimilarAggregatesInfo> toReplaceSet, IOptimizationContext context)
-            throws AlgebricksException {
-
-        ArrayList<LogicalVariable> pushedVars = new ArrayList<LogicalVariable>();
-        ArrayList<Mutable<ILogicalExpression>> pushedExprs = new ArrayList<Mutable<ILogicalExpression>>();
-
-        List<LogicalVariable> initVars = initAgg.getVariables();
-        List<Mutable<ILogicalExpression>> initExprs = initAgg.getExpressions();
-        int numExprs = initVars.size();
-
-        // First make sure that all agg funcs are two step, otherwise we cannot use local aggs.
-        for (int i = 0; i < numExprs; i++) {
-            AggregateFunctionCallExpression aggFun = (AggregateFunctionCallExpression) initExprs.get(i).getValue();
-            if (!aggFun.isTwoStep()) {
-                return new Pair<Boolean, Mutable<ILogicalOperator>>(false, null);
-            }
-        }
-
-        boolean haveAggToReplace = false;
-        for (int i = 0; i < numExprs; i++) {
-            Mutable<ILogicalExpression> expRef = initExprs.get(i);
-            AggregateFunctionCallExpression aggFun = (AggregateFunctionCallExpression) expRef.getValue();
-            IFunctionInfo fi1 = aggFun.getStepOneAggregate();
-            // Clone the aggregate's args.
-            List<Mutable<ILogicalExpression>> newArgs = new ArrayList<Mutable<ILogicalExpression>>(aggFun
-                    .getArguments().size());
-            for (Mutable<ILogicalExpression> er : aggFun.getArguments()) {
-                newArgs.add(new MutableObject<ILogicalExpression>(er.getValue().cloneExpression()));
-            }
-            IFunctionInfo fi2 = aggFun.getStepTwoAggregate();
-
-            SimilarAggregatesInfo inf = new SimilarAggregatesInfo();
-            LogicalVariable newAggVar = context.newVar();
-            pushedVars.add(newAggVar);
-            inf.stepOneResult = new VariableReferenceExpression(newAggVar);
-            inf.simAggs = new ArrayList<AggregateExprInfo>();
-            toReplaceSet.add(inf);
-            AggregateFunctionCallExpression aggLocal = new AggregateFunctionCallExpression(fi1, false, newArgs);
-            pushedExprs.add(new MutableObject<ILogicalExpression>(aggLocal));
-            AggregateExprInfo aei = new AggregateExprInfo();
-            aei.aggExprRef = expRef;
-            aei.newFunInfo = fi2;
-            inf.simAggs.add(aei);
-            haveAggToReplace = true;
-        }
-
-        if (!pushedVars.isEmpty()) {
-            AggregateOperator pushedAgg = new AggregateOperator(pushedVars, pushedExprs);
-            pushedAgg.setExecutionMode(ExecutionMode.LOCAL);
-            // If newGbyOp is null, then we optimizing an aggregate without group by.
-            if (newGbyOp != null) {
-                // Cut and paste nested input pipelines of initAgg to pushedAgg's input
-                Mutable<ILogicalOperator> inputRef = initAgg.getInputs().get(0);
-                Mutable<ILogicalOperator> bottomRef = inputRef;
-                while (bottomRef.getValue().getInputs().size() > 0) {
-                    bottomRef = bottomRef.getValue().getInputs().get(0);
-                }
-                ILogicalOperator oldNts = bottomRef.getValue();
-                initAgg.getInputs().clear();
-                initAgg.getInputs().add(new MutableObject<ILogicalOperator>(oldNts));
-
-                // Hook up the nested aggregate op with the outer group by.
-                NestedTupleSourceOperator nts = new NestedTupleSourceOperator(new MutableObject<ILogicalOperator>(
-                        newGbyOp));
-                nts.setExecutionMode(ExecutionMode.LOCAL);
-                bottomRef.setValue(nts);
-                pushedAgg.getInputs().add(inputRef);
-            } else {
-                // The local aggregate operator is fed by the input of the original aggregate operator.
-                pushedAgg.getInputs().add(new MutableObject<ILogicalOperator>(initAgg.getInputs().get(0).getValue()));
-                // Reintroduce assign op for the global agg partitioning var.
-                initAgg.getInputs().get(0).setValue(pushedAgg);
-                pushedAgg.setGlobal(false);
-                context.computeAndSetTypeEnvironmentForOperator(pushedAgg);
-            }
-            return new Pair<Boolean, Mutable<ILogicalOperator>>(true, new MutableObject<ILogicalOperator>(pushedAgg));
-        } else {
-            return new Pair<Boolean, Mutable<ILogicalOperator>>(haveAggToReplace, null);
-        }
-    }
-
-    protected class SimilarAggregatesInfo {
-        ILogicalExpression stepOneResult;
-        List<AggregateExprInfo> simAggs;
-    }
-
-    protected class AggregateExprInfo {
-        Mutable<ILogicalExpression> aggExprRef;
-        IFunctionInfo newFunInfo;
-    }
-
-    protected class BookkeepingInfo {
-        Map<GroupByOperator, List<LogicalVariable>> modifyGbyMap = new HashMap<GroupByOperator, List<LogicalVariable>>();
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/AbstractIntroduceGroupByCombinerRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/AbstractIntroduceGroupByCombinerRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/AbstractIntroduceGroupByCombinerRule.java
deleted file mode 100644
index b60c80d..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/AbstractIntroduceGroupByCombinerRule.java
+++ /dev/null
@@ -1,340 +0,0 @@
-/*
- * Copyright 2009-2013 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.hyracks.algebricks.rewriter.rules;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.commons.lang3.mutable.Mutable;
-import org.apache.commons.lang3.mutable.MutableObject;
-
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.common.utils.ListSet;
-import edu.uci.ics.hyracks.algebricks.common.utils.Pair;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalPlan;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.IOptimizationContext;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalVariable;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.OperatorAnnotations;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator.ExecutionMode;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractOperatorWithNestedPlans;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.visitors.IsomorphismUtilities;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.visitors.VariableUtilities;
-import edu.uci.ics.hyracks.algebricks.core.algebra.plan.ALogicalPlanImpl;
-import edu.uci.ics.hyracks.algebricks.core.algebra.util.OperatorPropertiesUtil;
-
-public abstract class AbstractIntroduceGroupByCombinerRule extends AbstractIntroduceCombinerRule {
-
-    @Override
-    public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
-            throws AlgebricksException {
-        AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
-        if (context.checkIfInDontApplySet(this, op)) {
-            return false;
-        }
-        if (op.getOperatorTag() != LogicalOperatorTag.GROUP) {
-            return false;
-        }
-        GroupByOperator gbyOp = (GroupByOperator) op;
-        if (gbyOp.getExecutionMode() != ExecutionMode.PARTITIONED) {
-            return false;
-        }
-
-        BookkeepingInfo bi = new BookkeepingInfo();
-        GroupByOperator newGbyOp = opToPush(gbyOp, bi, context);
-        if (newGbyOp == null) {
-            return false;
-        }
-
-        Set<LogicalVariable> newGbyLiveVars = new ListSet<LogicalVariable>();
-        VariableUtilities.getLiveVariables(newGbyOp, newGbyLiveVars);
-        for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : gbyOp.getDecorList()) {
-            List<LogicalVariable> usedDecorVars = new ArrayList<LogicalVariable>();
-            // p.second.getValue() should always return a VariableReferenceExpression, hence
-            // usedDecorVars should always contain only one variable.
-            p.second.getValue().getUsedVariables(usedDecorVars);
-            if (!newGbyLiveVars.contains(usedDecorVars.get(0))) {
-                // Let the left-hand side of gbyOp's decoration expressions populated through the combiner group-by without
-                // any intermediate assignment.
-                newGbyOp.addDecorExpression(null, p.second.getValue());
-            }
-        }
-        newGbyOp.setExecutionMode(ExecutionMode.LOCAL);
-        Object v = gbyOp.getAnnotations().get(OperatorAnnotations.USE_HASH_GROUP_BY);
-        newGbyOp.getAnnotations().put(OperatorAnnotations.USE_HASH_GROUP_BY, v);
-
-        Object v2 = gbyOp.getAnnotations().get(OperatorAnnotations.USE_EXTERNAL_GROUP_BY);
-        newGbyOp.getAnnotations().put(OperatorAnnotations.USE_EXTERNAL_GROUP_BY, v2);
-
-        List<LogicalVariable> propagatedVars = new LinkedList<LogicalVariable>();
-        VariableUtilities.getProducedVariables(newGbyOp, propagatedVars);
-
-        Set<LogicalVariable> freeVars = new HashSet<LogicalVariable>();
-        OperatorPropertiesUtil.getFreeVariablesInSubplans(gbyOp, freeVars);
-
-        for (LogicalVariable var : freeVars) {
-            if (!propagatedVars.contains(var)) {
-                LogicalVariable newDecorVar = context.newVar();
-                newGbyOp.addDecorExpression(newDecorVar, new VariableReferenceExpression(var));
-                VariableUtilities.substituteVariables(gbyOp.getNestedPlans().get(0).getRoots().get(0).getValue(), var,
-                        newDecorVar, context);
-            }
-        }
-
-        Mutable<ILogicalOperator> opRef3 = gbyOp.getInputs().get(0);
-        opRef3.setValue(newGbyOp);
-        typeGby(newGbyOp, context);
-        typeGby(gbyOp, context);
-        context.addToDontApplySet(this, op);
-        return true;
-    }
-
-    private void typeGby(AbstractOperatorWithNestedPlans op, IOptimizationContext context) throws AlgebricksException {
-        for (ILogicalPlan p : op.getNestedPlans()) {
-            OperatorPropertiesUtil.typePlan(p, context);
-        }
-        context.computeAndSetTypeEnvironmentForOperator(op);
-    }
-
-    private GroupByOperator opToPush(GroupByOperator gbyOp, BookkeepingInfo bi, IOptimizationContext context)
-            throws AlgebricksException {
-        // Hook up input to new group-by.
-        Mutable<ILogicalOperator> opRef3 = gbyOp.getInputs().get(0);
-        ILogicalOperator op3 = opRef3.getValue();
-        GroupByOperator newGbyOp = new GroupByOperator();
-        newGbyOp.getInputs().add(new MutableObject<ILogicalOperator>(op3));
-        // Copy annotations.
-        Map<String, Object> annotations = newGbyOp.getAnnotations();
-        annotations.putAll(gbyOp.getAnnotations());
-
-        List<LogicalVariable> gbyVars = gbyOp.getGbyVarList();
-        for (ILogicalPlan p : gbyOp.getNestedPlans()) {
-            Pair<Boolean, ILogicalPlan> bip = tryToPushSubplan(p, gbyOp, newGbyOp, bi, gbyVars, context);
-            if (!bip.first) {
-                // For now, if we cannot push everything, give up.
-                return null;
-            }
-            ILogicalPlan pushedSubplan = bip.second;
-            if (pushedSubplan != null) {
-                newGbyOp.getNestedPlans().add(pushedSubplan);
-            }
-        }
-
-        ArrayList<LogicalVariable> newOpGbyList = new ArrayList<LogicalVariable>();
-        ArrayList<LogicalVariable> replGbyList = new ArrayList<LogicalVariable>();
-        // Find maximal sequence of variable.
-        for (Map.Entry<GroupByOperator, List<LogicalVariable>> e : bi.modifyGbyMap.entrySet()) {
-            List<LogicalVariable> varList = e.getValue();
-            boolean see1 = true;
-            int sz1 = newOpGbyList.size();
-            int i = 0;
-            for (LogicalVariable v : varList) {
-                if (see1) {
-                    if (i < sz1) {
-                        LogicalVariable v2 = newOpGbyList.get(i);
-                        if (v != v2) {
-                            // cannot linearize
-                            return null;
-                        }
-                    } else {
-                        see1 = false;
-                        newOpGbyList.add(v);
-                        replGbyList.add(context.newVar());
-                    }
-                    i++;
-                } else {
-                    newOpGbyList.add(v);
-                    replGbyList.add(context.newVar());
-                }
-            }
-        }
-        // set the vars in the new op
-        int n = newOpGbyList.size();
-        for (int i = 0; i < n; i++) {
-            newGbyOp.addGbyExpression(replGbyList.get(i), new VariableReferenceExpression(newOpGbyList.get(i)));
-            VariableUtilities.substituteVariables(gbyOp, newOpGbyList.get(i), replGbyList.get(i), false, context);
-        }
-        return newGbyOp;
-    }
-
-    private Pair<Boolean, ILogicalPlan> tryToPushSubplan(ILogicalPlan nestedPlan, GroupByOperator oldGbyOp,
-            GroupByOperator newGbyOp, BookkeepingInfo bi, List<LogicalVariable> gbyVars, IOptimizationContext context)
-            throws AlgebricksException {
-        List<Mutable<ILogicalOperator>> pushedRoots = new ArrayList<Mutable<ILogicalOperator>>();
-        Set<SimilarAggregatesInfo> toReplaceSet = new HashSet<SimilarAggregatesInfo>();
-        for (Mutable<ILogicalOperator> r : nestedPlan.getRoots()) {
-            if (!tryToPushRoot(r, oldGbyOp, newGbyOp, bi, gbyVars, context, pushedRoots, toReplaceSet)) {
-                // For now, if we cannot push everything, give up.
-                return new Pair<Boolean, ILogicalPlan>(false, null);
-            }
-        }
-        if (pushedRoots.isEmpty()) {
-            return new Pair<Boolean, ILogicalPlan>(true, null);
-        } else {
-            // Replaces the aggregation expressions in the original group-by op with new ones.
-            ILogicalPlan newPlan = new ALogicalPlanImpl(pushedRoots);
-            ILogicalPlan plan = fingIdenticalPlan(newGbyOp, newPlan);
-            replaceOriginalAggFuncs(toReplaceSet);
-            if (plan == null) {
-                return new Pair<Boolean, ILogicalPlan>(true, newPlan);
-            } else {
-                // Does not add a nested subplan to newGbyOp if there already exists an isomorphic plan.
-                Set<LogicalVariable> originalVars = new ListSet<LogicalVariable>();
-                Set<LogicalVariable> newVars = new ListSet<LogicalVariable>();
-                for (Mutable<ILogicalOperator> rootRef : pushedRoots) {
-                    VariableUtilities.getProducedVariables(rootRef.getValue(), originalVars);
-                }
-                for (Mutable<ILogicalOperator> rootRef : plan.getRoots()) {
-                    VariableUtilities.getProducedVariables(rootRef.getValue(), newVars);
-                }
-
-                // Replaces variable exprs referring to the variables produced by newPlan by 
-                // those produced by plan.
-                Iterator<LogicalVariable> originalVarIter = originalVars.iterator();
-                Iterator<LogicalVariable> newVarIter = newVars.iterator();
-                while (originalVarIter.hasNext()) {
-                    LogicalVariable originalVar = originalVarIter.next();
-                    LogicalVariable newVar = newVarIter.next();
-                    for (SimilarAggregatesInfo sai : toReplaceSet) {
-                        for (AggregateExprInfo aei : sai.simAggs) {
-                            ILogicalExpression afce = aei.aggExprRef.getValue();
-                            afce.substituteVar(originalVar, newVar);
-                        }
-                    }
-                }
-                return new Pair<Boolean, ILogicalPlan>(true, null);
-            }
-        }
-    }
-
-    private ILogicalPlan fingIdenticalPlan(GroupByOperator newGbyOp, ILogicalPlan plan) throws AlgebricksException {
-        for (ILogicalPlan nestedPlan : newGbyOp.getNestedPlans()) {
-            if (IsomorphismUtilities.isOperatorIsomorphicPlan(plan, nestedPlan)) {
-                return nestedPlan;
-            }
-        }
-        return null;
-    }
-
-    private boolean tryToPushRoot(Mutable<ILogicalOperator> root, GroupByOperator oldGbyOp, GroupByOperator newGbyOp,
-            BookkeepingInfo bi, List<LogicalVariable> gbyVars, IOptimizationContext context,
-            List<Mutable<ILogicalOperator>> toPushAccumulate, Set<SimilarAggregatesInfo> toReplaceSet)
-            throws AlgebricksException {
-        AbstractLogicalOperator op1 = (AbstractLogicalOperator) root.getValue();
-        if (op1.getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
-            return false;
-        }
-        AbstractLogicalOperator op2 = (AbstractLogicalOperator) op1.getInputs().get(0).getValue();
-        // Finds nested group-by if any.
-        AbstractLogicalOperator op3 = op2;
-        while (op3.getOperatorTag() != LogicalOperatorTag.GROUP && op3.getInputs().size() == 1) {
-            op3 = (AbstractLogicalOperator) op3.getInputs().get(0).getValue();
-        }
-
-        if (op3.getOperatorTag() != LogicalOperatorTag.GROUP) {
-            AggregateOperator initAgg = (AggregateOperator) op1;
-            Pair<Boolean, Mutable<ILogicalOperator>> pOpRef = tryToPushAgg(initAgg, newGbyOp, toReplaceSet, context);
-            if (!pOpRef.first) {
-                return false;
-            }
-            Mutable<ILogicalOperator> opRef = pOpRef.second;
-            if (opRef != null) {
-                toPushAccumulate.add(opRef);
-            }
-            bi.modifyGbyMap.put(oldGbyOp, gbyVars);
-            return true;
-        } else {
-            GroupByOperator nestedGby = (GroupByOperator) op3;
-            List<LogicalVariable> gbyVars2 = nestedGby.getGbyVarList();
-            List<LogicalVariable> concatGbyVars = new ArrayList<LogicalVariable>(gbyVars);
-            concatGbyVars.addAll(gbyVars2);
-            for (ILogicalPlan p : nestedGby.getNestedPlans()) {
-                for (Mutable<ILogicalOperator> r2 : p.getRoots()) {
-                    if (!tryToPushRoot(r2, nestedGby, newGbyOp, bi, concatGbyVars, context, toPushAccumulate,
-                            toReplaceSet)) {
-                        return false;
-                    }
-                }
-            }
-
-            /***
-             * Push the nested pipeline which provides the input to the nested group operator into newGbyOp (the combined gby op).
-             * The change is to fix asterixdb issue 782.
-             */
-            Mutable<ILogicalOperator> nestedGbyInputRef = nestedGby.getInputs().get(0);
-            Mutable<ILogicalOperator> startOfPipelineRef = nestedGbyInputRef;
-            if (startOfPipelineRef.getValue().getOperatorTag() == LogicalOperatorTag.NESTEDTUPLESOURCE) {
-                return true;
-            }
-
-            // move down the nested pipeline to find the start of the pipeline right upon the nested-tuple-source
-            boolean hasIsNullFunction = OperatorPropertiesUtil.isNullTest((AbstractLogicalOperator) startOfPipelineRef
-                    .getValue());
-            while (startOfPipelineRef.getValue().getInputs().get(0).getValue().getOperatorTag() != LogicalOperatorTag.NESTEDTUPLESOURCE) {
-                startOfPipelineRef = startOfPipelineRef.getValue().getInputs().get(0);
-                hasIsNullFunction = OperatorPropertiesUtil.isNullTest((AbstractLogicalOperator) startOfPipelineRef
-                        .getValue());
-            }
-            //keep the old nested-tuple-source
-            Mutable<ILogicalOperator> oldNts = startOfPipelineRef.getValue().getInputs().get(0);
-
-            //move down the nested op in the new gby operator
-            Mutable<ILogicalOperator> newGbyNestedOpRef = toPushAccumulate.get(0);
-            while (newGbyNestedOpRef.getValue().getInputs().get(0).getValue().getOperatorTag() != LogicalOperatorTag.NESTEDTUPLESOURCE) {
-                newGbyNestedOpRef = newGbyNestedOpRef.getValue().getInputs().get(0);
-            }
-
-            //insert the pipeline before nested gby into the new (combiner) gby's nested plan on top of the nested-tuple-source
-            startOfPipelineRef.getValue().getInputs().set(0, newGbyNestedOpRef.getValue().getInputs().get(0));
-            newGbyNestedOpRef.getValue().getInputs().set(0, nestedGbyInputRef);
-
-            //in the old gby operator, remove the nested pipeline since it is already pushed to the combiner gby
-            nestedGby.getInputs().set(0, oldNts);
-            List<LogicalVariable> aggProducedVars = new ArrayList<LogicalVariable>();
-            VariableUtilities.getProducedVariables(toPushAccumulate.get(0).getValue(), aggProducedVars);
-
-            if (hasIsNullFunction && aggProducedVars.size() != 0) {
-                // if the old nested pipeline contains a not-null-check, we need to convert it to a not-system-null-check in the non-local gby
-                processNullTest(context, nestedGby, aggProducedVars);
-            }
-
-            return true;
-        }
-    }
-
-    /**
-     * Deal with the case where the nested plan in the combiner gby operator has a null-test before invoking aggregation functions.
-     * 
-     * @param context
-     *            The optimization context.
-     * @param nestedGby
-     *            The nested gby operator in the global gby operator's subplan.
-     * @param firstAggVar
-     *            The first aggregation variable produced by the combiner gby.
-     */
-    protected abstract void processNullTest(IOptimizationContext context, GroupByOperator nestedGby,
-            List<LogicalVariable> aggregateVarsProducedByCombiner);
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/BreakSelectIntoConjunctsRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/BreakSelectIntoConjunctsRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/BreakSelectIntoConjunctsRule.java
deleted file mode 100644
index 53ca903..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/BreakSelectIntoConjunctsRule.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright 2009-2013 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.hyracks.algebricks.rewriter.rules;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.commons.lang3.mutable.Mutable;
-import org.apache.commons.lang3.mutable.MutableObject;
-
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.IOptimizationContext;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.SelectOperator;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-public class BreakSelectIntoConjunctsRule implements IAlgebraicRewriteRule {
-
-    private List<Mutable<ILogicalExpression>> conjs = new ArrayList<Mutable<ILogicalExpression>>();
-
-    @Override
-    public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) {
-        return false;
-    }
-
-    @Override
-    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
-        AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
-        if (op.getOperatorTag() != LogicalOperatorTag.SELECT) {
-            return false;
-        }
-        SelectOperator select = (SelectOperator) op;
-
-        ILogicalExpression cond = select.getCondition().getValue();
-
-        conjs.clear();
-        if (!cond.splitIntoConjuncts(conjs)) {
-            return false;
-        }
-
-        Mutable<ILogicalOperator> childOfSelect = select.getInputs().get(0);
-        boolean fst = true;
-        ILogicalOperator botOp = select;
-        ILogicalExpression firstExpr = null;
-        for (Mutable<ILogicalExpression> eRef : conjs) {
-            ILogicalExpression e = eRef.getValue();
-            if (fst) {
-                fst = false;
-                firstExpr = e;
-            } else {
-                SelectOperator newSelect = new SelectOperator(new MutableObject<ILogicalExpression>(e),
-                        select.getRetainNull(), select.getNullPlaceholderVariable());
-                List<Mutable<ILogicalOperator>> botInpList = botOp.getInputs();
-                botInpList.clear();
-                botInpList.add(new MutableObject<ILogicalOperator>(newSelect));
-                context.computeAndSetTypeEnvironmentForOperator(botOp);
-                botOp = newSelect;
-            }
-        }
-        botOp.getInputs().add(childOfSelect);
-        select.getCondition().setValue(firstExpr);
-        context.computeAndSetTypeEnvironmentForOperator(botOp);
-        context.computeAndSetTypeEnvironmentForOperator(select);
-
-        return true;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/ComplexJoinInferenceRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/ComplexJoinInferenceRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/ComplexJoinInferenceRule.java
deleted file mode 100644
index 73fd966..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/ComplexJoinInferenceRule.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright 2009-2013 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.hyracks.algebricks.rewriter.rules;
-
-import java.util.HashSet;
-
-import org.apache.commons.lang3.mutable.Mutable;
-import org.apache.commons.lang3.mutable.MutableObject;
-
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalPlan;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.IOptimizationContext;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalVariable;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.ConstantExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractBinaryJoinOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractScanOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.SubplanOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.visitors.VariableUtilities;
-import edu.uci.ics.hyracks.algebricks.core.algebra.util.OperatorManipulationUtil;
-import edu.uci.ics.hyracks.algebricks.core.algebra.util.OperatorPropertiesUtil;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-public class ComplexJoinInferenceRule implements IAlgebraicRewriteRule {
-
-    @Override
-    public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
-            throws AlgebricksException {
-        ILogicalOperator op = opRef.getValue();
-        if (!(op instanceof AbstractScanOperator)) {
-            return false;
-        }
-
-        Mutable<ILogicalOperator> opRef2 = op.getInputs().get(0);
-        AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue();
-        if (op2.getOperatorTag() != LogicalOperatorTag.SUBPLAN) {
-            return false;
-        }
-        SubplanOperator subplan = (SubplanOperator) op2;
-
-        Mutable<ILogicalOperator> opRef3 = subplan.getInputs().get(0);
-        AbstractLogicalOperator op3 = (AbstractLogicalOperator) opRef3.getValue();
-
-        if (op3.getOperatorTag() == LogicalOperatorTag.EMPTYTUPLESOURCE
-                || op3.getOperatorTag() == LogicalOperatorTag.NESTEDTUPLESOURCE) {
-            return false;
-        }
-
-        if (subplanHasFreeVariables(subplan)) {
-            return false;
-        }
-
-        HashSet<LogicalVariable> varsUsedInUnnest = new HashSet<LogicalVariable>();
-        VariableUtilities.getUsedVariables(op, varsUsedInUnnest);
-
-        HashSet<LogicalVariable> producedInSubplan = new HashSet<LogicalVariable>();
-        VariableUtilities.getProducedVariables(subplan, producedInSubplan);
-
-        if (!producedInSubplan.containsAll(varsUsedInUnnest)) {
-            return false;
-        }
-
-        ntsToEtsInSubplan(subplan, context);
-        cleanupJoins(subplan);
-        InnerJoinOperator join = new InnerJoinOperator(new MutableObject<ILogicalExpression>(ConstantExpression.TRUE));
-        join.getInputs().add(opRef3);
-        opRef2.setValue(OperatorManipulationUtil.eliminateSingleSubplanOverEts(subplan));
-        join.getInputs().add(new MutableObject<ILogicalOperator>(op));
-        opRef.setValue(join);
-        context.computeAndSetTypeEnvironmentForOperator(join);
-        return true;
-    }
-
-    @Override
-    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) {
-        return false;
-    }
-
-    private static void cleanupJoins(SubplanOperator s) {
-        for (ILogicalPlan p : s.getNestedPlans()) {
-            for (Mutable<ILogicalOperator> r : p.getRoots()) {
-                cleanupJoins(r);
-            }
-        }
-    }
-
-    /** clean up joins that have one input branch that is empty tuple source */
-    private static void cleanupJoins(Mutable<ILogicalOperator> opRef) {
-        if (opRef.getValue() instanceof AbstractBinaryJoinOperator) {
-            for (Mutable<ILogicalOperator> inputRef : opRef.getValue().getInputs()) {
-                if (inputRef.getValue().getOperatorTag() == LogicalOperatorTag.EMPTYTUPLESOURCE) {
-                    opRef.getValue().getInputs().remove(inputRef);
-                    opRef.setValue(opRef.getValue().getInputs().get(0).getValue());
-                    break;
-                }
-            }
-        }
-        for (Mutable<ILogicalOperator> inputRef : opRef.getValue().getInputs()) {
-            cleanupJoins(inputRef);
-        }
-    }
-
-    private static void ntsToEtsInSubplan(SubplanOperator s, IOptimizationContext context) throws AlgebricksException {
-        for (ILogicalPlan p : s.getNestedPlans()) {
-            for (Mutable<ILogicalOperator> r : p.getRoots()) {
-                OperatorManipulationUtil.ntsToEts(r, context);
-            }
-        }
-    }
-
-    private static boolean subplanHasFreeVariables(SubplanOperator s) throws AlgebricksException {
-        for (ILogicalPlan p : s.getNestedPlans()) {
-            for (Mutable<ILogicalOperator> r : p.getRoots()) {
-                if (OperatorPropertiesUtil.hasFreeVariablesInSelfOrDesc((AbstractLogicalOperator) r.getValue())) {
-                    return true;
-                }
-            }
-        }
-        return false;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/ComplexUnnestToProductRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/ComplexUnnestToProductRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/ComplexUnnestToProductRule.java
deleted file mode 100644
index 910a8f9..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/ComplexUnnestToProductRule.java
+++ /dev/null
@@ -1,314 +0,0 @@
-/*
- * Copyright 2009-2013 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.hyracks.algebricks.rewriter.rules;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-
-import org.apache.commons.lang3.mutable.Mutable;
-import org.apache.commons.lang3.mutable.MutableObject;
-
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.IOptimizationContext;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalVariable;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.ConstantExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractOperatorWithNestedPlans;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.EmptyTupleSourceOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.visitors.VariableUtilities;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-/**
- * Complex rewrite rule for producing joins from unnests.
- * This rule is limited to creating left-deep trees.
- */
-public class ComplexUnnestToProductRule implements IAlgebraicRewriteRule {
-
-    @Override
-    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) {
-        return false;
-    }
-
-    @Override
-    public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
-            throws AlgebricksException {
-        AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
-        if (op.getOperatorTag() != LogicalOperatorTag.DATASOURCESCAN
-                && op.getOperatorTag() != LogicalOperatorTag.UNNEST) {
-            return false;
-        }
-
-        //stop rewriting if the operators originates from a nested tuple source
-        if (insideSubplan(opRef)) {
-            return false;
-        }
-
-        // We may pull selects above the join we create in order to eliminate possible dependencies between
-        // the outer and inner input plans of the join.
-        List<ILogicalOperator> topSelects = new ArrayList<ILogicalOperator>();
-
-        // Keep track of the operators and used variables participating in the inner input plan.
-        HashSet<LogicalVariable> innerUsedVars = new HashSet<LogicalVariable>();
-        List<ILogicalOperator> innerOps = new ArrayList<ILogicalOperator>();
-        HashSet<LogicalVariable> outerUsedVars = new HashSet<LogicalVariable>();
-        List<ILogicalOperator> outerOps = new ArrayList<ILogicalOperator>();
-        innerOps.add(op);
-        VariableUtilities.getUsedVariables(op, innerUsedVars);
-
-        Mutable<ILogicalOperator> opRef2 = op.getInputs().get(0);
-        AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue();
-
-        // Find an unnest or join and partition the plan between the first unnest and that operator into independent parts.
-        if (!findPlanPartition(op2, innerUsedVars, outerUsedVars, innerOps, outerOps, topSelects, false)) {
-            // We could not find an unnest or join.
-            return false;
-        }
-        // The last operator must be an unnest or join.
-        AbstractLogicalOperator unnestOrJoin = (AbstractLogicalOperator) outerOps.get(outerOps.size() - 1);
-
-        ILogicalOperator outerRoot = null;
-        ILogicalOperator innerRoot = null;
-        EmptyTupleSourceOperator ets = new EmptyTupleSourceOperator();
-        // If we found a join, simply use it as the outer root.
-        if (unnestOrJoin.getOperatorTag() != LogicalOperatorTag.INNERJOIN
-                && unnestOrJoin.getOperatorTag() != LogicalOperatorTag.LEFTOUTERJOIN) {
-            // We've found a second unnest. First, sanity check that the unnest does not produce any vars that are used by the plan above (until the first unnest).
-            List<LogicalVariable> producedVars = new ArrayList<LogicalVariable>();
-            VariableUtilities.getProducedVariables(unnestOrJoin, producedVars);
-            for (LogicalVariable producedVar : producedVars) {
-                if (innerUsedVars.contains(producedVar)) {
-                    return false;
-                }
-            }
-            // Continue finding a partitioning of the plan such that the inner and outer partitions are independent, in order to feed a join.
-            // Now, we look below the second unnest or join.
-            VariableUtilities.getUsedVariables(unnestOrJoin, outerUsedVars);
-            AbstractLogicalOperator unnestChild = (AbstractLogicalOperator) unnestOrJoin.getInputs().get(0).getValue();
-            if (!findPlanPartition(unnestChild, innerUsedVars, outerUsedVars, innerOps, outerOps, topSelects, true)) {
-                // We could not find a suitable partitioning.
-                return false;
-            }
-        }
-        innerRoot = buildOperatorChain(innerOps, ets, context);
-        context.computeAndSetTypeEnvironmentForOperator(innerRoot);
-        outerRoot = buildOperatorChain(outerOps, null, context);
-        context.computeAndSetTypeEnvironmentForOperator(outerRoot);
-
-        InnerJoinOperator product = new InnerJoinOperator(
-                new MutableObject<ILogicalExpression>(ConstantExpression.TRUE));
-        // Outer branch.
-        product.getInputs().add(new MutableObject<ILogicalOperator>(outerRoot));
-        // Inner branch.
-        product.getInputs().add(new MutableObject<ILogicalOperator>(innerRoot));
-        context.computeAndSetTypeEnvironmentForOperator(product);
-        // Put the selects on top of the join.
-        ILogicalOperator topOp = product;
-        if (!topSelects.isEmpty()) {
-            topOp = buildOperatorChain(topSelects, product, context);
-        }
-        // Plug the selects + product in the plan.
-        opRef.setValue(topOp);
-        context.computeAndSetTypeEnvironmentForOperator(topOp);
-        return true;
-    }
-
-    private ILogicalOperator buildOperatorChain(List<ILogicalOperator> ops, ILogicalOperator bottomOp,
-            IOptimizationContext context) throws AlgebricksException {
-        ILogicalOperator root = ops.get(0);
-        ILogicalOperator prevOp = root;
-        for (int i = 1; i < ops.size(); i++) {
-            ILogicalOperator inputOp = ops.get(i);
-            prevOp.getInputs().clear();
-            prevOp.getInputs().add(new MutableObject<ILogicalOperator>(inputOp));
-            prevOp = inputOp;
-        }
-        if (bottomOp != null) {
-            context.computeAndSetTypeEnvironmentForOperator(bottomOp);
-            prevOp.getInputs().clear();
-            prevOp.getInputs().add(new MutableObject<ILogicalOperator>(bottomOp));
-        }
-        return root;
-    }
-
-    private boolean findPlanPartition(AbstractLogicalOperator op, HashSet<LogicalVariable> innerUsedVars,
-            HashSet<LogicalVariable> outerUsedVars, List<ILogicalOperator> innerOps, List<ILogicalOperator> outerOps,
-            List<ILogicalOperator> topSelects, boolean belowSecondUnnest) throws AlgebricksException {
-        if (belowSecondUnnest && innerUsedVars.isEmpty()) {
-            // Trivially joinable.
-            return true;
-        }
-        if (!belowSecondUnnest) {
-            // Bail on the following operators.
-            switch (op.getOperatorTag()) {
-                case AGGREGATE:
-                case SUBPLAN:
-                case GROUP:
-                case UNNEST_MAP:
-                    return false;
-            }
-        }
-        switch (op.getOperatorTag()) {
-            case UNNEST:
-            case DATASOURCESCAN: {
-                // We may have reached this state by descending through a subplan.
-                outerOps.add(op);
-                return true;
-            }
-            case INNERJOIN:
-            case LEFTOUTERJOIN: {
-                // Make sure that no variables that are live under this join are needed by the inner.
-                List<LogicalVariable> liveVars = new ArrayList<LogicalVariable>();
-                VariableUtilities.getLiveVariables(op, liveVars);
-                for (LogicalVariable liveVar : liveVars) {
-                    if (innerUsedVars.contains(liveVar)) {
-                        return false;
-                    }
-                }
-                outerOps.add(op);
-                return true;
-            }
-            case SELECT: {
-                // Remember this select to pulling it above the join.
-                if (innerUsedVars.isEmpty()) {
-                    outerOps.add(op);
-                } else {
-                    topSelects.add(op);
-                }
-                break;
-            }
-            case PROJECT: {
-                // Throw away projects from the plan since we are pulling selects up.
-                break;
-            }
-            case EMPTYTUPLESOURCE:
-            case NESTEDTUPLESOURCE: {
-                if (belowSecondUnnest) {
-                    // We have successfully partitioned the plan into independent parts to be plugged into the join.
-                    return true;
-                } else {
-                    // We could not find a second unnest or a join.
-                    return false;
-                }
-            }
-            default: {
-                // The inner is trivially independent.
-                if (!belowSecondUnnest && innerUsedVars.isEmpty()) {
-                    outerOps.add(op);
-                    break;
-                }
-
-                // Examine produced vars to determine which partition uses them.
-                List<LogicalVariable> producedVars = new ArrayList<LogicalVariable>();
-                VariableUtilities.getProducedVariables(op, producedVars);
-                int outerMatches = 0;
-                int innerMatches = 0;
-                for (LogicalVariable producedVar : producedVars) {
-                    if (outerUsedVars.contains(producedVar)) {
-                        outerMatches++;
-                    }
-                    if (innerUsedVars.contains(producedVar)) {
-                        innerMatches++;
-                    }
-                }
-
-                HashSet<LogicalVariable> targetUsedVars = null;
-                if (outerMatches == producedVars.size() && !producedVars.isEmpty()) {
-                    // All produced vars used by outer partition.
-                    outerOps.add(op);
-                    targetUsedVars = outerUsedVars;
-                }
-                if (innerMatches == producedVars.size() && !producedVars.isEmpty()) {
-                    // All produced vars used by inner partition.
-                    innerOps.add(op);
-                    targetUsedVars = innerUsedVars;
-                }
-                if (innerMatches == 0 && outerMatches == 0) {
-                    // Op produces variables that are not used in the part of the plan we've seen (or it doesn't produce any vars).
-                    // Try to figure out where it belongs by analyzing the used variables.
-                    List<LogicalVariable> usedVars = new ArrayList<LogicalVariable>();
-                    VariableUtilities.getUsedVariables(op, usedVars);
-                    for (LogicalVariable usedVar : usedVars) {
-                        boolean canBreak = false;
-                        if (outerUsedVars.contains(usedVar)) {
-                            outerOps.add(op);
-                            targetUsedVars = outerUsedVars;
-                            canBreak = true;
-                        }
-                        if (innerUsedVars.contains(usedVar)) {
-                            innerOps.add(op);
-                            targetUsedVars = innerUsedVars;
-                            canBreak = true;
-                        }
-                        if (canBreak) {
-                            break;
-                        }
-                    }
-                    // TODO: For now we bail here, but we could remember such ops and determine their target partition at a later point.
-                    if (targetUsedVars == null) {
-                        return false;
-                    }
-                } else if (innerMatches != 0 && outerMatches != 0) {
-                    // The current operator produces variables that are used by both partitions, so the inner and outer are not independent and, therefore, we cannot create a join.
-                    // TODO: We may still be able to split the operator to create a viable partitioning.
-                    return false;
-                }
-                // Update used variables of partition that op belongs to.
-                if (op.hasNestedPlans() && op.getOperatorTag() != LogicalOperatorTag.SUBPLAN) {
-                    AbstractOperatorWithNestedPlans opWithNestedPlans = (AbstractOperatorWithNestedPlans) op;
-                    opWithNestedPlans.getUsedVariablesExceptNestedPlans(targetUsedVars);
-                } else {
-                    VariableUtilities.getUsedVariables(op, targetUsedVars);
-                }
-                break;
-            }
-        }
-        if (!op.hasInputs()) {
-            if (!belowSecondUnnest) {
-                // We could not find a second unnest or a join.
-                return false;
-            } else {
-                // We have successfully partitioned the plan into independent parts to be plugged into the join.
-                return true;
-            }
-        }
-        return findPlanPartition((AbstractLogicalOperator) op.getInputs().get(0).getValue(), innerUsedVars,
-                outerUsedVars, innerOps, outerOps, topSelects, belowSecondUnnest);
-    }
-
-    /**
-     * check whether the operator is inside a sub-plan
-     * 
-     * @param nestedRootRef
-     * @return true-if it is; false otherwise.
-     */
-    private boolean insideSubplan(Mutable<ILogicalOperator> nestedRootRef) {
-        AbstractLogicalOperator nestedRoot = (AbstractLogicalOperator) nestedRootRef.getValue();
-        if (nestedRoot.getOperatorTag() == LogicalOperatorTag.NESTEDTUPLESOURCE) {
-            return true;
-        }
-        List<Mutable<ILogicalOperator>> inputs = nestedRoot.getInputs();
-        for (Mutable<ILogicalOperator> input : inputs) {
-            if (insideSubplan(input)) {
-                return true;
-            }
-        }
-        return false;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/ConsolidateAssignsRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/ConsolidateAssignsRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/ConsolidateAssignsRule.java
deleted file mode 100644
index 4da332c..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/ConsolidateAssignsRule.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright 2009-2013 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.hyracks.algebricks.rewriter.rules;
-
-import java.util.HashSet;
-import java.util.List;
-
-import org.apache.commons.lang3.mutable.Mutable;
-
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.IOptimizationContext;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalVariable;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AssignOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.visitors.VariableUtilities;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-public class ConsolidateAssignsRule implements IAlgebraicRewriteRule {
-
-    @Override
-    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) {
-        return false;
-    }
-
-    @Override
-    public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
-            throws AlgebricksException {
-        AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
-        if (op.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
-            return false;
-        }
-        AssignOperator assign1 = (AssignOperator) op;
-
-        AbstractLogicalOperator op2 = (AbstractLogicalOperator) assign1.getInputs().get(0).getValue();
-        if (op2.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
-            return false;
-        }
-        AssignOperator assign2 = (AssignOperator) op2;
-
-        HashSet<LogicalVariable> used1 = new HashSet<LogicalVariable>();
-        VariableUtilities.getUsedVariables(assign1, used1);
-        for (LogicalVariable v2 : assign2.getVariables()) {
-            if (used1.contains(v2)) {
-                return false;
-            }
-        }
-
-        assign1.getVariables().addAll(assign2.getVariables());
-        assign1.getExpressions().addAll(assign2.getExpressions());
-
-        Mutable<ILogicalOperator> botOpRef = assign2.getInputs().get(0);
-        List<Mutable<ILogicalOperator>> asgnInpList = assign1.getInputs();
-        asgnInpList.clear();
-        asgnInpList.add(botOpRef);
-        context.computeAndSetTypeEnvironmentForOperator(assign1);
-        return true;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/ConsolidateSelectsRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/ConsolidateSelectsRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/ConsolidateSelectsRule.java
deleted file mode 100644
index e57bd3c..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/ConsolidateSelectsRule.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright 2009-2013 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.hyracks.algebricks.rewriter.rules;
-
-import org.apache.commons.lang3.mutable.Mutable;
-import org.apache.commons.lang3.mutable.MutableObject;
-
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.IOptimizationContext;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.functions.AlgebricksBuiltinFunctions;
-import edu.uci.ics.hyracks.algebricks.core.algebra.functions.IFunctionInfo;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.SelectOperator;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-/**
- * Matches the following operator pattern:
- * (select) <-- ((assign)* <-- (select)*)+
- * 
- * Consolidates the selects to:
- * (select) <-- (assign)*
- *
- */
-public class ConsolidateSelectsRule implements IAlgebraicRewriteRule {
-
-    @Override
-    public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) {
-        return false;
-    }
-
-    @Override
-    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
-    	AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
-        if (op.getOperatorTag() != LogicalOperatorTag.SELECT) {
-            return false;
-        }
-        SelectOperator firstSelect = (SelectOperator) op;
-
-        IFunctionInfo andFn = context.getMetadataProvider().lookupFunction(AlgebricksBuiltinFunctions.AND);
-        // New conjuncts for consolidated select.
-        AbstractFunctionCallExpression conj = null;        
-        AbstractLogicalOperator topMostOp = null;
-        AbstractLogicalOperator selectParent = null;
-        AbstractLogicalOperator nextSelect = firstSelect;
-		do {
-        	// Skip through assigns.
-            do {
-            	selectParent = nextSelect;
-            	nextSelect = (AbstractLogicalOperator) selectParent.getInputs().get(0).getValue();
-            } while (nextSelect.getOperatorTag() == LogicalOperatorTag.ASSIGN);
-            // Stop if the child op is not a select.
-            if (nextSelect.getOperatorTag() != LogicalOperatorTag.SELECT) {
-        		break;
-        	}
-            // Remember the top-most op that we are not removing.
-            topMostOp = selectParent;
-            
-            // Initialize the new conjuncts, if necessary.
-            if (conj == null) {
-            	conj = new ScalarFunctionCallExpression(andFn);
-            	// Add the first select's condition.
-            	conj.getArguments().add(new MutableObject<ILogicalExpression>(firstSelect.getCondition().getValue()));
-            }
-            
-            // Consolidate all following selects.
-            do {
-                // Add the condition nextSelect to the new list of conjuncts.
-                conj.getArguments().add(((SelectOperator) nextSelect).getCondition());
-                selectParent = nextSelect;
-                nextSelect = (AbstractLogicalOperator) nextSelect.getInputs().get(0).getValue();
-            } while (nextSelect.getOperatorTag() == LogicalOperatorTag.SELECT);
-            
-            // Hook up the input of the top-most remaining op if necessary.
-            if (topMostOp.getOperatorTag() == LogicalOperatorTag.ASSIGN || topMostOp == firstSelect) {
-            	topMostOp.getInputs().set(0, selectParent.getInputs().get(0));
-            }
-            
-            // Prepare for next iteration.
-            nextSelect = selectParent;
-        } while (true);
-		
-		// Did we consolidate any selects?
-        if (conj == null) {
-        	return false;
-        }
-        
-        // Set the new conjuncts.
-        firstSelect.getCondition().setValue(conj);
-        context.computeAndSetTypeEnvironmentForOperator(firstSelect);
-        return true;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/CopyLimitDownRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/CopyLimitDownRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/CopyLimitDownRule.java
deleted file mode 100644
index 2f080fb..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/CopyLimitDownRule.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright 2009-2013 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.hyracks.algebricks.rewriter.rules;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.commons.lang3.mutable.Mutable;
-import org.apache.commons.lang3.mutable.MutableObject;
-
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.IOptimizationContext;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalVariable;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.functions.AlgebricksBuiltinFunctions;
-import edu.uci.ics.hyracks.algebricks.core.algebra.functions.IFunctionInfo;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.LimitOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.visitors.VariableUtilities;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.physical.StreamLimitPOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.util.OperatorPropertiesUtil;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-public class CopyLimitDownRule implements IAlgebraicRewriteRule {
-
-    @Override
-    public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) {
-        return false;
-    }
-
-    @Override
-    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
-        AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
-        if (op.getOperatorTag() != LogicalOperatorTag.LIMIT) {
-            return false;
-        }
-        LimitOperator limitOp = (LimitOperator) op;
-        if (!limitOp.isTopmostLimitOp()) {
-            return false;
-        }
-
-        List<LogicalVariable> limitUsedVars = new ArrayList<>();
-        VariableUtilities.getUsedVariables(limitOp, limitUsedVars);
-
-        Mutable<ILogicalOperator> safeOpRef = null;
-        Mutable<ILogicalOperator> candidateOpRef = limitOp.getInputs().get(0);
-
-        List<LogicalVariable> candidateProducedVars = new ArrayList<>();
-        while (true) {
-            candidateProducedVars.clear();
-            ILogicalOperator candidateOp = candidateOpRef.getValue();
-            LogicalOperatorTag candidateOpTag = candidateOp.getOperatorTag();
-            if (candidateOp.getInputs().size() > 1 || !candidateOp.isMap()
-                    || candidateOpTag == LogicalOperatorTag.SELECT || candidateOpTag == LogicalOperatorTag.LIMIT
-                    || !OperatorPropertiesUtil.disjoint(limitUsedVars, candidateProducedVars)) {
-                break;
-            }
-
-            safeOpRef = candidateOpRef;
-            candidateOpRef = safeOpRef.getValue().getInputs().get(0);
-        }
-
-        if (safeOpRef != null) {
-            ILogicalOperator safeOp = safeOpRef.getValue();
-            Mutable<ILogicalOperator> unsafeOpRef = safeOp.getInputs().get(0);
-            ILogicalOperator unsafeOp = unsafeOpRef.getValue();
-            LimitOperator limitCloneOp = null;
-            if (limitOp.getOffset().getValue() == null) {
-                limitCloneOp = new LimitOperator(limitOp.getMaxObjects().getValue(), false);
-            } else {
-                IFunctionInfo finfoAdd = context.getMetadataProvider().lookupFunction(
-                        AlgebricksBuiltinFunctions.NUMERIC_ADD);
-                List<Mutable<ILogicalExpression>> addArgs = new ArrayList<>();
-                addArgs.add(new MutableObject<ILogicalExpression>(limitOp.getMaxObjects().getValue().cloneExpression()));
-                addArgs.add(new MutableObject<ILogicalExpression>(limitOp.getOffset().getValue().cloneExpression()));
-                ScalarFunctionCallExpression maxPlusOffset = new ScalarFunctionCallExpression(finfoAdd, addArgs);
-                limitCloneOp = new LimitOperator(maxPlusOffset, false);
-            }
-            limitCloneOp.setPhysicalOperator(new StreamLimitPOperator());
-            limitCloneOp.getInputs().add(new MutableObject<ILogicalOperator>(unsafeOp));
-            limitCloneOp.setExecutionMode(unsafeOp.getExecutionMode());
-            limitCloneOp.recomputeSchema();
-            unsafeOpRef.setValue(limitCloneOp);
-            context.computeAndSetTypeEnvironmentForOperator(limitCloneOp);
-            context.addToDontApplySet(this, limitOp);
-        }
-
-        return safeOpRef != null;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/EliminateGroupByEmptyKeyRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/EliminateGroupByEmptyKeyRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/EliminateGroupByEmptyKeyRule.java
deleted file mode 100644
index e93fdd1..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/EliminateGroupByEmptyKeyRule.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright 2009-2013 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.hyracks.algebricks.rewriter.rules;
-
-import java.util.List;
-
-import org.apache.commons.lang3.mutable.Mutable;
-
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalPlan;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.IOptimizationContext;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalVariable;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-/**
- * This rule lift out the aggregate operator out from a group-by operator
- * if the gby operator groups-by on empty key, e.g., the group-by variables are empty.
- * 
- * @author yingyib
- */
-public class EliminateGroupByEmptyKeyRule implements IAlgebraicRewriteRule {
-
-    @Override
-    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
-        return false;
-    }
-
-    @Override
-    public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
-            throws AlgebricksException {
-        AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
-        if (op.getOperatorTag() != LogicalOperatorTag.GROUP) {
-            return false;
-        }
-        GroupByOperator groupOp = (GroupByOperator) op;
-        List<LogicalVariable> groupVars = groupOp.getGbyVarList();
-        if (groupVars.size() > 0) {
-            return false;
-        }
-        List<ILogicalPlan> nestedPlans = groupOp.getNestedPlans();
-        if (nestedPlans.size() > 1) {
-            return false;
-        }
-        ILogicalPlan nestedPlan = nestedPlans.get(0);
-        if (nestedPlan.getRoots().size() > 1) {
-            return false;
-        }
-        Mutable<ILogicalOperator> topOpRef = nestedPlan.getRoots().get(0);
-        ILogicalOperator topOp = nestedPlan.getRoots().get(0).getValue();
-        Mutable<ILogicalOperator> nestedTupleSourceRef = getNestedTupleSourceReference(topOpRef);
-        /**
-         * connect nested top op into the plan
-         */
-        opRef.setValue(topOp);
-        /**
-         * connect child op into the plan
-         */
-        nestedTupleSourceRef.setValue(groupOp.getInputs().get(0).getValue());
-        return true;
-    }
-
-    private Mutable<ILogicalOperator> getNestedTupleSourceReference(Mutable<ILogicalOperator> nestedTopOperatorRef) {
-        Mutable<ILogicalOperator> currentOpRef = nestedTopOperatorRef;
-        while (currentOpRef.getValue().getInputs() != null && currentOpRef.getValue().getInputs().size() > 0) {
-            currentOpRef = currentOpRef.getValue().getInputs().get(0);
-        }
-        return currentOpRef;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/EliminateSubplanRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/EliminateSubplanRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/EliminateSubplanRule.java
deleted file mode 100644
index 8a381f7..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/EliminateSubplanRule.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright 2009-2013 by The Regents of the University of California
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * you may obtain a copy of the License from
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.hyracks.algebricks.rewriter.rules;
-
-import java.util.LinkedList;
-
-import org.apache.commons.lang3.mutable.Mutable;
-import org.apache.commons.lang3.mutable.MutableObject;
-
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalPlan;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.IOptimizationContext;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.ConstantExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.LeftOuterJoinOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.SubplanOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.util.OperatorManipulationUtil;
-import edu.uci.ics.hyracks.algebricks.core.algebra.util.OperatorPropertiesUtil;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-public class EliminateSubplanRule implements IAlgebraicRewriteRule {
-
-    @Override
-    public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) {
-        return false;
-    }
-
-    /**
-     * Eliminate Subplan above ETS
-     * and Subplan that has only ops. with one input and no free vars. (could we
-     * modify it to consider free vars which are sources of Unnest or Assign, if
-     * there are no aggregates?)
-     */
-    @Override
-    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
-        AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
-        if (op.getOperatorTag() != LogicalOperatorTag.SUBPLAN) {
-            return false;
-        }
-        SubplanOperator subplan = (SubplanOperator) op;
-
-        Mutable<ILogicalOperator> outerRef = subplan.getInputs().get(0);
-        AbstractLogicalOperator outerRefOp = (AbstractLogicalOperator) outerRef.getValue();
-        if (outerRefOp.getOperatorTag() == LogicalOperatorTag.EMPTYTUPLESOURCE) {
-            elimSubplanOverEts(opRef, context);
-            return true;
-        }
-        if (subplan.getNestedPlans().size() == 1 && subplan.getNestedPlans().get(0).getRoots().size() == 1
-                && !OperatorPropertiesUtil.hasFreeVariables(subplan)) {
-            if (elimOneSubplanWithNoFreeVars(opRef)) {
-                return true;
-            }
-        }
-
-        return false;
-    }
-
-    private boolean elimOneSubplanWithNoFreeVars(Mutable<ILogicalOperator> opRef) {
-        SubplanOperator subplan = (SubplanOperator) opRef.getValue();
-        AbstractLogicalOperator rootOp = (AbstractLogicalOperator) subplan.getNestedPlans().get(0).getRoots().get(0)
-                .getValue();
-        if (rootOp.getOperatorTag() == LogicalOperatorTag.EMPTYTUPLESOURCE
-                || rootOp.getOperatorTag() == LogicalOperatorTag.NESTEDTUPLESOURCE) {
-            opRef.setValue(subplan.getInputs().get(0).getValue());
-            return true;
-        } else {
-            AbstractLogicalOperator botOp = rootOp;
-            if (botOp.getInputs().size() != 1) {
-                return false;
-            }
-            do {
-                Mutable<ILogicalOperator> botRef = botOp.getInputs().get(0);
-                botOp = (AbstractLogicalOperator) botRef.getValue();
-                if (botOp.getOperatorTag() == LogicalOperatorTag.EMPTYTUPLESOURCE) {
-                    botRef.setValue(subplan.getInputs().get(0).getValue());
-                    opRef.setValue(rootOp);
-                    return true;
-                }
-            } while (botOp.getInputs().size() == 1);
-            return false;
-        }
-    }
-
-    private void elimSubplanOverEts(Mutable<ILogicalOperator> opRef, IOptimizationContext ctx)
-            throws AlgebricksException {
-        SubplanOperator subplan = (SubplanOperator) opRef.getValue();
-        for (ILogicalPlan p : subplan.getNestedPlans()) {
-            for (Mutable<ILogicalOperator> r : p.getRoots()) {
-                OperatorManipulationUtil.ntsToEts(r, ctx);
-            }
-        }
-        LinkedList<Mutable<ILogicalOperator>> allRoots = subplan.allRootsInReverseOrder();
-        if (allRoots.size() == 1) {
-            opRef.setValue(allRoots.get(0).getValue());
-        } else {
-            ILogicalOperator topOp = null;
-            for (Mutable<ILogicalOperator> r : allRoots) {
-                if (topOp == null) {
-                    topOp = r.getValue();
-                } else {
-                    LeftOuterJoinOperator j = new LeftOuterJoinOperator(new MutableObject<ILogicalExpression>(
-                            ConstantExpression.TRUE));
-                    j.getInputs().add(new MutableObject<ILogicalOperator>(topOp));
-                    j.getInputs().add(r);
-                    ctx.setOutputTypeEnvironment(j, j.computeOutputTypeEnvironment(ctx));
-                    topOp = j;
-                }
-            }
-            opRef.setValue(topOp);
-        }
-    }
-}


Mime
View raw message