You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by im...@apache.org on 2015/08/25 18:41:27 UTC

[14/51] [partial] incubator-asterixdb-hyracks git commit: Change folder structure for Java repackage

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/ExtractCommonOperatorsRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/ExtractCommonOperatorsRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/ExtractCommonOperatorsRule.java
deleted file mode 100644
index 07621ce..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/ExtractCommonOperatorsRule.java
+++ /dev/null
@@ -1,502 +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.BitSet;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.lang3.mutable.Mutable;
-import org.apache.commons.lang3.mutable.MutableInt;
-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.LogicalOperatorTag;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalVariable;
-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.AssignOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ExchangeOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ProjectOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ReplicateOperator;
-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.operators.physical.AssignPOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.physical.OneToOneExchangePOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.physical.ReplicatePOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.physical.StreamProjectPOperator;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-public class ExtractCommonOperatorsRule implements IAlgebraicRewriteRule {
-
-    private final HashMap<Mutable<ILogicalOperator>, List<Mutable<ILogicalOperator>>> childrenToParents = new HashMap<Mutable<ILogicalOperator>, List<Mutable<ILogicalOperator>>>();
-    private final List<Mutable<ILogicalOperator>> roots = new ArrayList<Mutable<ILogicalOperator>>();
-    private final List<List<Mutable<ILogicalOperator>>> equivalenceClasses = new ArrayList<List<Mutable<ILogicalOperator>>>();
-    private final HashMap<Mutable<ILogicalOperator>, BitSet> opToCandidateInputs = new HashMap<Mutable<ILogicalOperator>, BitSet>();
-    private final HashMap<Mutable<ILogicalOperator>, MutableInt> clusterMap = new HashMap<Mutable<ILogicalOperator>, MutableInt>();
-    private final HashMap<Integer, BitSet> clusterWaitForMap = new HashMap<Integer, BitSet>();
-    private int lastUsedClusterId = 0;
-
-    @Override
-    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
-        AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
-        if (op.getOperatorTag() != LogicalOperatorTag.WRITE && op.getOperatorTag() != LogicalOperatorTag.WRITE_RESULT
-                && op.getOperatorTag() != LogicalOperatorTag.DISTRIBUTE_RESULT) {
-            return false;
-        }
-        if (!roots.contains(op))
-            roots.add(new MutableObject<ILogicalOperator>(op));
-        return false;
-    }
-
-    @Override
-    public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
-            throws AlgebricksException {
-        AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
-        if (op.getOperatorTag() != LogicalOperatorTag.WRITE && op.getOperatorTag() != LogicalOperatorTag.WRITE_RESULT
-                && op.getOperatorTag() != LogicalOperatorTag.DISTRIBUTE_RESULT) {
-            return false;
-        }
-        boolean rewritten = false;
-        boolean changed = false;
-        if (roots.size() > 0) {
-            do {
-                changed = false;
-                // applying the rewriting until fixpoint
-                topDownMaterialization(roots);
-                genCandidates(context);
-                removeTrivialShare();
-                if (equivalenceClasses.size() > 0)
-                    changed = rewrite(context);
-                if (!rewritten)
-                    rewritten = changed;
-                equivalenceClasses.clear();
-                childrenToParents.clear();
-                opToCandidateInputs.clear();
-                clusterMap.clear();
-                clusterWaitForMap.clear();
-                lastUsedClusterId = 0;
-            } while (changed);
-            roots.clear();
-        }
-        return rewritten;
-    }
-
-    private void removeTrivialShare() {
-        for (List<Mutable<ILogicalOperator>> candidates : equivalenceClasses) {
-            for (int i = candidates.size() - 1; i >= 0; i--) {
-                Mutable<ILogicalOperator> opRef = candidates.get(i);
-                AbstractLogicalOperator aop = (AbstractLogicalOperator) opRef.getValue();
-                if (aop.getOperatorTag() == LogicalOperatorTag.EXCHANGE)
-                    aop = (AbstractLogicalOperator) aop.getInputs().get(0).getValue();
-                if (aop.getOperatorTag() == LogicalOperatorTag.EMPTYTUPLESOURCE)
-                    candidates.remove(i);
-            }
-        }
-        for (int i = equivalenceClasses.size() - 1; i >= 0; i--)
-            if (equivalenceClasses.get(i).size() < 2)
-                equivalenceClasses.remove(i);
-    }
-
-    private boolean rewrite(IOptimizationContext context) throws AlgebricksException {
-        boolean changed = false;
-        for (List<Mutable<ILogicalOperator>> members : equivalenceClasses) {
-            if (rewriteForOneEquivalentClass(members, context))
-                changed = true;
-        }
-        return changed;
-    }
-
-    private boolean rewriteForOneEquivalentClass(List<Mutable<ILogicalOperator>> members, IOptimizationContext context)
-            throws AlgebricksException {
-        List<Mutable<ILogicalOperator>> group = new ArrayList<Mutable<ILogicalOperator>>();
-        boolean rewritten = false;
-        while (members.size() > 0) {
-            group.clear();
-            Mutable<ILogicalOperator> candidate = members.remove(members.size() - 1);
-            group.add(candidate);
-            for (int i = members.size() - 1; i >= 0; i--) {
-                Mutable<ILogicalOperator> peer = members.get(i);
-                if (IsomorphismUtilities.isOperatorIsomorphic(candidate.getValue(), peer.getValue())) {
-                    group.add(peer);
-                    members.remove(i);
-                }
-            }
-            boolean[] materializationFlags = computeMaterilizationFlags(group);
-            if (group.isEmpty()) {
-                continue;
-            }
-            candidate = group.get(0);
-            ReplicateOperator rop = new ReplicateOperator(group.size(), materializationFlags);
-            rop.setPhysicalOperator(new ReplicatePOperator());
-            rop.setExecutionMode(ExecutionMode.PARTITIONED);
-            Mutable<ILogicalOperator> ropRef = new MutableObject<ILogicalOperator>(rop);
-            AbstractLogicalOperator aopCandidate = (AbstractLogicalOperator) candidate.getValue();
-            List<Mutable<ILogicalOperator>> originalCandidateParents = childrenToParents.get(candidate);
-
-            if (aopCandidate.getOperatorTag() == LogicalOperatorTag.EXCHANGE) {
-                rop.getInputs().add(candidate);
-            } else {
-                AbstractLogicalOperator beforeExchange = new ExchangeOperator();
-                beforeExchange.setPhysicalOperator(new OneToOneExchangePOperator());
-                Mutable<ILogicalOperator> beforeExchangeRef = new MutableObject<ILogicalOperator>(beforeExchange);
-                beforeExchange.getInputs().add(candidate);
-                context.computeAndSetTypeEnvironmentForOperator(beforeExchange);
-                rop.getInputs().add(beforeExchangeRef);
-            }
-            context.computeAndSetTypeEnvironmentForOperator(rop);
-
-            for (Mutable<ILogicalOperator> parentRef : originalCandidateParents) {
-                AbstractLogicalOperator parent = (AbstractLogicalOperator) parentRef.getValue();
-                int index = parent.getInputs().indexOf(candidate);
-                if (parent.getOperatorTag() == LogicalOperatorTag.EXCHANGE) {
-                    parent.getInputs().set(index, ropRef);
-                    rop.getOutputs().add(parentRef);
-                } else {
-                    AbstractLogicalOperator exchange = new ExchangeOperator();
-                    exchange.setPhysicalOperator(new OneToOneExchangePOperator());
-                    MutableObject<ILogicalOperator> exchangeRef = new MutableObject<ILogicalOperator>(exchange);
-                    exchange.getInputs().add(ropRef);
-                    rop.getOutputs().add(exchangeRef);
-                    context.computeAndSetTypeEnvironmentForOperator(exchange);
-                    parent.getInputs().set(index, exchangeRef);
-                    context.computeAndSetTypeEnvironmentForOperator(parent);
-                }
-            }
-            List<LogicalVariable> liveVarsNew = new ArrayList<LogicalVariable>();
-            VariableUtilities.getLiveVariables(candidate.getValue(), liveVarsNew);
-            ArrayList<Mutable<ILogicalExpression>> assignExprs = new ArrayList<Mutable<ILogicalExpression>>();
-            for (LogicalVariable liveVar : liveVarsNew)
-                assignExprs.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(liveVar)));
-            for (Mutable<ILogicalOperator> ref : group) {
-                if (ref.equals(candidate))
-                    continue;
-                ArrayList<LogicalVariable> liveVars = new ArrayList<LogicalVariable>();
-                Map<LogicalVariable, LogicalVariable> variableMappingBack = new HashMap<LogicalVariable, LogicalVariable>();
-                IsomorphismUtilities.mapVariablesTopDown(ref.getValue(), candidate.getValue(), variableMappingBack);
-                for (int i = 0; i < liveVarsNew.size(); i++) {
-                    liveVars.add(variableMappingBack.get(liveVarsNew.get(i)));
-                }
-
-                AbstractLogicalOperator assignOperator = new AssignOperator(liveVars, assignExprs);
-                assignOperator.setPhysicalOperator(new AssignPOperator());
-                AbstractLogicalOperator projectOperator = new ProjectOperator(liveVars);
-                projectOperator.setPhysicalOperator(new StreamProjectPOperator());
-                AbstractLogicalOperator exchOp = new ExchangeOperator();
-                exchOp.setPhysicalOperator(new OneToOneExchangePOperator());
-                exchOp.getInputs().add(ropRef);
-                MutableObject<ILogicalOperator> exchOpRef = new MutableObject<ILogicalOperator>(exchOp);
-                rop.getOutputs().add(exchOpRef);
-                assignOperator.getInputs().add(exchOpRef);
-                projectOperator.getInputs().add(new MutableObject<ILogicalOperator>(assignOperator));
-
-                // set the types
-                context.computeAndSetTypeEnvironmentForOperator(exchOp);
-                context.computeAndSetTypeEnvironmentForOperator(assignOperator);
-                context.computeAndSetTypeEnvironmentForOperator(projectOperator);
-
-                List<Mutable<ILogicalOperator>> parentOpList = childrenToParents.get(ref);
-                for (Mutable<ILogicalOperator> parentOpRef : parentOpList) {
-                    AbstractLogicalOperator parentOp = (AbstractLogicalOperator) parentOpRef.getValue();
-                    int index = parentOp.getInputs().indexOf(ref);
-                    if (parentOp.getOperatorTag() == LogicalOperatorTag.EXCHANGE) {
-                        AbstractLogicalOperator parentOpNext = (AbstractLogicalOperator) childrenToParents
-                                .get(parentOpRef).get(0).getValue();
-                        if (parentOpNext.isMap()) {
-                            index = parentOpNext.getInputs().indexOf(parentOpRef);
-                            parentOp = parentOpNext;
-                        }
-                    }
-
-                    ILogicalOperator childOp = parentOp.getOperatorTag() == LogicalOperatorTag.PROJECT ? assignOperator
-                            : projectOperator;
-                    if (parentOp.isMap()) {
-                        parentOp.getInputs().set(index, new MutableObject<ILogicalOperator>(childOp));
-                    } else {
-                        AbstractLogicalOperator exchg = new ExchangeOperator();
-                        exchg.setPhysicalOperator(new OneToOneExchangePOperator());
-                        exchg.getInputs().add(new MutableObject<ILogicalOperator>(childOp));
-                        parentOp.getInputs().set(index, new MutableObject<ILogicalOperator>(exchg));
-                        context.computeAndSetTypeEnvironmentForOperator(exchg);
-                    }
-                    context.computeAndSetTypeEnvironmentForOperator(parentOp);
-                }
-            }
-            rewritten = true;
-        }
-        return rewritten;
-    }
-
-    private void genCandidates(IOptimizationContext context) throws AlgebricksException {
-        List<List<Mutable<ILogicalOperator>>> previousEquivalenceClasses = new ArrayList<List<Mutable<ILogicalOperator>>>();
-        while (equivalenceClasses.size() > 0) {
-            previousEquivalenceClasses.clear();
-            for (List<Mutable<ILogicalOperator>> candidates : equivalenceClasses) {
-                List<Mutable<ILogicalOperator>> candidatesCopy = new ArrayList<Mutable<ILogicalOperator>>();
-                candidatesCopy.addAll(candidates);
-                previousEquivalenceClasses.add(candidatesCopy);
-            }
-            List<Mutable<ILogicalOperator>> currentLevelOpRefs = new ArrayList<Mutable<ILogicalOperator>>();
-            for (List<Mutable<ILogicalOperator>> candidates : equivalenceClasses) {
-                if (candidates.size() > 0) {
-                    for (Mutable<ILogicalOperator> opRef : candidates) {
-                        List<Mutable<ILogicalOperator>> refs = childrenToParents.get(opRef);
-                        if (refs != null)
-                            currentLevelOpRefs.addAll(refs);
-                    }
-                }
-                if (currentLevelOpRefs.size() == 0)
-                    continue;
-                candidatesGrow(currentLevelOpRefs, candidates);
-            }
-            if (currentLevelOpRefs.size() == 0)
-                break;
-            prune(context);
-        }
-        if (equivalenceClasses.size() < 1 && previousEquivalenceClasses.size() > 0) {
-            equivalenceClasses.addAll(previousEquivalenceClasses);
-            prune(context);
-        }
-    }
-
-    private void topDownMaterialization(List<Mutable<ILogicalOperator>> tops) {
-        List<Mutable<ILogicalOperator>> candidates = new ArrayList<Mutable<ILogicalOperator>>();
-        List<Mutable<ILogicalOperator>> nextLevel = new ArrayList<Mutable<ILogicalOperator>>();
-        for (Mutable<ILogicalOperator> op : tops) {
-            for (Mutable<ILogicalOperator> opRef : op.getValue().getInputs()) {
-                List<Mutable<ILogicalOperator>> opRefList = childrenToParents.get(opRef);
-                if (opRefList == null) {
-                    opRefList = new ArrayList<Mutable<ILogicalOperator>>();
-                    childrenToParents.put(opRef, opRefList);
-                    nextLevel.add(opRef);
-                }
-                opRefList.add(op);
-            }
-            if (op.getValue().getInputs().size() == 0)
-                candidates.add(op);
-        }
-        if (equivalenceClasses.size() > 0) {
-            equivalenceClasses.get(0).addAll(candidates);
-        } else {
-            equivalenceClasses.add(candidates);
-        }
-        if (nextLevel.size() > 0) {
-            topDownMaterialization(nextLevel);
-        }
-    }
-
-    private void candidatesGrow(List<Mutable<ILogicalOperator>> opList, List<Mutable<ILogicalOperator>> candidates) {
-        List<Mutable<ILogicalOperator>> previousCandidates = new ArrayList<Mutable<ILogicalOperator>>();
-        previousCandidates.addAll(candidates);
-        candidates.clear();
-        boolean validCandidate = false;
-        for (Mutable<ILogicalOperator> op : opList) {
-            List<Mutable<ILogicalOperator>> inputs = op.getValue().getInputs();
-            for (int i = 0; i < inputs.size(); i++) {
-                Mutable<ILogicalOperator> inputRef = inputs.get(i);
-                validCandidate = false;
-                for (Mutable<ILogicalOperator> candidate : previousCandidates) {
-                    // if current input is in candidates
-                    if (inputRef.getValue().equals(candidate.getValue())) {
-                        if (inputs.size() == 1) {
-                            validCandidate = true;
-                        } else {
-                            BitSet candidateInputBitMap = opToCandidateInputs.get(op);
-                            if (candidateInputBitMap == null) {
-                                candidateInputBitMap = new BitSet(inputs.size());
-                                opToCandidateInputs.put(op, candidateInputBitMap);
-                            }
-                            candidateInputBitMap.set(i);
-                            if (candidateInputBitMap.cardinality() == inputs.size()) {
-                                validCandidate = true;
-                            }
-                        }
-                        break;
-                    }
-                }
-            }
-            if (!validCandidate)
-                continue;
-            if (!candidates.contains(op))
-                candidates.add(op);
-        }
-    }
-
-    private void prune(IOptimizationContext context) throws AlgebricksException {
-        List<List<Mutable<ILogicalOperator>>> previousEquivalenceClasses = new ArrayList<List<Mutable<ILogicalOperator>>>();
-        for (List<Mutable<ILogicalOperator>> candidates : equivalenceClasses) {
-            List<Mutable<ILogicalOperator>> candidatesCopy = new ArrayList<Mutable<ILogicalOperator>>();
-            candidatesCopy.addAll(candidates);
-            previousEquivalenceClasses.add(candidatesCopy);
-        }
-        equivalenceClasses.clear();
-        for (List<Mutable<ILogicalOperator>> candidates : previousEquivalenceClasses) {
-            boolean[] reserved = new boolean[candidates.size()];
-            for (int i = 0; i < reserved.length; i++)
-                reserved[i] = false;
-            for (int i = candidates.size() - 1; i >= 0; i--) {
-                if (reserved[i] == false) {
-                    List<Mutable<ILogicalOperator>> equivalentClass = new ArrayList<Mutable<ILogicalOperator>>();
-                    ILogicalOperator candidate = candidates.get(i).getValue();
-                    equivalentClass.add(candidates.get(i));
-                    for (int j = i - 1; j >= 0; j--) {
-                        ILogicalOperator peer = candidates.get(j).getValue();
-                        if (IsomorphismUtilities.isOperatorIsomorphic(candidate, peer)) {
-                            reserved[i] = true;
-                            reserved[j] = true;
-                            equivalentClass.add(candidates.get(j));
-                        }
-                    }
-                    if (equivalentClass.size() > 1) {
-                        equivalenceClasses.add(equivalentClass);
-                        Collections.reverse(equivalentClass);
-                    }
-                }
-            }
-            for (int i = candidates.size() - 1; i >= 0; i--) {
-                if (!reserved[i]) {
-                    candidates.remove(i);
-                }
-            }
-        }
-    }
-
-    private boolean[] computeMaterilizationFlags(List<Mutable<ILogicalOperator>> group) {
-        lastUsedClusterId = 0;
-        for (Mutable<ILogicalOperator> root : roots) {
-            computeClusters(null, root, new MutableInt(++lastUsedClusterId));
-        }
-        boolean[] materializationFlags = new boolean[group.size()];
-        boolean worthMaterialization = worthMaterialization(group.get(0));
-        boolean requiresMaterialization;
-        // get clusterIds for each candidate in the group
-        List<Integer> groupClusterIds = new ArrayList<Integer>(group.size());
-        for (int i = 0; i < group.size(); i++) {
-            groupClusterIds.add(clusterMap.get(group.get(i)).getValue());
-        }
-        for (int i = group.size() - 1; i >= 0; i--) {
-            requiresMaterialization = requiresMaterialization(groupClusterIds, i);
-            if (requiresMaterialization && !worthMaterialization) {
-                group.remove(i);
-                groupClusterIds.remove(i);
-            }
-            materializationFlags[i] = requiresMaterialization;
-        }
-        if (group.size() < 2) {
-            group.clear();
-        }
-        // if does not worth materialization, the flags for the remaining candidates should be false
-        return worthMaterialization ? materializationFlags : new boolean[group.size()];
-    }
-
-    private boolean requiresMaterialization(List<Integer> groupClusterIds, int index) {
-        Integer clusterId = groupClusterIds.get(index);
-        BitSet blockingClusters = new BitSet();
-        getAllBlockingClusterIds(clusterId, blockingClusters);
-        if (!blockingClusters.isEmpty()) {
-            for (int i = 0; i < groupClusterIds.size(); i++) {
-                if (i == index) {
-                    continue;
-                }
-                if (blockingClusters.get(groupClusterIds.get(i))) {
-                    return true;
-                }
-            }
-        }
-        return false;
-    }
-
-    private void getAllBlockingClusterIds(int clusterId, BitSet blockingClusters) {
-        BitSet waitFor = clusterWaitForMap.get(clusterId);
-        if (waitFor != null) {
-            for (int i = waitFor.nextSetBit(0); i >= 0; i = waitFor.nextSetBit(i + 1)) {
-                getAllBlockingClusterIds(i, blockingClusters);
-            }
-            blockingClusters.or(waitFor);
-        }
-    }
-
-    private void computeClusters(Mutable<ILogicalOperator> parentRef, Mutable<ILogicalOperator> opRef,
-            MutableInt currentClusterId) {
-        // only replicate operator has multiple outputs
-        int outputIndex = 0;
-        if (opRef.getValue().getOperatorTag() == LogicalOperatorTag.REPLICATE) {
-            ReplicateOperator rop = (ReplicateOperator) opRef.getValue();
-            List<Mutable<ILogicalOperator>> outputs = rop.getOutputs();
-            for (outputIndex = 0; outputIndex < outputs.size(); outputIndex++) {
-                if (outputs.get(outputIndex).equals(parentRef)) {
-                    break;
-                }
-            }
-        }
-        AbstractLogicalOperator aop = (AbstractLogicalOperator) opRef.getValue();
-        Pair<int[], int[]> labels = aop.getPhysicalOperator().getInputOutputDependencyLabels(opRef.getValue());
-        List<Mutable<ILogicalOperator>> inputs = opRef.getValue().getInputs();
-        for (int i = 0; i < inputs.size(); i++) {
-            Mutable<ILogicalOperator> inputRef = inputs.get(i);
-            if (labels.second[outputIndex] == 1 && labels.first[i] == 0) { // 1 -> 0
-                if (labels.second.length == 1) {
-                    clusterMap.put(opRef, currentClusterId);
-                    // start a new cluster
-                    MutableInt newClusterId = new MutableInt(++lastUsedClusterId);
-                    computeClusters(opRef, inputRef, newClusterId);
-                    BitSet waitForList = clusterWaitForMap.get(currentClusterId.getValue());
-                    if (waitForList == null) {
-                        waitForList = new BitSet();
-                        clusterWaitForMap.put(currentClusterId.getValue(), waitForList);
-                    }
-                    waitForList.set(newClusterId.getValue());
-                }
-            } else { // 0 -> 0 and 1 -> 1
-                MutableInt prevClusterId = clusterMap.get(opRef);
-                if (prevClusterId == null || prevClusterId.getValue().equals(currentClusterId.getValue())) {
-                    clusterMap.put(opRef, currentClusterId);
-                    computeClusters(opRef, inputRef, currentClusterId);
-                } else {
-                    // merge prevClusterId and currentClusterId: update all the map entries that has currentClusterId to prevClusterId
-                    for (BitSet bs : clusterWaitForMap.values()) {
-                        if (bs.get(currentClusterId.getValue())) {
-                            bs.clear(currentClusterId.getValue());
-                            bs.set(prevClusterId.getValue());
-                        }
-                    }
-                    currentClusterId.setValue(prevClusterId.getValue());
-                }
-            }
-        }
-    }
-
-    protected boolean worthMaterialization(Mutable<ILogicalOperator> candidate) {
-        AbstractLogicalOperator aop = (AbstractLogicalOperator) candidate.getValue();
-        if (aop.getPhysicalOperator().expensiveThanMaterialization()) {
-            return true;
-        }
-        List<Mutable<ILogicalOperator>> inputs = candidate.getValue().getInputs();
-        for (Mutable<ILogicalOperator> inputRef : inputs) {
-            if (worthMaterialization(inputRef)) {
-                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/ExtractFunctionsFromJoinConditionRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/ExtractFunctionsFromJoinConditionRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/ExtractFunctionsFromJoinConditionRule.java
deleted file mode 100644
index 8f8e62b..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/ExtractFunctionsFromJoinConditionRule.java
+++ /dev/null
@@ -1,155 +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.LogicalExpressionTag;
-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.AbstractFunctionCallExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.functions.AlgebricksBuiltinFunctions;
-import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-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.AssignOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.visitors.VariableUtilities;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-/**
- * Factors out function expressions from each comparison function or similarity function in join condition by
- * assigning them to a variables, and replacing the function expressions with references to those variables.
- * Examples:
- * Plan with function expressions in comparison or similarity condition of join expression.
- * Generates one assign operator per extracted function expression.
- *
- * <pre>
- * Before plan:
- * 
- *   join ( eq( funcX($$1), funcX($$2) ) )
- * 
- * After plan:
- * 
- *   join (eq($$3,$$4))
- *   assign [$$4] <- [funcY($$2)]
- *   assign [$$3] <- [funcX($$1)]
- * </pre>
- */
-public class ExtractFunctionsFromJoinConditionRule 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.INNERJOIN
-                && op.getOperatorTag() != LogicalOperatorTag.LEFTOUTERJOIN) {
-            return false;
-        }
-        AbstractBinaryJoinOperator joinOp = (AbstractBinaryJoinOperator) op;
-        ILogicalExpression expr = joinOp.getCondition().getValue();
-
-        return assignFunctionExpressions(joinOp, expr, context);
-
-    }
-
-    private boolean assignFunctionExpressions(AbstractLogicalOperator joinOp, ILogicalExpression expr,
-            IOptimizationContext context) throws AlgebricksException {
-        if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
-            return false;
-        }
-        AbstractFunctionCallExpression fexp = (AbstractFunctionCallExpression) expr;
-        FunctionIdentifier fi = fexp.getFunctionIdentifier();
-
-        boolean modified = false;
-        if (fi.equals(AlgebricksBuiltinFunctions.AND) || fi.equals(AlgebricksBuiltinFunctions.OR)
-                || processArgumentsToFunction(fi)) {
-            for (Mutable<ILogicalExpression> a : fexp.getArguments()) {
-                if (assignFunctionExpressions(joinOp, a.getValue(), context)) {
-                    modified = true;
-                }
-            }
-            return modified;
-        } else if (AlgebricksBuiltinFunctions.isComparisonFunction(fi) || isComparisonFunction(fi)) {
-            for (Mutable<ILogicalExpression> exprRef : fexp.getArguments()) {
-                if (exprRef.getValue().getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
-                    LogicalVariable newVar = context.newVar();
-                    AssignOperator newAssign = new AssignOperator(newVar, new MutableObject<ILogicalExpression>(exprRef
-                            .getValue().cloneExpression()));
-                    newAssign.setExecutionMode(joinOp.getExecutionMode());
-
-                    // Place assign below joinOp.
-                    List<LogicalVariable> used = new ArrayList<LogicalVariable>();
-                    VariableUtilities.getUsedVariables(newAssign, used);
-
-                    Mutable<ILogicalOperator> leftBranchRef = joinOp.getInputs().get(0);
-                    ILogicalOperator leftBranch = leftBranchRef.getValue();
-                    List<LogicalVariable> leftBranchVariables = new ArrayList<LogicalVariable>();
-                    VariableUtilities.getLiveVariables(leftBranch, leftBranchVariables);
-                    if (leftBranchVariables.containsAll(used)) {
-                        // place assign on left branch
-                        newAssign.getInputs().add(new MutableObject<ILogicalOperator>(leftBranch));
-                        leftBranchRef.setValue(newAssign);
-                        modified = true;
-                    } else {
-                        Mutable<ILogicalOperator> rightBranchRef = joinOp.getInputs().get(1);
-                        ILogicalOperator rightBranch = rightBranchRef.getValue();
-                        List<LogicalVariable> rightBranchVariables = new ArrayList<LogicalVariable>();
-                        VariableUtilities.getLiveVariables(rightBranch, rightBranchVariables);
-                        if (rightBranchVariables.containsAll(used)) {
-                            // place assign on right branch
-                            newAssign.getInputs().add(new MutableObject<ILogicalOperator>(rightBranch));
-                            rightBranchRef.setValue(newAssign);
-                            modified = true;
-                        }
-                    }
-
-                    if (modified) {
-                        // Replace original expr with variable reference.
-                        exprRef.setValue(new VariableReferenceExpression(newVar));
-                        context.computeAndSetTypeEnvironmentForOperator(newAssign);
-                        context.computeAndSetTypeEnvironmentForOperator(joinOp);
-                    }
-                }
-            }
-            return modified;
-        } else {
-            return false;
-        }
-    }
-
-    protected boolean processArgumentsToFunction(FunctionIdentifier fi) {
-        return false;
-    }
-
-    protected boolean isComparisonFunction(FunctionIdentifier fi) {
-        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/ExtractGbyExpressionsRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/ExtractGbyExpressionsRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/ExtractGbyExpressionsRule.java
deleted file mode 100644
index 2790166..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/ExtractGbyExpressionsRule.java
+++ /dev/null
@@ -1,111 +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 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.LogicalExpressionTag;
-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.VariableReferenceExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator;
-
-/**
- * Needed only bc. current Hyrax operators require keys to be fields.
- */
-public class ExtractGbyExpressionsRule extends AbstractExtractExprRule {
-
-    @Override
-    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) {
-        return false;
-    }
-
-    @Override
-    public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
-            throws AlgebricksException {
-        AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue();
-        if (op1.getOperatorTag() != LogicalOperatorTag.GROUP) {
-            return false;
-        }
-
-        if (context.checkIfInDontApplySet(this, op1)) {
-            return false;
-        }
-        context.addToDontApplySet(this, op1);
-        GroupByOperator g = (GroupByOperator) op1;
-        boolean r1 = gbyExprWasRewritten(g, context);
-        boolean r2 = decorExprWasRewritten(g, context);
-        boolean fired = r1 || r2;
-        if (fired) {
-            context.computeAndSetTypeEnvironmentForOperator(g);
-        }
-        return fired;
-    }
-
-    private boolean gbyExprWasRewritten(GroupByOperator g, IOptimizationContext context) throws AlgebricksException {
-        if (!gbyHasComplexExpr(g)) {
-            return false;
-        }
-        Mutable<ILogicalOperator> opRef2 = g.getInputs().get(0);
-        for (Pair<LogicalVariable, Mutable<ILogicalExpression>> gbyPair : g.getGroupByList()) {
-            ILogicalExpression expr = gbyPair.second.getValue();
-            if (expr.getExpressionTag() != LogicalExpressionTag.VARIABLE) {
-                LogicalVariable v = extractExprIntoAssignOpRef(expr, opRef2, context);
-                gbyPair.second.setValue(new VariableReferenceExpression(v));
-            }
-        }
-        return true;
-    }
-
-    private boolean decorExprWasRewritten(GroupByOperator g, IOptimizationContext context) throws AlgebricksException {
-        if (!decorHasComplexExpr(g)) {
-            return false;
-        }
-        Mutable<ILogicalOperator> opRef2 = g.getInputs().get(0);
-        for (Pair<LogicalVariable, Mutable<ILogicalExpression>> decorPair : g.getDecorList()) {
-            ILogicalExpression expr = decorPair.second.getValue();
-            if (expr.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
-                LogicalVariable v = extractExprIntoAssignOpRef(expr, opRef2, context);
-                decorPair.second.setValue(new VariableReferenceExpression(v));
-            }
-        }
-        return true;
-    }
-
-    private boolean gbyHasComplexExpr(GroupByOperator g) {
-        for (Pair<LogicalVariable, Mutable<ILogicalExpression>> gbyPair : g.getGroupByList()) {
-            if (gbyPair.second.getValue().getExpressionTag() != LogicalExpressionTag.VARIABLE) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    private boolean decorHasComplexExpr(GroupByOperator g) {
-        for (Pair<LogicalVariable, Mutable<ILogicalExpression>> gbyPair : g.getDecorList()) {
-            if (gbyPair.second.getValue().getExpressionTag() != LogicalExpressionTag.VARIABLE) {
-                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/FactorRedundantGroupAndDecorVarsRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/FactorRedundantGroupAndDecorVarsRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/FactorRedundantGroupAndDecorVarsRule.java
deleted file mode 100644
index 6cb01f2..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/FactorRedundantGroupAndDecorVarsRule.java
+++ /dev/null
@@ -1,92 +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.HashMap;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Map;
-
-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.LogicalExpressionTag;
-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.VariableReferenceExpression;
-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.GroupByOperator;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-public class FactorRedundantGroupAndDecorVarsRule 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 gby = (GroupByOperator) op;
-        Map<LogicalVariable, LogicalVariable> varRhsToLhs = new HashMap<LogicalVariable, LogicalVariable>();
-        boolean gvChanged = factorRedundantRhsVars(gby.getGroupByList(), opRef, varRhsToLhs, context);
-        boolean dvChanged = factorRedundantRhsVars(gby.getDecorList(), opRef, varRhsToLhs, context);
-
-        return gvChanged || dvChanged;
-    }
-
-    private boolean factorRedundantRhsVars(List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> veList,
-            Mutable<ILogicalOperator> opRef, Map<LogicalVariable, LogicalVariable> varRhsToLhs,
-            IOptimizationContext context) throws AlgebricksException {
-        varRhsToLhs.clear();
-        ListIterator<Pair<LogicalVariable, Mutable<ILogicalExpression>>> iter = veList.listIterator();
-        boolean changed = false;
-        while (iter.hasNext()) {
-            Pair<LogicalVariable, Mutable<ILogicalExpression>> p = iter.next();
-            if (p.second.getValue().getExpressionTag() != LogicalExpressionTag.VARIABLE) {
-                continue;
-            }
-            LogicalVariable v = GroupByOperator.getDecorVariable(p);
-            LogicalVariable lhs = varRhsToLhs.get(v);
-            if (lhs != null) {
-                if (p.first != null) {
-                    AssignOperator assign = new AssignOperator(p.first, new MutableObject<ILogicalExpression>(
-                            new VariableReferenceExpression(lhs)));
-                    ILogicalOperator op = opRef.getValue();
-                    assign.getInputs().add(new MutableObject<ILogicalOperator>(op));
-                    opRef.setValue(assign);
-                    context.computeAndSetTypeEnvironmentForOperator(assign);
-                }
-                iter.remove();
-                changed = true;
-            } else {
-                varRhsToLhs.put(v, p.first);
-            }
-        }
-        return changed;
-    }
-
-}

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/InferTypesRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/InferTypesRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/InferTypesRule.java
deleted file mode 100644
index 3530a5f..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/InferTypesRule.java
+++ /dev/null
@@ -1,42 +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 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.rewriter.base.IAlgebraicRewriteRule;
-
-public class InferTypesRule 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 {
-        ILogicalOperator op = opRef.getValue();
-        if (context.getOutputTypeEnvironment(op) != null) {
-            return false;
-        }
-        context.computeAndSetTypeEnvironmentForOperator(op);
-        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/InlineAssignIntoAggregateRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/InlineAssignIntoAggregateRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/InlineAssignIntoAggregateRule.java
deleted file mode 100644
index 99a1fae..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/InlineAssignIntoAggregateRule.java
+++ /dev/null
@@ -1,136 +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.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.expressions.AbstractFunctionCallExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.ConstantExpression;
-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.AggregateOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AssignOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.visitors.AbstractConstVarFunVisitor;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-public class InlineAssignIntoAggregateRule 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.GROUP) {
-            return false;
-        }
-        boolean changed = false;
-        GroupByOperator gbyOp = (GroupByOperator) op;
-        for (ILogicalPlan p : gbyOp.getNestedPlans()) {
-            for (Mutable<ILogicalOperator> r : p.getRoots()) {
-                if (inlined(r)) {
-                    changed = true;
-                }
-            }
-        }
-        return changed;
-    }
-
-    private boolean inlined(Mutable<ILogicalOperator> r) throws AlgebricksException {
-        AbstractLogicalOperator op1 = (AbstractLogicalOperator) r.getValue();
-        if (op1.getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
-            return false;
-        }
-        AbstractLogicalOperator op2 = (AbstractLogicalOperator) op1.getInputs().get(0).getValue();
-        if (op2.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
-            return false;
-        }
-        AggregateOperator agg = (AggregateOperator) op1;
-        AssignOperator assign = (AssignOperator) op2;
-        VarExprSubstitution ves = new VarExprSubstitution(assign.getVariables(), assign.getExpressions());
-        for (Mutable<ILogicalExpression> exprRef : agg.getExpressions()) {
-            ILogicalExpression expr = exprRef.getValue();
-            Pair<Boolean, ILogicalExpression> p = expr.accept(ves, null);
-            if (p.first == true) {
-                exprRef.setValue(p.second);
-            }
-            // AbstractLogicalExpression ale = (AbstractLogicalExpression) expr;
-            // ale.accept(ves, null);
-        }
-        List<Mutable<ILogicalOperator>> op1InpList = op1.getInputs();
-        op1InpList.clear();
-        op1InpList.add(op2.getInputs().get(0));
-        return true;
-    }
-
-    private class VarExprSubstitution extends AbstractConstVarFunVisitor<Pair<Boolean, ILogicalExpression>, Void> {
-
-        private List<LogicalVariable> variables;
-        private List<Mutable<ILogicalExpression>> expressions;
-
-        public VarExprSubstitution(List<LogicalVariable> variables, List<Mutable<ILogicalExpression>> expressions) {
-            this.variables = variables;
-            this.expressions = expressions;
-        }
-
-        @Override
-        public Pair<Boolean, ILogicalExpression> visitConstantExpression(ConstantExpression expr, Void arg) {
-            return new Pair<Boolean, ILogicalExpression>(false, expr);
-        }
-
-        @Override
-        public Pair<Boolean, ILogicalExpression> visitFunctionCallExpression(AbstractFunctionCallExpression expr,
-                Void arg) throws AlgebricksException {
-            boolean changed = false;
-            for (Mutable<ILogicalExpression> eRef : expr.getArguments()) {
-                ILogicalExpression e = eRef.getValue();
-                Pair<Boolean, ILogicalExpression> p = e.accept(this, arg);
-                if (p.first) {
-                    eRef.setValue(p.second);
-                    changed = true;
-                }
-            }
-            return new Pair<Boolean, ILogicalExpression>(changed, expr);
-        }
-
-        @Override
-        public Pair<Boolean, ILogicalExpression> visitVariableReferenceExpression(VariableReferenceExpression expr,
-                Void arg) {
-            LogicalVariable v = expr.getVariableReference();
-            int idx = variables.indexOf(v);
-            if (idx < 0) {
-                return new Pair<Boolean, ILogicalExpression>(false, expr);
-            } else {
-                return new Pair<Boolean, ILogicalExpression>(true, expressions.get(idx).getValue());
-            }
-
-        }
-
-    }
-}

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/InlineSingleReferenceVariablesRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/InlineSingleReferenceVariablesRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/InlineSingleReferenceVariablesRule.java
deleted file mode 100644
index 9ae94ba..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/InlineSingleReferenceVariablesRule.java
+++ /dev/null
@@ -1,94 +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 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.LogicalVariable;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.visitors.VariableUtilities;
-
-/**
- * Inlines variables that are referenced exactly once.
- * 
- * Preconditions/Assumptions:
- * Assumes no projects are in the plan.
- * 
- * Example assuming variable $$3 is referenced exactly once.
- * 
- * Before plan:
- * select (funcA($$3))
- *   ...
- *     assign [$$3] <- [field-access($$0, 1)]
- * 
- * After plan:
- * select (funcA(field-access($$0, 1))
- *   ...
- *     assign [] <- []
- */
-public class InlineSingleReferenceVariablesRule extends InlineVariablesRule {
-
-    // Maps from variable to a list of operators using that variable.
-    protected Map<LogicalVariable, List<ILogicalOperator>> usedVarsMap = new HashMap<LogicalVariable, List<ILogicalOperator>>();
-    protected List<LogicalVariable> usedVars = new ArrayList<LogicalVariable>();
-    
-    @Override
-    protected void prepare(IOptimizationContext context) {
-        super.prepare(context);
-        usedVarsMap.clear();
-        usedVars.clear();
-    }
-    
-    @Override
-    protected boolean performFinalAction() throws AlgebricksException {
-        boolean modified = false;
-        for (Map.Entry<LogicalVariable, List<ILogicalOperator>> entry : usedVarsMap.entrySet()) {
-            // Perform replacement only if variable is referenced a single time.
-            if (entry.getValue().size() == 1) {
-                ILogicalOperator op = entry.getValue().get(0);
-                if (!op.requiresVariableReferenceExpressions()) {
-                    inlineVisitor.setOperator(op);
-                    inlineVisitor.setTargetVariable(entry.getKey());
-                    if (op.acceptExpressionTransform(inlineVisitor)) {
-                        modified = true;
-                    }
-                    inlineVisitor.setTargetVariable(null);
-                }         
-            }
-        }
-        return modified;
-    }
-
-    @Override
-    protected boolean performBottomUpAction(AbstractLogicalOperator op) throws AlgebricksException {
-        usedVars.clear();
-        VariableUtilities.getUsedVariables(op, usedVars);
-        for (LogicalVariable var : usedVars) {
-            List<ILogicalOperator> opsUsingVar = usedVarsMap.get(var);
-            if (opsUsingVar == null) {
-                opsUsingVar = new ArrayList<ILogicalOperator>();
-                usedVarsMap.put(var, opsUsingVar);
-            }
-            opsUsingVar.add(op);
-        }
-        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/InlineVariablesRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/InlineVariablesRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/InlineVariablesRule.java
deleted file mode 100644
index 6390efc..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/InlineVariablesRule.java
+++ /dev/null
@@ -1,253 +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.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-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.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.LogicalExpressionTag;
-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.AbstractFunctionCallExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.AbstractLogicalExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-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.SubplanOperator;
-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.visitors.ILogicalExpressionReferenceTransform;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-/**
- * Replaces variable reference expressions with their assigned function-call expression where applicable
- * (some variables are generated by datasources).
- * Inlining variables may enable other optimizations by allowing selects and assigns to be moved
- * (e.g., a select may be pushed into a join to enable an efficient physical join operator).
- * Preconditions/Assumptions:
- * Assumes no projects are in the plan. Only inlines variables whose assigned expression is a function call
- * (i.e., this rule ignores right-hand side constants and other variable references expressions
- * Postconditions/Examples:
- * All qualifying variables have been inlined.
- * Example (simplified):
- * Before plan:
- * select <- [$$1 < $$2 + $$0]
- * assign [$$2] <- [funcZ() + $$0]
- * assign [$$0, $$1] <- [funcX(), funcY()]
- * After plan:
- * select <- [funcY() < funcZ() + funcX() + funcX()]
- * assign [$$2] <- [funcZ() + funcX()]
- * assign [$$0, $$1] <- [funcX(), funcY()]
- */
-public class InlineVariablesRule implements IAlgebraicRewriteRule {
-
-    // Map of variables that could be replaced by their producing expression.
-    // Populated during the top-down sweep of the plan.
-    protected Map<LogicalVariable, ILogicalExpression> varAssignRhs = new HashMap<LogicalVariable, ILogicalExpression>();
-
-    // Visitor for replacing variable reference expressions with their originating expression.
-    protected InlineVariablesVisitor inlineVisitor = new InlineVariablesVisitor(varAssignRhs);
-
-    // Set of FunctionIdentifiers that we should not inline.
-    protected Set<FunctionIdentifier> doNotInlineFuncs = new HashSet<FunctionIdentifier>();
-
-    protected boolean hasRun = false;
-
-    @Override
-    public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) {
-        return false;
-    }
-
-    @Override
-    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
-        if (hasRun) {
-            return false;
-        }
-        if (context.checkIfInDontApplySet(this, opRef.getValue())) {
-            return false;
-        }
-        prepare(context);
-        boolean modified = inlineVariables(opRef, context);
-        if (performFinalAction()) {
-            modified = true;
-        }
-        hasRun = true;
-        return modified;
-    }
-
-    protected void prepare(IOptimizationContext context) {
-        varAssignRhs.clear();
-        inlineVisitor.setContext(context);
-    }
-
-    protected boolean performBottomUpAction(AbstractLogicalOperator op) throws AlgebricksException {
-        // Only inline variables in operators that can deal with arbitrary expressions.
-        if (!op.requiresVariableReferenceExpressions()) {
-            inlineVisitor.setOperator(op);
-            return op.acceptExpressionTransform(inlineVisitor);
-        }
-        return false;
-    }
-
-    protected boolean performFinalAction() throws AlgebricksException {
-        return false;
-    }
-
-    protected boolean inlineVariables(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
-            throws AlgebricksException {
-        AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
-
-        // Update mapping from variables to expressions during top-down traversal.
-        if (op.getOperatorTag() == LogicalOperatorTag.ASSIGN) {
-            AssignOperator assignOp = (AssignOperator) op;
-            List<LogicalVariable> vars = assignOp.getVariables();
-            List<Mutable<ILogicalExpression>> exprs = assignOp.getExpressions();
-            for (int i = 0; i < vars.size(); i++) {
-                ILogicalExpression expr = exprs.get(i).getValue();
-                // Ignore functions that are either in the doNotInline set or are non-functional               
-                if (expr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
-                    AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr;
-                    if (doNotInlineFuncs.contains(funcExpr.getFunctionIdentifier()) || !funcExpr.isFunctional()) {
-                        continue;
-                    }
-                }
-                varAssignRhs.put(vars.get(i), exprs.get(i).getValue());
-            }
-        }
-
-        // Descend into children removing projects on the way.
-        boolean modified = false;
-        for (Mutable<ILogicalOperator> inputOpRef : op.getInputs()) {
-            if (inlineVariables(inputOpRef, context)) {
-                modified = true;
-            }
-        }
-
-        // Descend into subplan
-        if (op.getOperatorTag() == LogicalOperatorTag.SUBPLAN) {
-            ALogicalPlanImpl subPlan = (ALogicalPlanImpl) ((SubplanOperator) op).getNestedPlans().get(0);
-            Mutable<ILogicalOperator> subPlanRootOpRef = subPlan.getRoots().get(0);
-            if (inlineVariables(subPlanRootOpRef, context)) {
-                modified = true;
-            }
-        }
-
-        if (performBottomUpAction(op)) {
-            modified = true;
-        }
-
-        if (modified) {
-            context.computeAndSetTypeEnvironmentForOperator(op);
-            context.addToDontApplySet(this, op);
-            // Re-enable rules that we may have already tried. They could be applicable now after inlining.
-            context.removeFromAlreadyCompared(opRef.getValue());
-        }
-
-        return modified;
-    }
-
-    protected class InlineVariablesVisitor implements ILogicalExpressionReferenceTransform {
-
-        private final Map<LogicalVariable, ILogicalExpression> varAssignRhs;
-        private final Set<LogicalVariable> liveVars = new HashSet<LogicalVariable>();
-        private final List<LogicalVariable> rhsUsedVars = new ArrayList<LogicalVariable>();
-        private ILogicalOperator op;
-        private IOptimizationContext context;
-        // If set, only replace this variable reference.
-        private LogicalVariable targetVar;
-
-        public InlineVariablesVisitor(Map<LogicalVariable, ILogicalExpression> varAssignRhs) {
-            this.varAssignRhs = varAssignRhs;
-        }
-
-        public void setTargetVariable(LogicalVariable targetVar) {
-            this.targetVar = targetVar;
-        }
-
-        public void setContext(IOptimizationContext context) {
-            this.context = context;
-        }
-
-        public void setOperator(ILogicalOperator op) throws AlgebricksException {
-            this.op = op;
-            liveVars.clear();
-        }
-
-        @Override
-        public boolean transform(Mutable<ILogicalExpression> exprRef) throws AlgebricksException {
-            ILogicalExpression e = exprRef.getValue();
-            switch (((AbstractLogicalExpression) e).getExpressionTag()) {
-                case VARIABLE: {
-                    LogicalVariable var = ((VariableReferenceExpression) e).getVariableReference();
-                    // Restrict replacement to targetVar if it has been set.
-                    if (targetVar != null && var != targetVar) {
-                        return false;
-                    }
-
-                    // Make sure has not been excluded from inlining.
-                    if (context.shouldNotBeInlined(var)) {
-                        return false;
-                    }
-
-                    ILogicalExpression rhs = varAssignRhs.get(var);
-                    if (rhs == null) {
-                        // Variable was not produced by an assign.
-                        return false;
-                    }
-
-                    // Make sure used variables from rhs are live.
-                    if (liveVars.isEmpty()) {
-                        VariableUtilities.getLiveVariables(op, liveVars);
-                    }
-                    rhsUsedVars.clear();
-                    rhs.getUsedVariables(rhsUsedVars);
-                    for (LogicalVariable rhsUsedVar : rhsUsedVars) {
-                        if (!liveVars.contains(rhsUsedVar)) {
-                            return false;
-                        }
-                    }
-
-                    // Replace variable reference with a clone of the rhs expr.
-                    exprRef.setValue(rhs.cloneExpression());
-                    return true;
-                }
-                case FUNCTION_CALL: {
-                    AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) e;
-                    boolean modified = false;
-                    for (Mutable<ILogicalExpression> arg : fce.getArguments()) {
-                        if (transform(arg)) {
-                            modified = true;
-                        }
-                    }
-                    return modified;
-                }
-                default: {
-                    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/InsertOuterJoinRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/InsertOuterJoinRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/InsertOuterJoinRule.java
deleted file mode 100644
index c5aee3c..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/InsertOuterJoinRule.java
+++ /dev/null
@@ -1,121 +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.Iterator;
-
-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.operators.logical.AbstractLogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator;
-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.OperatorPropertiesUtil;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-public class InsertOuterJoinRule 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 op0 = (AbstractLogicalOperator) opRef.getValue();
-        if (op0.getOperatorTag() != LogicalOperatorTag.SUBPLAN) {
-            return false;
-        }
-        SubplanOperator subplan = (SubplanOperator) op0;
-
-        Iterator<ILogicalPlan> plansIter = subplan.getNestedPlans().iterator();
-        ILogicalPlan p = null;
-        while (plansIter.hasNext()) {
-            p = plansIter.next();
-        }
-        if (p == null) {
-            return false;
-        }
-        if (p.getRoots().size() != 1) {
-            return false;
-        }
-        Mutable<ILogicalOperator> subplanRoot = p.getRoots().get(0);
-        AbstractLogicalOperator op1 = (AbstractLogicalOperator) subplanRoot.getValue();
-        Mutable<ILogicalOperator> opUnder = subplan.getInputs().get(0);
-
-        if (OperatorPropertiesUtil.isNullTest((AbstractLogicalOperator) opUnder.getValue())) {
-            return false;
-        }
-
-        switch (op1.getOperatorTag()) {
-            case INNERJOIN: {
-                InnerJoinOperator join = (InnerJoinOperator) op1;
-                Mutable<ILogicalOperator> leftRef = join.getInputs().get(0);
-                Mutable<ILogicalOperator> rightRef = join.getInputs().get(1);
-                Mutable<ILogicalOperator> ntsRef = getNtsAtEndOfPipeline(leftRef);
-                if (ntsRef == null) {
-                    ntsRef = getNtsAtEndOfPipeline(rightRef);
-                    if (ntsRef == null) {
-                        return false;
-                    } else {
-                        Mutable<ILogicalOperator> t = leftRef;
-                        leftRef = rightRef;
-                        rightRef = t;
-                    }
-                }
-                ntsRef.setValue(opUnder.getValue());
-                LeftOuterJoinOperator loj = new LeftOuterJoinOperator(join.getCondition());
-                loj.getInputs().add(leftRef);
-                loj.getInputs().add(rightRef);
-                opRef.setValue(loj);
-                context.computeAndSetTypeEnvironmentForOperator(loj);
-                return true;
-            }
-            case LEFTOUTERJOIN: {
-                LeftOuterJoinOperator join = (LeftOuterJoinOperator) op1;
-                Mutable<ILogicalOperator> leftRef = join.getInputs().get(0);
-                Mutable<ILogicalOperator> ntsRef = getNtsAtEndOfPipeline(leftRef);
-                if (ntsRef == null) {
-                    return false;
-                }
-                ntsRef.setValue(opUnder.getValue());
-                opRef.setValue(join);
-                context.computeAndSetTypeEnvironmentForOperator(join);
-                return true;
-            }
-            default: {
-                return false;
-            }
-        }
-    }
-
-    private Mutable<ILogicalOperator> getNtsAtEndOfPipeline(Mutable<ILogicalOperator> opRef) {
-        AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
-        if (op.getOperatorTag() == LogicalOperatorTag.NESTEDTUPLESOURCE) {
-            return opRef;
-        }
-        if (op.getInputs().size() != 1) {
-            return null;
-        }
-        return getNtsAtEndOfPipeline(op.getInputs().get(0));
-    }
-
-}

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/InsertProjectBeforeUnionRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/InsertProjectBeforeUnionRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/InsertProjectBeforeUnionRule.java
deleted file mode 100644
index 80b8815..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/InsertProjectBeforeUnionRule.java
+++ /dev/null
@@ -1,110 +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.common.utils.Triple;
-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.ProjectOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.UnionAllOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.visitors.VariableUtilities;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.physical.StreamProjectPOperator;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-public class InsertProjectBeforeUnionRule implements IAlgebraicRewriteRule {
-
-    @Override
-    public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
-            throws AlgebricksException {
-        return false;
-    }
-
-    /**
-     * When the input schema to WriteOperator is different from the output
-     * schema in terms of variable order, add a project operator to get the
-     * write order
-     */
-    @Override
-    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
-        AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
-        if (op.getOperatorTag() != LogicalOperatorTag.UNIONALL) {
-            return false;
-        }
-        UnionAllOperator opUnion = (UnionAllOperator) op;
-        List<Triple<LogicalVariable, LogicalVariable, LogicalVariable>> varMap = opUnion.getVariableMappings();
-        ArrayList<LogicalVariable> usedVariablesFromOne = new ArrayList<LogicalVariable>();
-        ArrayList<LogicalVariable> usedVariablesFromTwo = new ArrayList<LogicalVariable>();
-
-        for (Triple<LogicalVariable, LogicalVariable, LogicalVariable> triple : varMap) {
-            usedVariablesFromOne.add(triple.first);
-            usedVariablesFromTwo.add(triple.second);
-        }
-
-        ArrayList<LogicalVariable> inputSchemaOne = new ArrayList<LogicalVariable>();
-        VariableUtilities.getLiveVariables(opUnion.getInputs().get(0).getValue(), inputSchemaOne);
-
-        ArrayList<LogicalVariable> inputSchemaTwo = new ArrayList<LogicalVariable>();
-        VariableUtilities.getLiveVariables(opUnion.getInputs().get(1).getValue(), inputSchemaTwo);
-
-        boolean rewritten = false;
-        if (!isIdentical(usedVariablesFromOne, inputSchemaOne)) {
-            insertProjectOperator(opUnion, 0, usedVariablesFromOne, context);
-            rewritten = true;
-        }
-        if (!isIdentical(usedVariablesFromTwo, inputSchemaTwo)) {
-            insertProjectOperator(opUnion, 1, usedVariablesFromTwo, context);
-            rewritten = true;
-        }
-        return rewritten;
-    }
-
-    private void insertProjectOperator(UnionAllOperator opUnion, int branch, ArrayList<LogicalVariable> usedVariables,
-            IOptimizationContext context) throws AlgebricksException {
-        ProjectOperator projectOp = new ProjectOperator(usedVariables);
-        ILogicalOperator parentOp = opUnion.getInputs().get(branch).getValue();
-        projectOp.getInputs().add(new MutableObject<ILogicalOperator>(parentOp));
-        opUnion.getInputs().get(branch).setValue(projectOp);
-        projectOp.setPhysicalOperator(new StreamProjectPOperator());
-        context.computeAndSetTypeEnvironmentForOperator(projectOp);
-        context.computeAndSetTypeEnvironmentForOperator(parentOp);
-    }
-
-    private boolean isIdentical(List<LogicalVariable> finalSchema, List<LogicalVariable> inputSchema)
-            throws AlgebricksException {
-        int finalSchemaSize = finalSchema.size();
-        int inputSchemaSize = inputSchema.size();
-        if (finalSchemaSize != inputSchemaSize) {
-            return false;
-        }
-        for (int i = 0; i < finalSchemaSize; i++) {
-            LogicalVariable var1 = finalSchema.get(i);
-            LogicalVariable var2 = inputSchema.get(i);
-            if (!var1.equals(var2))
-                return false;
-        }
-        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/IntroHashPartitionMergeExchange.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/IntroHashPartitionMergeExchange.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/IntroHashPartitionMergeExchange.java
deleted file mode 100644
index 51f2025..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/IntroHashPartitionMergeExchange.java
+++ /dev/null
@@ -1,74 +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 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.PhysicalOperatorTag;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.physical.HashPartitionExchangePOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.physical.HashPartitionMergeExchangePOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.physical.SortMergeExchangePOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.properties.OrderColumn;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-public class IntroHashPartitionMergeExchange 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 op1 = (AbstractLogicalOperator) opRef.getValue();
-        if (op1.getPhysicalOperator() == null
-                || (op1.getPhysicalOperator().getOperatorTag() != PhysicalOperatorTag.HASH_PARTITION_EXCHANGE && op1
-                        .getPhysicalOperator().getOperatorTag() != PhysicalOperatorTag.HASH_PARTITION_MERGE_EXCHANGE)) {
-            return false;
-        }
-        AbstractLogicalOperator op2 = (AbstractLogicalOperator) op1.getInputs().get(0).getValue();
-        if (op2.getPhysicalOperator() == null
-                || op2.getPhysicalOperator().getOperatorTag() != PhysicalOperatorTag.SORT_MERGE_EXCHANGE) {
-            return false;
-        }
-        if (op1.getPhysicalOperator().getOperatorTag() == PhysicalOperatorTag.HASH_PARTITION_MERGE_EXCHANGE) {
-            // if it is a hash_partition_merge_exchange, the sort_merge_exchange can be simply removed
-            op1.getInputs().get(0).setValue(op2.getInputs().get(0).getValue());
-            op1.computeDeliveredPhysicalProperties(context);
-            return true;
-        }
-        HashPartitionExchangePOperator hpe = (HashPartitionExchangePOperator) op1.getPhysicalOperator();
-        SortMergeExchangePOperator sme = (SortMergeExchangePOperator) op2.getPhysicalOperator();
-        List<OrderColumn> ocList = new ArrayList<OrderColumn>();
-        for (OrderColumn oc : sme.getSortColumns()) {
-            ocList.add(oc);
-        }
-        HashPartitionMergeExchangePOperator hpme = new HashPartitionMergeExchangePOperator(ocList, hpe.getHashFields(),
-                hpe.getDomain());
-        op1.setPhysicalOperator(hpme);
-        op1.getInputs().get(0).setValue(op2.getInputs().get(0).getValue());
-        op1.computeDeliveredPhysicalProperties(context);
-        return true;
-    }
-
-}