asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject [13/51] [partial] incubator-asterixdb-hyracks git commit: Change folder structure for Java repackage
Date Tue, 25 Aug 2015 16:41:26 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/IntroJoinInsideSubplanRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/IntroJoinInsideSubplanRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/IntroJoinInsideSubplanRule.java
deleted file mode 100644
index 8929623..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/IntroJoinInsideSubplanRule.java
+++ /dev/null
@@ -1,102 +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.ListIterator;
-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.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.AbstractLogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.NestedTupleSourceOperator;
-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;
-
-public class IntroJoinInsideSubplanRule extends AbstractDecorrelationRule {
-
-    @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;
-
-        Mutable<ILogicalOperator> leftRef = subplan.getInputs().get(0);
-        if (((AbstractLogicalOperator) leftRef.getValue()).getOperatorTag() == LogicalOperatorTag.EMPTYTUPLESOURCE) {
-            return false;
-        }
-
-        ListIterator<ILogicalPlan> plansIter = subplan.getNestedPlans().listIterator();
-        ILogicalPlan p = null;
-        while (plansIter.hasNext()) {
-            p = plansIter.next();
-        }
-        if (p == null) {
-            return false;
-        }
-        if (p.getRoots().size() != 1) {
-            return false;
-        }
-        Mutable<ILogicalOperator> opRef1 = p.getRoots().get(0);
-
-        while (true) {
-            AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef1.getValue();
-            if (op1.getInputs().size() != 1) {
-                return false;
-            }
-            if (op1.getOperatorTag() == LogicalOperatorTag.SELECT) {
-                Mutable<ILogicalOperator> op2Ref = op1.getInputs().get(0);
-                AbstractLogicalOperator op2 = (AbstractLogicalOperator) op2Ref.getValue();
-                if (op2.getOperatorTag() != LogicalOperatorTag.SELECT && descOrSelfIsScanOrJoin(op2)) {
-                    Set<LogicalVariable> free2 = new HashSet<LogicalVariable>();
-                    OperatorPropertiesUtil.getFreeVariablesInSelfOrDesc(op2, free2);
-                    if (free2.isEmpty()) {
-                        Set<LogicalVariable> free1 = new HashSet<LogicalVariable>();
-                        OperatorPropertiesUtil.getFreeVariablesInSelfOrDesc(op1, free1);
-                        if (!free1.isEmpty()) {
-                            OperatorManipulationUtil.ntsToEts(op2Ref, context);
-                            NestedTupleSourceOperator nts = new NestedTupleSourceOperator(
-                                    new MutableObject<ILogicalOperator>(subplan));
-                            Mutable<ILogicalOperator> ntsRef = new MutableObject<ILogicalOperator>(nts);
-                            Mutable<ILogicalOperator> innerRef = new MutableObject<ILogicalOperator>(op2);
-                            InnerJoinOperator join = new InnerJoinOperator(new MutableObject<ILogicalExpression>(
-                                    ConstantExpression.TRUE), ntsRef, innerRef);
-                            op2Ref.setValue(join);
-                            context.computeAndSetTypeEnvironmentForOperator(nts);
-                            context.computeAndSetTypeEnvironmentForOperator(join);
-                            return true;
-                        }
-                    }
-                }
-            }
-            opRef1 = op1.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/IntroduceAggregateCombinerRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/IntroduceAggregateCombinerRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/IntroduceAggregateCombinerRule.java
deleted file mode 100644
index b0dbb1e..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/IntroduceAggregateCombinerRule.java
+++ /dev/null
@@ -1,57 +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.Set;
-
-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.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.AbstractLogicalOperator.ExecutionMode;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator;
-
-public class IntroduceAggregateCombinerRule 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;
-        }
-        context.addToDontApplySet(this, op);
-        if (op.getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
-            return false;
-        }
-        AggregateOperator aggOp = (AggregateOperator) op;
-        if (!aggOp.isGlobal() || aggOp.getExecutionMode() == ExecutionMode.LOCAL) {
-            return false;
-        }
-        Set<SimilarAggregatesInfo> toReplaceSet = new HashSet<SimilarAggregatesInfo>();
-        Pair<Boolean, Mutable<ILogicalOperator>> result = tryToPushAgg(aggOp, null, toReplaceSet, context);
-        if (!result.first || result.second == null) {
-            return false;
-        }
-        replaceOriginalAggFuncs(toReplaceSet);
-        context.computeAndSetTypeEnvironmentForOperator(aggOp);
-        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/IntroduceGroupByCombinerRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/IntroduceGroupByCombinerRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/IntroduceGroupByCombinerRule.java
deleted file mode 100644
index aa418ea..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/IntroduceGroupByCombinerRule.java
+++ /dev/null
@@ -1,31 +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 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.GroupByOperator;
-
-public class IntroduceGroupByCombinerRule extends AbstractIntroduceGroupByCombinerRule {
-
-    @Override
-    protected void processNullTest(IOptimizationContext context, GroupByOperator nestedGby,
-            List<LogicalVariable> aggregateVarsProducedByCombiner) {
-        /** The default introduce group-by combiner rule ignores null test, however a language implementor can decide their own semantics. */
-    }
-
-}
\ 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/IntroduceGroupByForSubplanRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/IntroduceGroupByForSubplanRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/IntroduceGroupByForSubplanRule.java
deleted file mode 100644
index a6d9ab0..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/IntroduceGroupByForSubplanRule.java
+++ /dev/null
@@ -1,323 +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.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-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.expressions.ConstantExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression;
-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.IFunctionInfo;
-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.AggregateOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AssignOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.DataSourceScanOperator;
-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.algebra.operators.logical.ProjectOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.SelectOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.SubplanOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.UnnestOperator;
-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.properties.FunctionalDependency;
-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.config.AlgebricksConfig;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-import edu.uci.ics.hyracks.algebricks.rewriter.util.PhysicalOptimizationsUtil;
-
-/**
- * The rule searches for SUBPLAN operator with a optional PROJECT operator and
- * an AGGREGATE followed by a join operator.
- *
- * <pre>
- * Before
- * 
- *   plan__parent
- *   SUBPLAN {
- *     PROJECT?
- *     AGGREGATE
- *     plan__nested_A
- *     INNER_JOIN | LEFT_OUTER_JOIN ($condition, $left, $right)
- *       plan__nested_B
- *   }
- *   plan__child
- * 
- *   where $condition does not equal a constant true.
- * 
- * After (This is a general application of the rule, specifics may vary based on the query plan.)
- * 
- *   plan__parent
- *   GROUP_BY {
- *     PROJECT?
- *     AGGREGATE
- *     plan__nested_A
- *     SELECT( algebricks:not( is_null( $right ) ) )
- *     NESTED_TUPLE_SOURCE
- *   }
- *   SUBPLAN {
- *     INNER_JOIN | LEFT_OUTER_JOIN ($condition, $left, $right)
- *       plan__nested_B
- *   }
- *   plan__child
- * </pre>
- *
- * @author prestonc
- */
-
-public class IntroduceGroupByForSubplanRule 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> botRef = subplanRoot;
-        AbstractLogicalOperator op2;
-        // Project is optional
-        if (op1.getOperatorTag() != LogicalOperatorTag.PROJECT) {
-            op2 = op1;
-        } else {
-            ProjectOperator project = (ProjectOperator) op1;
-            botRef = project.getInputs().get(0);
-            op2 = (AbstractLogicalOperator) botRef.getValue();
-        }
-        if (op2.getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
-            return false;
-        }
-        AggregateOperator aggregate = (AggregateOperator) op2;
-
-        Set<LogicalVariable> free = new HashSet<LogicalVariable>();
-        VariableUtilities.getUsedVariables(aggregate, free);
-
-        Mutable<ILogicalOperator> op3Ref = aggregate.getInputs().get(0);
-        AbstractLogicalOperator op3 = (AbstractLogicalOperator) op3Ref.getValue();
-
-        while (op3.getInputs().size() == 1) {
-            Set<LogicalVariable> prod = new HashSet<LogicalVariable>();
-            VariableUtilities.getProducedVariables(op3, prod);
-            free.removeAll(prod);
-            VariableUtilities.getUsedVariables(op3, free);
-            botRef = op3Ref;
-            op3Ref = op3.getInputs().get(0);
-            op3 = (AbstractLogicalOperator) op3Ref.getValue();
-        }
-
-        if (op3.getOperatorTag() != LogicalOperatorTag.INNERJOIN
-                && op3.getOperatorTag() != LogicalOperatorTag.LEFTOUTERJOIN) {
-            return false;
-        }
-        AbstractBinaryJoinOperator join = (AbstractBinaryJoinOperator) op3;
-        if (join.getCondition().getValue() == ConstantExpression.TRUE) {
-            return false;
-        }
-        VariableUtilities.getUsedVariables(join, free);
-
-        AbstractLogicalOperator b0 = (AbstractLogicalOperator) join.getInputs().get(0).getValue();
-        // see if there's an NTS at the end of the pipeline
-        NestedTupleSourceOperator outerNts = getNts(b0);
-        if (outerNts == null) {
-            AbstractLogicalOperator b1 = (AbstractLogicalOperator) join.getInputs().get(1).getValue();
-            outerNts = getNts(b1);
-            if (outerNts == null) {
-                return false;
-            }
-        }
-
-        Set<LogicalVariable> pkVars = computeGbyVars(outerNts, free, context);
-        if (pkVars == null || pkVars.size() < 1) {
-            // there is no non-trivial primary key, group-by keys are all live variables
-            ILogicalOperator subplanInput = subplan.getInputs().get(0).getValue();
-            pkVars = new HashSet<LogicalVariable>();
-            VariableUtilities.getLiveVariables(subplanInput, pkVars);
-        }
-        AlgebricksConfig.ALGEBRICKS_LOGGER.fine("Found FD for introducing group-by: " + pkVars);
-
-        Mutable<ILogicalOperator> rightRef = join.getInputs().get(1);
-        LogicalVariable testForNull = null;
-        AbstractLogicalOperator right = (AbstractLogicalOperator) rightRef.getValue();
-        switch (right.getOperatorTag()) {
-            case UNNEST: {
-                UnnestOperator innerUnnest = (UnnestOperator) right;
-                // Select [ $y != null ]
-                testForNull = innerUnnest.getVariable();
-                break;
-            }
-            case RUNNINGAGGREGATE: {
-                ILogicalOperator inputToRunningAggregate = right.getInputs().get(0).getValue();
-                Set<LogicalVariable> producedVars = new ListSet<LogicalVariable>();
-                VariableUtilities.getProducedVariables(inputToRunningAggregate, producedVars);
-                if (!producedVars.isEmpty()) {
-                    // Select [ $y != null ]
-                    testForNull = producedVars.iterator().next();
-                }
-                break;
-            }
-            case DATASOURCESCAN: {
-                DataSourceScanOperator innerScan = (DataSourceScanOperator) right;
-                // Select [ $y != null ]
-                if (innerScan.getVariables().size() == 1) {
-                    testForNull = innerScan.getVariables().get(0);
-                }
-                break;
-            }
-        }
-        if (testForNull == null) {
-            testForNull = context.newVar();
-            AssignOperator tmpAsgn = new AssignOperator(testForNull, new MutableObject<ILogicalExpression>(
-                    ConstantExpression.TRUE));
-            tmpAsgn.getInputs().add(new MutableObject<ILogicalOperator>(rightRef.getValue()));
-            rightRef.setValue(tmpAsgn);
-            context.computeAndSetTypeEnvironmentForOperator(tmpAsgn);
-        }
-
-        IFunctionInfo finfoEq = context.getMetadataProvider().lookupFunction(AlgebricksBuiltinFunctions.IS_NULL);
-        ILogicalExpression isNullTest = new ScalarFunctionCallExpression(finfoEq,
-                new MutableObject<ILogicalExpression>(new VariableReferenceExpression(testForNull)));
-        IFunctionInfo finfoNot = context.getMetadataProvider().lookupFunction(AlgebricksBuiltinFunctions.NOT);
-        ScalarFunctionCallExpression nonNullTest = new ScalarFunctionCallExpression(finfoNot,
-                new MutableObject<ILogicalExpression>(isNullTest));
-        SelectOperator selectNonNull = new SelectOperator(new MutableObject<ILogicalExpression>(nonNullTest), false,
-                null);
-        GroupByOperator g = new GroupByOperator();
-        Mutable<ILogicalOperator> newSubplanRef = new MutableObject<ILogicalOperator>(subplan);
-        NestedTupleSourceOperator nts = new NestedTupleSourceOperator(new MutableObject<ILogicalOperator>(g));
-        opRef.setValue(g);
-        selectNonNull.getInputs().add(new MutableObject<ILogicalOperator>(nts));
-
-        List<Mutable<ILogicalOperator>> prodInpList = botRef.getValue().getInputs();
-        prodInpList.clear();
-        prodInpList.add(new MutableObject<ILogicalOperator>(selectNonNull));
-
-        ILogicalPlan gPlan = new ALogicalPlanImpl(new MutableObject<ILogicalOperator>(subplanRoot.getValue()));
-        g.getNestedPlans().add(gPlan);
-        subplanRoot.setValue(op3Ref.getValue());
-        g.getInputs().add(newSubplanRef);
-
-        HashSet<LogicalVariable> underVars = new HashSet<LogicalVariable>();
-        VariableUtilities.getLiveVariables(subplan.getInputs().get(0).getValue(), underVars);
-        underVars.removeAll(pkVars);
-        Map<LogicalVariable, LogicalVariable> mappedVars = buildVarExprList(pkVars, context, g, g.getGroupByList());
-        context.updatePrimaryKeys(mappedVars);
-        for (LogicalVariable uv : underVars) {
-            g.getDecorList().add(
-                    new Pair<LogicalVariable, Mutable<ILogicalExpression>>(null, new MutableObject<ILogicalExpression>(
-                            new VariableReferenceExpression(uv))));
-        }
-        OperatorPropertiesUtil.typeOpRec(subplanRoot, context);
-        OperatorPropertiesUtil.typeOpRec(gPlan.getRoots().get(0), context);
-        context.computeAndSetTypeEnvironmentForOperator(g);
-        return true;
-    }
-
-    private NestedTupleSourceOperator getNts(AbstractLogicalOperator op) {
-        AbstractLogicalOperator alo = op;
-        do {
-            if (alo.getOperatorTag() == LogicalOperatorTag.NESTEDTUPLESOURCE) {
-                return (NestedTupleSourceOperator) alo;
-            }
-            if (alo.getInputs().size() != 1) {
-                return null;
-            }
-            alo = (AbstractLogicalOperator) alo.getInputs().get(0).getValue();
-        } while (true);
-    }
-
-    protected Set<LogicalVariable> computeGbyVars(AbstractLogicalOperator op, Set<LogicalVariable> freeVars,
-            IOptimizationContext context) throws AlgebricksException {
-        PhysicalOptimizationsUtil.computeFDsAndEquivalenceClasses(op, context);
-        List<FunctionalDependency> fdList = context.getFDList(op);
-        if (fdList == null) {
-            return null;
-        }
-        // check if any of the FDs is a key
-        List<LogicalVariable> all = new ArrayList<LogicalVariable>();
-        VariableUtilities.getLiveVariables(op, all);
-        all.retainAll(freeVars);
-        for (FunctionalDependency fd : fdList) {
-            if (fd.getTail().containsAll(all)) {
-                return new HashSet<LogicalVariable>(fd.getHead());
-            }
-        }
-        return null;
-    }
-
-    private Map<LogicalVariable, LogicalVariable> buildVarExprList(Collection<LogicalVariable> vars,
-            IOptimizationContext context, GroupByOperator g,
-            List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> outVeList) throws AlgebricksException {
-        Map<LogicalVariable, LogicalVariable> m = new HashMap<LogicalVariable, LogicalVariable>();
-        for (LogicalVariable ov : vars) {
-            LogicalVariable newVar = context.newVar();
-            ILogicalExpression varExpr = new VariableReferenceExpression(newVar);
-            outVeList.add(new Pair<LogicalVariable, Mutable<ILogicalExpression>>(ov,
-                    new MutableObject<ILogicalExpression>(varExpr)));
-            for (ILogicalPlan p : g.getNestedPlans()) {
-                for (Mutable<ILogicalOperator> r : p.getRoots()) {
-                    OperatorManipulationUtil.substituteVarRec((AbstractLogicalOperator) r.getValue(), ov, newVar, true,
-                            context);
-                }
-            }
-            AbstractLogicalOperator opUnder = (AbstractLogicalOperator) g.getInputs().get(0).getValue();
-            OperatorManipulationUtil.substituteVarRec(opUnder, ov, newVar, true, context);
-            m.put(ov, newVar);
-        }
-        return m;
-    }
-}

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/IntroduceProjectsRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/IntroduceProjectsRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/IntroduceProjectsRule.java
deleted file mode 100644
index 3c96bc2..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/IntroduceProjectsRule.java
+++ /dev/null
@@ -1,171 +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.Collections;
-import java.util.HashSet;
-import java.util.List;
-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.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.rewriter.base.IAlgebraicRewriteRule;
-
-/**
- * Projects away unused variables at the earliest possible point.
- * Does a full DFS sweep of the plan adding ProjectOperators in the bottom-up pass.
- * Also, removes projects that have become useless.
- * TODO: This rule 'recklessly' adds as many projects as possible, but there is no guarantee
- * that the overall cost of the plan is reduced since project operators also add a cost.
- */
-public class IntroduceProjectsRule implements IAlgebraicRewriteRule {
-
-    private final Set<LogicalVariable> usedVars = new HashSet<LogicalVariable>();
-    private final Set<LogicalVariable> liveVars = new HashSet<LogicalVariable>();
-    private final Set<LogicalVariable> producedVars = new HashSet<LogicalVariable>();
-    private final List<LogicalVariable> projectVars = new ArrayList<LogicalVariable>();
-    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;
-        }
-        hasRun = true;
-        return introduceProjects(null, -1, opRef, Collections.<LogicalVariable> emptySet(), context);
-    }
-
-    protected boolean introduceProjects(AbstractLogicalOperator parentOp, int parentInputIndex,
-            Mutable<ILogicalOperator> opRef, Set<LogicalVariable> parentUsedVars, IOptimizationContext context)
-            throws AlgebricksException {
-        AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
-        boolean modified = false;
-
-        usedVars.clear();
-        VariableUtilities.getUsedVariables(op, usedVars);
-
-        // In the top-down pass, maintain a set of variables that are used in op and all its parents.
-        HashSet<LogicalVariable> parentsUsedVars = new HashSet<LogicalVariable>();
-        parentsUsedVars.addAll(parentUsedVars);
-        parentsUsedVars.addAll(usedVars);
-
-        // Descend into children.        
-        for (int i = 0; i < op.getInputs().size(); i++) {
-            Mutable<ILogicalOperator> inputOpRef = op.getInputs().get(i);
-            if (introduceProjects(op, i, inputOpRef, parentsUsedVars, context)) {
-                modified = true;
-            }
-        }
-
-        if (modified) {
-            context.computeAndSetTypeEnvironmentForOperator(op);
-        }
-        // In the bottom-up pass, determine which live variables are not used by op's parents.
-        // Such variables are be projected away.
-        liveVars.clear();
-        VariableUtilities.getLiveVariables(op, liveVars);
-        producedVars.clear();
-        VariableUtilities.getProducedVariables(op, producedVars);
-        liveVars.removeAll(producedVars);
-
-        projectVars.clear();
-        for (LogicalVariable liveVar : liveVars) {
-            if (parentsUsedVars.contains(liveVar)) {
-                projectVars.add(liveVar);
-            }
-        }
-
-        // Some of the variables that are live at this op are not used above.
-        if (projectVars.size() != liveVars.size()) {
-            // Add a project operator under each of op's qualifying input branches.
-            for (int i = 0; i < op.getInputs().size(); i++) {
-                ILogicalOperator childOp = op.getInputs().get(i).getValue();
-                liveVars.clear();
-                VariableUtilities.getLiveVariables(childOp, liveVars);
-                List<LogicalVariable> vars = new ArrayList<LogicalVariable>();
-                vars.addAll(projectVars);
-                // Only retain those variables that are live in the i-th input branch.
-                vars.retainAll(liveVars);
-                if (vars.size() != liveVars.size()) {
-                    ProjectOperator projectOp = new ProjectOperator(vars);
-                    projectOp.getInputs().add(new MutableObject<ILogicalOperator>(childOp));
-                    op.getInputs().get(i).setValue(projectOp);
-                    context.computeAndSetTypeEnvironmentForOperator(projectOp);
-                    modified = true;
-                }
-            }
-        } else if (op.getOperatorTag() == LogicalOperatorTag.PROJECT) {
-            // Check if the existing project has become useless.
-            liveVars.clear();
-            VariableUtilities.getLiveVariables(op.getInputs().get(0).getValue(), liveVars);
-            ProjectOperator projectOp = (ProjectOperator) op;
-            List<LogicalVariable> projectVars = projectOp.getVariables();
-            if (liveVars.size() == projectVars.size() && liveVars.containsAll(projectVars)) {
-                boolean eliminateProject = true;
-                // For UnionAll the variables must also be in exactly the correct order.
-                if (parentOp.getOperatorTag() == LogicalOperatorTag.UNIONALL) {
-                    eliminateProject = canEliminateProjectBelowUnion((UnionAllOperator) parentOp, projectOp,
-                            parentInputIndex);
-                }
-                if (eliminateProject) {
-                    // The existing project has become useless. Remove it.
-                    parentOp.getInputs().get(parentInputIndex).setValue(op.getInputs().get(0).getValue());
-                }
-            }
-        }
-
-        if (modified) {
-            context.computeAndSetTypeEnvironmentForOperator(op);
-        }
-        return modified;
-    }
-    
-    private boolean canEliminateProjectBelowUnion(UnionAllOperator unionOp, ProjectOperator projectOp,
-            int unionInputIndex) throws AlgebricksException {
-        List<LogicalVariable> orderedLiveVars = new ArrayList<LogicalVariable>();
-        VariableUtilities.getLiveVariables(projectOp.getInputs().get(0).getValue(), orderedLiveVars);
-        int numVars = orderedLiveVars.size();
-        for (int i = 0; i < numVars; i++) {
-            Triple<LogicalVariable, LogicalVariable, LogicalVariable> varTriple = unionOp.getVariableMappings().get(i);
-            if (unionInputIndex == 0) {
-                if (varTriple.first != orderedLiveVars.get(i)) {
-                    return false;
-                }
-            } else {
-                if (varTriple.second != orderedLiveVars.get(i)) {
-                    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/IsolateHyracksOperatorsRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/IsolateHyracksOperatorsRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/IsolateHyracksOperatorsRule.java
deleted file mode 100644
index 71af64b..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/IsolateHyracksOperatorsRule.java
+++ /dev/null
@@ -1,140 +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.ILogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.IOptimizationContext;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.IPhysicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
-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.logical.AbstractLogicalOperator.ExecutionMode;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ExchangeOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.physical.OneToOneExchangePOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.util.OperatorPropertiesUtil;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-public class IsolateHyracksOperatorsRule implements IAlgebraicRewriteRule {
-
-    private final PhysicalOperatorTag[] operatorsBelowWhichJobGenIsDisabled;
-
-    public IsolateHyracksOperatorsRule(PhysicalOperatorTag[] operatorsBelowWhichJobGenIsDisabled) {
-        this.operatorsBelowWhichJobGenIsDisabled = operatorsBelowWhichJobGenIsDisabled;
-    }
-
-    @Override
-    public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
-            throws AlgebricksException {
-        AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
-        IPhysicalOperator pt = op.getPhysicalOperator();
-
-        if (pt == null || op.getOperatorTag() == LogicalOperatorTag.EXCHANGE) {
-            return false;
-        }
-        if (!pt.isMicroOperator()) {
-            return testIfExchangeBelow(opRef, context);
-        } else {
-            return testIfExchangeAbove(opRef, context);
-        }
-    }
-
-    @Override
-    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) {
-        return false;
-    }
-
-    private boolean testIfExchangeBelow(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
-            throws AlgebricksException {
-        AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
-        boolean exchInserted = false;
-
-        for (Mutable<ILogicalOperator> i : op.getInputs()) {
-            AbstractLogicalOperator c = (AbstractLogicalOperator) i.getValue();
-            if (c.getOperatorTag() != LogicalOperatorTag.EXCHANGE) {
-                if (c.getPhysicalOperator() == null) {
-                    return false;
-                }
-                insertOneToOneExchange(i, context);
-                exchInserted = true;
-            }
-        }
-        IPhysicalOperator pt = op.getPhysicalOperator();
-        if (pt.isJobGenDisabledBelowMe() || arrayContains(operatorsBelowWhichJobGenIsDisabled, pt.getOperatorTag())) {
-            for (Mutable<ILogicalOperator> i : op.getInputs()) {
-                disableJobGenRec(i.getValue());
-            }
-        }
-        return exchInserted;
-    }
-
-    private void disableJobGenRec(ILogicalOperator operator) {
-        AbstractLogicalOperator op = (AbstractLogicalOperator) operator;
-        op.disableJobGen();
-        for (Mutable<ILogicalOperator> i : op.getInputs()) {
-            disableJobGenRec(i.getValue());
-        }
-    }
-
-    private boolean testIfExchangeAbove(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
-            throws AlgebricksException {
-        AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
-        if (op.getOperatorTag() == LogicalOperatorTag.EXCHANGE) {
-            return false;
-        }
-        boolean exchInserted = false;
-        for (Mutable<ILogicalOperator> i : op.getInputs()) {
-            AbstractLogicalOperator c = (AbstractLogicalOperator) i.getValue();
-            IPhysicalOperator cpop = c.getPhysicalOperator();
-            if (c.getOperatorTag() == LogicalOperatorTag.EXCHANGE || cpop == null) {
-                continue;
-            }
-            if (!cpop.isMicroOperator()) {
-                insertOneToOneExchange(i, context);
-                exchInserted = true;
-            }
-        }
-        return exchInserted;
-    }
-
-    private final static <T> boolean arrayContains(T[] array, T tag) {
-        for (int i = 0; i < array.length; i++) {
-            if (array[i] == tag) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    private final static void insertOneToOneExchange(Mutable<ILogicalOperator> i, IOptimizationContext context)
-            throws AlgebricksException {
-        ExchangeOperator e = new ExchangeOperator();
-        e.setPhysicalOperator(new OneToOneExchangePOperator());
-        ILogicalOperator inOp = i.getValue();
-
-        e.getInputs().add(new MutableObject<ILogicalOperator>(inOp));
-        i.setValue(e);
-        // e.recomputeSchema();
-        OperatorPropertiesUtil.computeSchemaAndPropertiesRecIfNull(e, context);
-        ExecutionMode em = ((AbstractLogicalOperator) inOp).getExecutionMode();
-        e.setExecutionMode(em);
-        e.computeDeliveredPhysicalProperties(context);
-        context.computeAndSetTypeEnvironmentForOperator(e);
-    }
-
-}

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/MoveFreeVariableOperatorOutOfSubplanRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/MoveFreeVariableOperatorOutOfSubplanRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/MoveFreeVariableOperatorOutOfSubplanRule.java
deleted file mode 100644
index 5867abd..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/MoveFreeVariableOperatorOutOfSubplanRule.java
+++ /dev/null
@@ -1,183 +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.ListIterator;
-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.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.SubplanOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.visitors.VariableUtilities;
-import edu.uci.ics.hyracks.algebricks.core.algebra.util.OperatorPropertiesUtil;
-import edu.uci.ics.hyracks.algebricks.rewriter.rules.AbstractDecorrelationRule;
-
-/**
- * The rule searches for operators that can be moved outside the subplan.
- *
- * <pre>
- * Before
- * 
- *   %PARENT_PLAN
- *   SUBPLAN{
- *     %NESTED_OPERATORS_B+
- *     ASSIGN || %SUBPLAN
- *     %NESTED_OPERATORS_A*
- *     NESTEDTUPLESOURCE
- *   }
- *   %CHILD_PLAN
- * 
- *   where
- *     %SUBPLAN has one nested plan with a root AGGREGATE operator.
- * 
- * After
- * 
- *   %PARENT_PLAN
- *   SUBPLAN{
- *     %NESTED_OPERATORS_B+
- *     %NESTED_OPERATORS_A*
- *     NESTEDTUPLESOURCE
- *   }
- *   ASSIGN || %SUBPLAN
- *   %CHILD_PLAN
- * </pre>
- */
-public class MoveFreeVariableOperatorOutOfSubplanRule extends AbstractDecorrelationRule {
-
-    @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;
-
-        Mutable<ILogicalOperator> leftRef = subplan.getInputs().get(0);
-        if (((AbstractLogicalOperator) leftRef.getValue()).getOperatorTag() == LogicalOperatorTag.EMPTYTUPLESOURCE) {
-            return false;
-        }
-
-        ListIterator<ILogicalPlan> plansIter = subplan.getNestedPlans().listIterator();
-        ILogicalPlan p = null;
-        while (plansIter.hasNext()) {
-            p = plansIter.next();
-        }
-        if (p == null) {
-            return false;
-        }
-        if (p.getRoots().size() != 1) {
-            return false;
-        }
-        Mutable<ILogicalOperator> opRef1 = p.getRoots().get(0);
-
-        //The root operator will not be movable. Start with the second op
-        AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef1.getValue();
-        if (op1.getInputs().size() != 1) {
-            return false;
-        }
-        Mutable<ILogicalOperator> op2Ref = op1.getInputs().get(0);
-
-        //Get all variables that come from outside of the loop
-        Set<LogicalVariable> free = new HashSet<LogicalVariable>();
-        OperatorPropertiesUtil.getFreeVariablesInSelfOrDesc(op1, free);
-
-        while (op2Ref != null) {
-            //Get the operator that we want to look at
-            AbstractLogicalOperator op2 = (AbstractLogicalOperator) op2Ref.getValue();
-
-            //Make sure we are looking at subplan with a scan/join
-            if (op2.getInputs().size() != 1 || !descOrSelfIsScanOrJoin(op2)) {
-                return false;
-            }
-            boolean notApplicable = false;
-
-            //Get its used variables
-            Set<LogicalVariable> used = new HashSet<LogicalVariable>();
-
-            //not movable if the operator is not an assign or subplan
-            //Might be helpful in the future for other operations in the future
-            if (movableOperator(op2.getOperatorTag())) {
-                if (op2.getOperatorTag() == LogicalOperatorTag.ASSIGN) {
-                    VariableUtilities.getUsedVariables(op2, used);
-                } else if (op2.getOperatorTag() == LogicalOperatorTag.SUBPLAN) {
-                    // Nested plan must have an aggregate root.
-                    ListIterator<ILogicalPlan> subplansIter = ((SubplanOperator) op2).getNestedPlans().listIterator();
-                    ILogicalPlan plan = null;
-                    while (subplansIter.hasNext()) {
-                        plan = subplansIter.next();
-                    }
-                    if (plan == null) {
-                        return false;
-                    }
-                    if (plan.getRoots().size() != 1) {
-                        return false;
-                    }
-                    ILogicalOperator op3 = plan.getRoots().get(0).getValue();
-                    if (op3.getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
-                        return false;
-                    }
-                    // Used variables do not include ones created in the subplan.
-                    VariableUtilities.getUsedVariables(op2, used);
-                    Set<LogicalVariable> subplanProducedAndDown = new HashSet<LogicalVariable>();
-                    VariableUtilities.getProducedVariablesInDescendantsAndSelf(op3, subplanProducedAndDown);
-                    used.removeAll(subplanProducedAndDown);
-                } else {
-                    notApplicable = true;
-                }
-            } else {
-                notApplicable = true;
-            }
-
-            //Make sure that all of its used variables come from outside
-            for (LogicalVariable var : used) {
-                if (!free.contains(var)) {
-                    notApplicable = true;
-                }
-            }
-
-            if (notApplicable) {
-                op2Ref = op2.getInputs().get(0);
-            } else {
-                //Make the input of op2 be the input of op1
-                op2Ref.setValue(op2.getInputs().get(0).getValue());
-
-                //Make the outside of the subplan the input of op2
-                Mutable<ILogicalOperator> outsideRef = op2.getInputs().get(0);
-                outsideRef.setValue(op0.getInputs().get(0).getValue());
-
-                //Make op2 the input of the subplan
-                Mutable<ILogicalOperator> op2OutsideRef = op0.getInputs().get(0);
-                op2OutsideRef.setValue(op2);
-
-                return true;
-            }
-
-        }
-        return false;
-    }
-
-    protected boolean movableOperator(LogicalOperatorTag operatorTag) {
-        return (operatorTag == LogicalOperatorTag.ASSIGN || operatorTag == LogicalOperatorTag.SUBPLAN);
-    }
-}
\ 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/NestedSubplanToJoinRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/NestedSubplanToJoinRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/NestedSubplanToJoinRule.java
deleted file mode 100644
index 6484202..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/NestedSubplanToJoinRule.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.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-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.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.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.LeftOuterJoinOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.util.OperatorPropertiesUtil;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-/**
- * replace Subplan operators with nested loop joins where the join condition is true, if the Subplan
- * does not contain free variables (does not have correlations to the input stream).
- * 
- * @author yingyib
- */
-public class NestedSubplanToJoinRule 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 {
-        if (context.checkIfInDontApplySet(this, opRef.getValue()))
-            return false;
-        context.addToDontApplySet(this, opRef.getValue());
-
-        ILogicalOperator op1 = opRef.getValue();
-        if (op1.getInputs().size() == 0) {
-            return false;
-        }
-
-        boolean rewritten = false;
-        for (int index = 0; index < op1.getInputs().size(); index++) {
-            AbstractLogicalOperator child = (AbstractLogicalOperator) op1.getInputs().get(index).getValue();
-            if (child.getOperatorTag() != LogicalOperatorTag.SUBPLAN) {
-                continue;
-            }
-
-            AbstractOperatorWithNestedPlans subplan = (AbstractOperatorWithNestedPlans) child;
-            Set<LogicalVariable> freeVars = new HashSet<LogicalVariable>();
-            OperatorPropertiesUtil.getFreeVariablesInSubplans(subplan, freeVars);
-            if (!freeVars.isEmpty()) {
-                /**
-                 * the subplan is correlated with the outer plan, other rules can deal with it
-                 */
-                continue;
-            }
-
-            /** get the input operator of the subplan operator */
-            ILogicalOperator subplanInput = subplan.getInputs().get(0).getValue();
-            AbstractLogicalOperator subplanInputOp = (AbstractLogicalOperator) subplanInput;
-
-            /** If the other join branch is a trivial plan, do not do the rewriting. */
-            if (subplanInputOp.getOperatorTag() == LogicalOperatorTag.EMPTYTUPLESOURCE) {
-                continue;
-            }
-
-            /** get all nested top operators */
-            List<ILogicalPlan> nestedPlans = subplan.getNestedPlans();
-            List<Mutable<ILogicalOperator>> nestedRoots = new ArrayList<Mutable<ILogicalOperator>>();
-            for (ILogicalPlan nestedPlan : nestedPlans) {
-                nestedRoots.addAll(nestedPlan.getRoots());
-            }
-            if (nestedRoots.size() == 0) {
-                /** there is no nested top operators */
-                continue;
-            }
-
-            /** expend the input and roots into a DAG of nested loop joins */
-            Mutable<ILogicalExpression> expr = new MutableObject<ILogicalExpression>(ConstantExpression.TRUE);
-            Mutable<ILogicalOperator> nestedRootRef = nestedRoots.get(0);
-            ILogicalOperator join = new LeftOuterJoinOperator(expr, new MutableObject<ILogicalOperator>(subplanInput),
-                    nestedRootRef);
-
-            /** rewrite the nested tuple source to be empty tuple source */
-            rewriteNestedTupleSource(nestedRootRef);
-
-            for (int i = 1; i < nestedRoots.size(); i++) {
-                join = new LeftOuterJoinOperator(expr, new MutableObject<ILogicalOperator>(join), nestedRoots.get(i));
-            }
-            op1.getInputs().get(index).setValue(join);
-            context.computeAndSetTypeEnvironmentForOperator(join);
-            rewritten = true;
-        }
-        return rewritten;
-    }
-
-    /**
-     * rewrite NestedTupleSource operators to EmptyTupleSource operators
-     * 
-     * @param nestedRootRef
-     */
-    private void rewriteNestedTupleSource(Mutable<ILogicalOperator> nestedRootRef) {
-        AbstractLogicalOperator nestedRoot = (AbstractLogicalOperator) nestedRootRef.getValue();
-        if (nestedRoot.getOperatorTag() == LogicalOperatorTag.NESTEDTUPLESOURCE) {
-            nestedRootRef.setValue(new EmptyTupleSourceOperator());
-        }
-        List<Mutable<ILogicalOperator>> inputs = nestedRoot.getInputs();
-        for (Mutable<ILogicalOperator> input : inputs) {
-            rewriteNestedTupleSource(input);
-        }
-    }
-}

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/PullSelectOutOfEqJoin.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/PullSelectOutOfEqJoin.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/PullSelectOutOfEqJoin.java
deleted file mode 100644
index b268e77..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/PullSelectOutOfEqJoin.java
+++ /dev/null
@@ -1,114 +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.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.FunctionIdentifier;
-import edu.uci.ics.hyracks.algebricks.core.algebra.functions.IFunctionInfo;
-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.SelectOperator;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-public class PullSelectOutOfEqJoin 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) {
-            return false;
-        }
-        AbstractBinaryJoinOperator join = (AbstractBinaryJoinOperator) op;
-
-        ILogicalExpression expr = join.getCondition().getValue();
-        if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
-            return false;
-        }
-        AbstractFunctionCallExpression fexp = (AbstractFunctionCallExpression) expr;
-        FunctionIdentifier fi = fexp.getFunctionIdentifier();
-        if (!fi.equals(AlgebricksBuiltinFunctions.AND)) {
-            return false;
-        }
-        List<Mutable<ILogicalExpression>> eqVarVarComps = new ArrayList<Mutable<ILogicalExpression>>();
-        List<Mutable<ILogicalExpression>> otherPredicates = new ArrayList<Mutable<ILogicalExpression>>();
-        for (Mutable<ILogicalExpression> arg : fexp.getArguments()) {
-            if (isEqVarVar(arg.getValue())) {
-                eqVarVarComps.add(arg);
-            } else {
-                otherPredicates.add(arg);
-            }
-        }
-        if (eqVarVarComps.isEmpty() || otherPredicates.isEmpty()) {
-            return false;
-        }
-        // pull up
-        ILogicalExpression pulledCond = makeCondition(otherPredicates, context);
-        SelectOperator select = new SelectOperator(new MutableObject<ILogicalExpression>(pulledCond), false, null);
-        ILogicalExpression newJoinCond = makeCondition(eqVarVarComps, context);
-        join.getCondition().setValue(newJoinCond);
-        select.getInputs().add(new MutableObject<ILogicalOperator>(join));
-        opRef.setValue(select);
-        context.computeAndSetTypeEnvironmentForOperator(select);
-        return true;
-    }
-
-    private ILogicalExpression makeCondition(List<Mutable<ILogicalExpression>> predList, IOptimizationContext context) {
-        if (predList.size() > 1) {
-            IFunctionInfo finfo = context.getMetadataProvider().lookupFunction(AlgebricksBuiltinFunctions.AND);
-            return new ScalarFunctionCallExpression(finfo, predList);
-        } else {
-            return predList.get(0).getValue();
-        }
-    }
-
-    private boolean isEqVarVar(ILogicalExpression expr) {
-        if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
-            return false;
-        }
-        AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expr;
-        if (!f.getFunctionIdentifier().equals(AlgebricksBuiltinFunctions.EQ)) {
-            return false;
-        }
-        ILogicalExpression e1 = f.getArguments().get(0).getValue();
-        if (e1.getExpressionTag() != LogicalExpressionTag.VARIABLE) {
-            return false;
-        } else {
-            ILogicalExpression e2 = f.getArguments().get(1).getValue();
-            return e2.getExpressionTag() == LogicalExpressionTag.VARIABLE;
-        }
-    }
-
-}

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/PushAssignBelowUnionAllRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/PushAssignBelowUnionAllRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/PushAssignBelowUnionAllRule.java
deleted file mode 100644
index 418ee36..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/PushAssignBelowUnionAllRule.java
+++ /dev/null
@@ -1,165 +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 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.Triple;
-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.operators.logical.AbstractLogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AssignOperator;
-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.rewriter.base.IAlgebraicRewriteRule;
-
-/**
- * Pushes an AssignOperator below a UnionAll operator by creating an new AssignOperator below each of
- * the UnionAllOperator's branches with appropriate variable replacements.
- * This rule can help to enable other rules that are difficult to fire across a UnionAllOperator,
- * for example, eliminating common sub-expressions.
- * Example:
- * Before plan:
- * ...
- * assign [$$20, $$21] <- [funcA($$3), funcB($$6)]
- * union ($$1, $$2, $$3) ($$4, $$5, $$6)
- * union_branch_0
- * ...
- * union_branch_1
- * ...
- * After plan:
- * ...
- * union ($$1, $$2, $$3) ($$4, $$5, $$6) ($$22, $$24, $$20) ($$23, $$25, $$21)
- * assign [$$22, $$23] <- [funcA($$1), funcB($$4)]
- * union_branch_0
- * ...
- * assign [$$24, $$25] <- [funcA($$2), funcB($$5)]
- * union_branch_1
- * ...
- */
-public class PushAssignBelowUnionAllRule 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.hasInputs()) {
-            return false;
-        }
-
-        boolean modified = false;
-        for (int i = 0; i < op.getInputs().size(); i++) {
-            AbstractLogicalOperator childOp = (AbstractLogicalOperator) op.getInputs().get(i).getValue();
-            if (childOp.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
-                continue;
-            }
-            AssignOperator assignOp = (AssignOperator) childOp;
-            for (Mutable<ILogicalExpression> expr : assignOp.getExpressions()) {
-                if (!expr.getValue().isFunctional()) {
-                    return false;
-                }
-            }
-
-            AbstractLogicalOperator childOfChildOp = (AbstractLogicalOperator) assignOp.getInputs().get(0).getValue();
-            if (childOfChildOp.getOperatorTag() != LogicalOperatorTag.UNIONALL) {
-                continue;
-            }
-            UnionAllOperator unionOp = (UnionAllOperator) childOfChildOp;
-
-            Set<LogicalVariable> assignUsedVars = new HashSet<LogicalVariable>();
-            VariableUtilities.getUsedVariables(assignOp, assignUsedVars);
-
-            List<LogicalVariable> assignVars = assignOp.getVariables();
-
-            AssignOperator[] newAssignOps = new AssignOperator[2];
-            for (int j = 0; j < unionOp.getInputs().size(); j++) {
-                newAssignOps[j] = createAssignBelowUnionAllBranch(unionOp, j, assignOp, assignUsedVars, context);
-            }
-            // Add original assign variables to the union variable mappings.
-            for (int j = 0; j < assignVars.size(); j++) {
-                LogicalVariable first = newAssignOps[0].getVariables().get(j);
-                LogicalVariable second = newAssignOps[1].getVariables().get(j);
-                Triple<LogicalVariable, LogicalVariable, LogicalVariable> varMapping = new Triple<LogicalVariable, LogicalVariable, LogicalVariable>(
-                        first, second, assignVars.get(j));
-                unionOp.getVariableMappings().add(varMapping);
-            }
-            context.computeAndSetTypeEnvironmentForOperator(unionOp);
-
-            // Remove original assign operator.
-            op.getInputs().set(i, assignOp.getInputs().get(0));
-            context.computeAndSetTypeEnvironmentForOperator(op);
-            modified = true;
-        }
-
-        return modified;
-    }
-
-    private AssignOperator createAssignBelowUnionAllBranch(UnionAllOperator unionOp, int inputIndex,
-            AssignOperator originalAssignOp, Set<LogicalVariable> assignUsedVars, IOptimizationContext context)
-            throws AlgebricksException {
-        AssignOperator newAssignOp = cloneAssignOperator(originalAssignOp, context);
-        newAssignOp.getInputs()
-                .add(new MutableObject<ILogicalOperator>(unionOp.getInputs().get(inputIndex).getValue()));
-        context.computeAndSetTypeEnvironmentForOperator(newAssignOp);
-        unionOp.getInputs().get(inputIndex).setValue(newAssignOp);
-        int numVarMappings = unionOp.getVariableMappings().size();
-        for (int i = 0; i < numVarMappings; i++) {
-            Triple<LogicalVariable, LogicalVariable, LogicalVariable> varMapping = unionOp.getVariableMappings().get(i);
-            if (assignUsedVars.contains(varMapping.third)) {
-                LogicalVariable replacementVar;
-                if (inputIndex == 0) {
-                    replacementVar = varMapping.first;
-                } else {
-                    replacementVar = varMapping.second;
-                }
-                VariableUtilities.substituteVariables(newAssignOp, varMapping.third, replacementVar, context);
-            }
-        }
-        return newAssignOp;
-    }
-
-    /**
-     * Clones the given assign operator changing the returned variables to be new ones.
-     * Also, leaves the inputs of the clone clear.
-     */
-    private AssignOperator cloneAssignOperator(AssignOperator assignOp, IOptimizationContext context) {
-        List<LogicalVariable> vars = new ArrayList<LogicalVariable>();
-        List<Mutable<ILogicalExpression>> exprs = new ArrayList<Mutable<ILogicalExpression>>();
-        int numVars = assignOp.getVariables().size();
-        for (int i = 0; i < numVars; i++) {
-            vars.add(context.newVar());
-            exprs.add(new MutableObject<ILogicalExpression>(assignOp.getExpressions().get(i).getValue()
-                    .cloneExpression()));
-        }
-        AssignOperator assignCloneOp = new AssignOperator(vars, exprs);
-        assignCloneOp.setExecutionMode(assignOp.getExecutionMode());
-        return assignCloneOp;
-    }
-}

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/PushAssignDownThroughProductRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/PushAssignDownThroughProductRule.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/PushAssignDownThroughProductRule.java
deleted file mode 100644
index d8523f6..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/PushAssignDownThroughProductRule.java
+++ /dev/null
@@ -1,87 +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.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.visitors.VariableUtilities;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-public class PushAssignDownThroughProductRule 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.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
-            return false;
-        }
-        Mutable<ILogicalOperator> op2Ref = op1.getInputs().get(0);
-        AbstractLogicalOperator op2 = (AbstractLogicalOperator) op2Ref.getValue();
-        if (op2.getOperatorTag() != LogicalOperatorTag.INNERJOIN) {
-            return false;
-        }
-        AbstractBinaryJoinOperator join = (AbstractBinaryJoinOperator) op2;
-        if (join.getCondition().getValue() != ConstantExpression.TRUE) {
-            return false;
-        }
-
-        List<LogicalVariable> used = new ArrayList<LogicalVariable>();
-        VariableUtilities.getUsedVariables(op1, used);
-
-        Mutable<ILogicalOperator> b0Ref = op2.getInputs().get(0);
-        ILogicalOperator b0 = b0Ref.getValue();
-        List<LogicalVariable> b0Scm = new ArrayList<LogicalVariable>();
-        VariableUtilities.getLiveVariables(b0, b0Scm);
-        if (b0Scm.containsAll(used)) {
-            // push assign on left branch
-            op2Ref.setValue(b0);
-            b0Ref.setValue(op1);
-            opRef.setValue(op2);
-            return true;
-        } else {
-            Mutable<ILogicalOperator> b1Ref = op2.getInputs().get(1);
-            ILogicalOperator b1 = b1Ref.getValue();
-            List<LogicalVariable> b1Scm = new ArrayList<LogicalVariable>();
-            VariableUtilities.getLiveVariables(b1, b1Scm);
-            if (b1Scm.containsAll(used)) {
-                // push assign on right branch
-                op2Ref.setValue(b1);
-                b1Ref.setValue(op1);
-                opRef.setValue(op2);
-                return true;
-            } else {
-                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/PushFunctionsBelowJoin.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/PushFunctionsBelowJoin.java b/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/PushFunctionsBelowJoin.java
deleted file mode 100644
index 0d24618..0000000
--- a/algebricks/algebricks-rewriter/src/main/java/edu/uci/ics/hyracks/algebricks/rewriter/rules/PushFunctionsBelowJoin.java
+++ /dev/null
@@ -1,208 +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.Iterator;
-import java.util.List;
-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.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.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;
-
-/**
- * Pushes function-call expressions below a join if possible.
- * Assigns the result of such function-calls expressions to new variables, and replaces the original
- * expression with a corresponding variable reference expression.
- * This rule can help reduce the cost of computing expensive functions by pushing them below
- * a join (which may blow up the cardinality).
- * Also, this rule may help to enable other rules such as common subexpression elimination, again to reduce
- * the number of calls to expensive functions.
- * 
- * Example: (we are pushing pushMeFunc)
- * 
- * Before plan:
- * assign [$$10] <- [funcA(funcB(pushMeFunc($$3, $$4)))]
- *   join (some condition) 
- *     join_branch_0 where $$3 and $$4 are not live
- *       ...
- *     join_branch_1 where $$3 and $$4 are live
- *       ...
- * 
- * After plan:
- * assign [$$10] <- [funcA(funcB($$11))]
- *   join (some condition) 
- *     join_branch_0 where $$3 and $$4 are not live
- *       ...
- *     join_branch_1 where $$3 and $$4 are live
- *       assign[$$11] <- [pushMeFunc($$3, $$4)]
- *         ...
- */
-public class PushFunctionsBelowJoin implements IAlgebraicRewriteRule {
-
-    private final Set<FunctionIdentifier> toPushFuncIdents;
-    private final List<Mutable<ILogicalExpression>> funcExprs = new ArrayList<Mutable<ILogicalExpression>>();
-    private final List<LogicalVariable> usedVars = new ArrayList<LogicalVariable>();
-    private final List<LogicalVariable> liveVars = new ArrayList<LogicalVariable>();
-
-    public PushFunctionsBelowJoin(Set<FunctionIdentifier> toPushFuncIdents) {
-        this.toPushFuncIdents = toPushFuncIdents;
-    }
-
-    @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.ASSIGN) {
-            return false;
-        }
-        AssignOperator assignOp = (AssignOperator) op;
-
-        // Find a join operator below this assign.
-        Mutable<ILogicalOperator> joinOpRef = findJoinOp(assignOp.getInputs().get(0));
-        if (joinOpRef == null) {
-            return false;
-        }
-        AbstractBinaryJoinOperator joinOp = (AbstractBinaryJoinOperator) joinOpRef.getValue();
-
-        // Check if the assign uses a function that we wish to push below the join if possible.
-        funcExprs.clear();
-        gatherFunctionCalls(assignOp, funcExprs);
-        if (funcExprs.isEmpty()) {
-            return false;
-        }
-
-        // Try to push the functions down the input branches of the join.
-        boolean modified = false;
-        if (pushDownFunctions(joinOp, 0, funcExprs, context)) {
-            modified = true;
-        }
-        if (pushDownFunctions(joinOp, 1, funcExprs, context)) {
-            modified = true;
-        }
-        if (modified) {
-            context.computeAndSetTypeEnvironmentForOperator(joinOp);
-        }
-        return modified;
-    }
-
-    private Mutable<ILogicalOperator> findJoinOp(Mutable<ILogicalOperator> opRef) {
-        AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
-        switch (op.getOperatorTag()) {
-            case INNERJOIN:
-            case LEFTOUTERJOIN: {
-                return opRef;
-            }
-            // Bail on these operators.
-            case GROUP:
-            case AGGREGATE:
-            case DISTINCT:
-            case UNNEST_MAP: {
-                return null;
-            }
-            // Traverse children.
-            default: {
-                for (Mutable<ILogicalOperator> childOpRef : op.getInputs()) {
-                    return findJoinOp(childOpRef);
-                }
-            }
-        }
-        return null;
-    }
-
-    private void gatherFunctionCalls(AssignOperator assignOp, List<Mutable<ILogicalExpression>> funcExprs) {
-        for (Mutable<ILogicalExpression> exprRef : assignOp.getExpressions()) {
-            gatherFunctionCalls(exprRef, funcExprs);
-        }
-    }
-
-    private void gatherFunctionCalls(Mutable<ILogicalExpression> exprRef, List<Mutable<ILogicalExpression>> funcExprs) {
-        AbstractLogicalExpression expr = (AbstractLogicalExpression) exprRef.getValue();
-        if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
-            return;
-        }
-        // Check whether the function is a function we want to push.
-        AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr;
-        if (toPushFuncIdents.contains(funcExpr.getFunctionIdentifier())) {
-            funcExprs.add(exprRef);
-        }
-        // Traverse arguments.
-        for (Mutable<ILogicalExpression> funcArg : funcExpr.getArguments()) {
-            gatherFunctionCalls(funcArg, funcExprs);
-        }
-    }
-
-    private boolean pushDownFunctions(AbstractBinaryJoinOperator joinOp, int inputIndex,
-            List<Mutable<ILogicalExpression>> funcExprs, IOptimizationContext context) throws AlgebricksException {
-        ILogicalOperator joinInputOp = joinOp.getInputs().get(inputIndex).getValue();
-        liveVars.clear();
-        VariableUtilities.getLiveVariables(joinInputOp, liveVars);
-        Iterator<Mutable<ILogicalExpression>> funcIter = funcExprs.iterator();
-        List<LogicalVariable> assignVars = null;
-        List<Mutable<ILogicalExpression>> assignExprs = null;
-        while (funcIter.hasNext()) {
-            Mutable<ILogicalExpression> funcExprRef = funcIter.next();
-            ILogicalExpression funcExpr = funcExprRef.getValue();
-            usedVars.clear();
-            funcExpr.getUsedVariables(usedVars);
-            // Check if we can push the function down this branch.
-            if (liveVars.containsAll(usedVars)) {
-                if (assignVars == null) {
-                    assignVars = new ArrayList<LogicalVariable>();
-                    assignExprs = new ArrayList<Mutable<ILogicalExpression>>();
-                }
-                // Replace the original expression with a variable reference expression.
-                LogicalVariable replacementVar = context.newVar();
-                assignVars.add(replacementVar);
-                assignExprs.add(new MutableObject<ILogicalExpression>(funcExpr));
-                funcExprRef.setValue(new VariableReferenceExpression(replacementVar));
-                funcIter.remove();
-            }
-        }
-        // Create new assign operator below the join if any functions can be pushed.
-        if (assignVars != null) {
-            AssignOperator newAssign = new AssignOperator(assignVars, assignExprs);
-            newAssign.getInputs().add(new MutableObject<ILogicalOperator>(joinInputOp));
-            newAssign.setExecutionMode(joinOp.getExecutionMode());
-            joinOp.getInputs().get(inputIndex).setValue(newAssign);
-            context.computeAndSetTypeEnvironmentForOperator(newAssign);
-            return true;
-        }
-        return false;
-    }
-}



Mime
View raw message