asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject [44/51] [partial] incubator-asterixdb git commit: Change folder structure for Java repackage
Date Tue, 25 Aug 2015 16:44:32 GMT
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/34d81630/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/PushFieldAccessRule.java
----------------------------------------------------------------------
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/PushFieldAccessRule.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/PushFieldAccessRule.java
deleted file mode 100644
index 3a19854..0000000
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/PushFieldAccessRule.java
+++ /dev/null
@@ -1,391 +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.asterix.optimizer.rules;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.apache.commons.lang3.mutable.Mutable;
-import org.apache.commons.lang3.mutable.MutableObject;
-
-import edu.uci.ics.asterix.algebra.base.AsterixOperatorAnnotations;
-import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
-import edu.uci.ics.asterix.common.exceptions.AsterixRuntimeException;
-import edu.uci.ics.asterix.metadata.declared.AqlDataSource;
-import edu.uci.ics.asterix.metadata.declared.AqlDataSource.AqlDataSourceType;
-import edu.uci.ics.asterix.metadata.declared.AqlMetadataProvider;
-import edu.uci.ics.asterix.metadata.declared.AqlSourceId;
-import edu.uci.ics.asterix.metadata.entities.Dataset;
-import edu.uci.ics.asterix.metadata.entities.Index;
-import edu.uci.ics.asterix.metadata.utils.DatasetUtils;
-import edu.uci.ics.asterix.om.base.AInt32;
-import edu.uci.ics.asterix.om.base.AString;
-import edu.uci.ics.asterix.om.base.IAObject;
-import edu.uci.ics.asterix.om.constants.AsterixConstantValue;
-import edu.uci.ics.asterix.om.types.ARecordType;
-import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.asterix.om.types.IAType;
-import edu.uci.ics.asterix.optimizer.base.AnalysisUtil;
-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.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.ConstantExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.metadata.IDataSource;
-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.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.visitors.VariableUtilities;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-public class PushFieldAccessRule 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 (context.checkIfInDontApplySet(this, op)) {
-            return false;
-        }
-        if (op.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
-            return false;
-        }
-        AssignOperator access = (AssignOperator) op;
-        ILogicalExpression expr = getFirstExpr(access);
-        String finalAnnot = null;
-        if (AnalysisUtil.isAccessToFieldRecord(expr)) {
-            finalAnnot = AsterixOperatorAnnotations.PUSHED_FIELD_ACCESS;
-        } else if (AnalysisUtil.isRunnableAccessToFieldRecord(expr)) {
-            finalAnnot = AsterixOperatorAnnotations.PUSHED_RUNNABLE_FIELD_ACCESS;
-        } else {
-            return false;
-        }
-        return propagateFieldAccessRec(opRef, context, finalAnnot);
-    }
-
-    @SuppressWarnings("unchecked")
-    private boolean isAccessToIndexedField(AssignOperator assign, IOptimizationContext context)
-            throws AlgebricksException {
-        AbstractFunctionCallExpression accessFun = (AbstractFunctionCallExpression) assign.getExpressions().get(0)
-                .getValue();
-        ILogicalExpression e0 = accessFun.getArguments().get(0).getValue();
-        if (e0.getExpressionTag() != LogicalExpressionTag.VARIABLE) {
-            return false;
-        }
-        LogicalVariable var = ((VariableReferenceExpression) e0).getVariableReference();
-        if (context.findPrimaryKey(var) == null) {
-            // not referring to a dataset record
-            return false;
-        }
-        AbstractLogicalOperator op = assign;
-        while (op.getInputs().size() == 1 && op.getOperatorTag() != LogicalOperatorTag.DATASOURCESCAN) {
-            op = (AbstractLogicalOperator) op.getInputs().get(0).getValue();
-        }
-        if (op.getOperatorTag() != LogicalOperatorTag.DATASOURCESCAN) {
-            return false;
-        }
-        DataSourceScanOperator scan = (DataSourceScanOperator) op;
-        LogicalVariable recVar = scan.getVariables().get(scan.getVariables().size() - 1);
-        if (recVar != var) {
-            return false;
-        }
-        AqlMetadataProvider mp = (AqlMetadataProvider) context.getMetadataProvider();
-        AqlSourceId asid = ((IDataSource<AqlSourceId>) scan.getDataSource()).getId();
-
-        Dataset dataset = mp.findDataset(asid.getDataverseName(), asid.getDatasourceName());
-        if (dataset == null) {
-            throw new AlgebricksException("Dataset " + asid.getDatasourceName() + " not found.");
-        }
-        if (dataset.getDatasetType() != DatasetType.INTERNAL) {
-            return false;
-        }
-        ILogicalExpression e1 = accessFun.getArguments().get(1).getValue();
-        if (e1.getExpressionTag() != LogicalExpressionTag.CONSTANT) {
-            return false;
-        }
-        ConstantExpression ce = (ConstantExpression) e1;
-        IAObject obj = ((AsterixConstantValue) ce.getValue()).getObject();
-        String fldName;
-        if (obj.getType().getTypeTag() == ATypeTag.STRING) {
-            fldName = ((AString) obj).getStringValue();
-        } else {
-            int pos = ((AInt32) obj).getIntegerValue();
-            String tName = dataset.getItemTypeName();
-            IAType t = mp.findType(dataset.getDataverseName(), tName);
-            if (t.getTypeTag() != ATypeTag.RECORD) {
-                return false;
-            }
-            ARecordType rt = (ARecordType) t;
-            if (pos >= rt.getFieldNames().length) {
-                return false;
-            }
-            fldName = rt.getFieldNames()[pos];
-        }
-
-        List<Index> datasetIndexes = mp.getDatasetIndexes(dataset.getDataverseName(), dataset.getDatasetName());
-        boolean hasSecondaryIndex = false;
-        for (Index index : datasetIndexes) {
-            if (index.isSecondaryIndex()) {
-                hasSecondaryIndex = true;
-                break;
-            }
-        }
-
-        return hasSecondaryIndex;
-    }
-
-    private boolean tryingToPushThroughSelectionWithSameDataSource(AssignOperator access, AbstractLogicalOperator op2) {
-        if (op2.getOperatorTag() != LogicalOperatorTag.SELECT) {
-            return false;
-        }
-        ILogicalExpression e1 = (ILogicalExpression) access.getAnnotations().get(
-                AsterixOperatorAnnotations.FIELD_ACCESS);
-        if (e1 == null) {
-            return false;
-        }
-        ILogicalExpression e2 = (ILogicalExpression) op2.getAnnotations().get(AsterixOperatorAnnotations.FIELD_ACCESS);
-        if (e2 == null) {
-            return false;
-        }
-        return e1.equals(e2);
-    }
-
-    @SuppressWarnings("unchecked")
-    private boolean propagateFieldAccessRec(Mutable<ILogicalOperator> opRef, IOptimizationContext context,
-            String finalAnnot) throws AlgebricksException {
-        AssignOperator access = (AssignOperator) opRef.getValue();
-        Mutable<ILogicalOperator> opRef2 = access.getInputs().get(0);
-        AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue();
-        // If it's not an indexed field, it is pushed so that scan can be
-        // rewritten into index search.
-        if (op2.getOperatorTag() == LogicalOperatorTag.PROJECT || context.checkAndAddToAlreadyCompared(access, op2)
-                && !(op2.getOperatorTag() == LogicalOperatorTag.SELECT && isAccessToIndexedField(access, context))) {
-            return false;
-        }
-        if (tryingToPushThroughSelectionWithSameDataSource(access, op2)) {
-            return false;
-        }
-        if (testAndModifyRedundantOp(access, op2)) {
-            propagateFieldAccessRec(opRef2, context, finalAnnot);
-            return true;
-        }
-        List<LogicalVariable> usedInAccess = new LinkedList<LogicalVariable>();
-        VariableUtilities.getUsedVariables(access, usedInAccess);
-        List<LogicalVariable> produced2 = new LinkedList<LogicalVariable>();
-        if (op2.getOperatorTag() == LogicalOperatorTag.GROUP) {
-            VariableUtilities.getLiveVariables(op2, produced2);
-        } else {
-            VariableUtilities.getProducedVariables(op2, produced2);
-        }
-        boolean pushItDown = false;
-        List<LogicalVariable> inter = new ArrayList<LogicalVariable>(usedInAccess);
-        if (inter.isEmpty()) { // ground value
-            return false;
-        }
-        inter.retainAll(produced2);
-        if (inter.isEmpty()) {
-            pushItDown = true;
-        } else if (op2.getOperatorTag() == LogicalOperatorTag.GROUP) {
-            GroupByOperator g = (GroupByOperator) op2;
-            List<Pair<LogicalVariable, LogicalVariable>> varMappings = new ArrayList<Pair<LogicalVariable, LogicalVariable>>();
-            for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : g.getDecorList()) {
-                ILogicalExpression e = p.second.getValue();
-                if (e.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
-                    LogicalVariable decorVar = GroupByOperator.getDecorVariable(p);
-                    if (inter.contains(decorVar)) {
-                        inter.remove(decorVar);
-                        LogicalVariable v1 = ((VariableReferenceExpression) e).getVariableReference();
-                        varMappings.add(new Pair<LogicalVariable, LogicalVariable>(decorVar, v1));
-                    }
-                }
-            }
-            if (inter.isEmpty()) {
-                boolean changed = false;
-                for (Pair<LogicalVariable, LogicalVariable> m : varMappings) {
-                    LogicalVariable v2 = context.newVar();
-                    LogicalVariable oldVar = access.getVariables().get(0);
-                    g.getDecorList().add(
-                            new Pair<LogicalVariable, Mutable<ILogicalExpression>>(oldVar,
-                                    new MutableObject<ILogicalExpression>(new VariableReferenceExpression(v2))));
-                    changed = true;
-                    access.getVariables().set(0, v2);
-                    VariableUtilities.substituteVariables(access, m.first, m.second, context);
-                }
-                if (changed) {
-                    context.computeAndSetTypeEnvironmentForOperator(g);
-                }
-                usedInAccess.clear();
-                VariableUtilities.getUsedVariables(access, usedInAccess);
-                pushItDown = true;
-            }
-        }
-        if (pushItDown) {
-            if (op2.getOperatorTag() == LogicalOperatorTag.NESTEDTUPLESOURCE) {
-                Mutable<ILogicalOperator> childOfSubplan = ((NestedTupleSourceOperator) op2).getDataSourceReference()
-                        .getValue().getInputs().get(0);
-                pushAccessDown(opRef, op2, childOfSubplan, context, finalAnnot);
-                return true;
-            }
-            if (op2.getInputs().size() == 1 && !op2.hasNestedPlans()) {
-                pushAccessDown(opRef, op2, op2.getInputs().get(0), context, finalAnnot);
-                return true;
-            } else {
-                for (Mutable<ILogicalOperator> inp : op2.getInputs()) {
-                    HashSet<LogicalVariable> v2 = new HashSet<LogicalVariable>();
-                    VariableUtilities.getLiveVariables(inp.getValue(), v2);
-                    if (v2.containsAll(usedInAccess)) {
-                        pushAccessDown(opRef, op2, inp, context, finalAnnot);
-                        return true;
-                    }
-                }
-            }
-            if (op2.hasNestedPlans()) {
-                AbstractOperatorWithNestedPlans nestedOp = (AbstractOperatorWithNestedPlans) op2;
-                for (ILogicalPlan plan : nestedOp.getNestedPlans()) {
-                    for (Mutable<ILogicalOperator> root : plan.getRoots()) {
-                        HashSet<LogicalVariable> v2 = new HashSet<LogicalVariable>();
-                        VariableUtilities.getLiveVariables(root.getValue(), v2);
-                        if (v2.containsAll(usedInAccess)) {
-                            pushAccessDown(opRef, op2, root, context, finalAnnot);
-                            return true;
-                        }
-                    }
-                }
-            }
-            throw new AsterixRuntimeException("Field access " + access.getExpressions().get(0).getValue()
-                    + " does not correspond to any input of operator " + op2);
-        } else {
-            // Check if the accessed field is not one of the partitioning key
-            // fields. If yes, we can equate the two variables.
-            if (op2.getOperatorTag() == LogicalOperatorTag.DATASOURCESCAN) {
-                DataSourceScanOperator scan = (DataSourceScanOperator) op2;
-                int n = scan.getVariables().size();
-                LogicalVariable scanRecordVar = scan.getVariables().get(n - 1);
-                AbstractFunctionCallExpression accessFun = (AbstractFunctionCallExpression) access.getExpressions()
-                        .get(0).getValue();
-                ILogicalExpression e0 = accessFun.getArguments().get(0).getValue();
-                LogicalExpressionTag tag = e0.getExpressionTag();
-                if (tag == LogicalExpressionTag.VARIABLE) {
-                    VariableReferenceExpression varRef = (VariableReferenceExpression) e0;
-                    if (varRef.getVariableReference() == scanRecordVar) {
-                        ILogicalExpression e1 = accessFun.getArguments().get(1).getValue();
-                        if (e1.getExpressionTag() == LogicalExpressionTag.CONSTANT) {
-                            IDataSource<AqlSourceId> dataSource = (IDataSource<AqlSourceId>) scan.getDataSource();
-                            AqlDataSourceType dsType = ((AqlDataSource) dataSource).getDatasourceType();
-                            if (dsType == AqlDataSourceType.FEED || dsType == AqlDataSourceType.LOADABLE) {
-                                return false;
-                            }
-                            AqlSourceId asid = dataSource.getId();
-                            AqlMetadataProvider mp = (AqlMetadataProvider) context.getMetadataProvider();
-                            Dataset dataset = mp.findDataset(asid.getDataverseName(), asid.getDatasourceName());
-                            if (dataset == null) {
-                                throw new AlgebricksException("Dataset " + asid.getDatasourceName() + " not found.");
-                            }
-                            if (dataset.getDatasetType() != DatasetType.INTERNAL) {
-                                setAsFinal(access, context, finalAnnot);
-                                return false;
-                            }
-                            ConstantExpression ce = (ConstantExpression) e1;
-                            IAObject obj = ((AsterixConstantValue) ce.getValue()).getObject();
-                            String fldName;
-                            if (obj.getType().getTypeTag() == ATypeTag.STRING) {
-                                fldName = ((AString) obj).getStringValue();
-                            } else {
-                                int pos = ((AInt32) obj).getIntegerValue();
-                                String tName = dataset.getItemTypeName();
-                                IAType t = mp.findType(dataset.getDataverseName(), tName);
-                                if (t.getTypeTag() != ATypeTag.RECORD) {
-                                    return false;
-                                }
-                                ARecordType rt = (ARecordType) t;
-                                if (pos >= rt.getFieldNames().length) {
-                                    setAsFinal(access, context, finalAnnot);
-                                    return false;
-                                }
-                                fldName = rt.getFieldNames()[pos];
-                            }
-                            int p = DatasetUtils.getPositionOfPartitioningKeyField(dataset, fldName);
-                            if (p < 0) { // not one of the partitioning fields
-                                setAsFinal(access, context, finalAnnot);
-                                return false;
-                            }
-                            LogicalVariable keyVar = scan.getVariables().get(p);
-                            access.getExpressions().get(0).setValue(new VariableReferenceExpression(keyVar));
-                            return true;
-                        }
-                    }
-                }
-            }
-            setAsFinal(access, context, finalAnnot);
-            return false;
-        }
-    }
-
-    private void setAsFinal(ILogicalOperator access, IOptimizationContext context, String finalAnnot) {
-        access.getAnnotations().put(finalAnnot, true);
-        context.addToDontApplySet(this, access);
-    }
-
-    private boolean testAndModifyRedundantOp(AssignOperator access, AbstractLogicalOperator op2) {
-        if (op2.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
-            return false;
-        }
-        AssignOperator a2 = (AssignOperator) op2;
-        if (getFirstExpr(access).equals(getFirstExpr(a2))) {
-            access.getExpressions().get(0).setValue(new VariableReferenceExpression(a2.getVariables().get(0)));
-            return true;
-        } else {
-            return false;
-        }
-    }
-
-    // indirect recursivity with propagateFieldAccessRec
-    private void pushAccessDown(Mutable<ILogicalOperator> fldAccessOpRef, ILogicalOperator op2,
-            Mutable<ILogicalOperator> inputOfOp2, IOptimizationContext context, String finalAnnot)
-            throws AlgebricksException {
-        ILogicalOperator fieldAccessOp = fldAccessOpRef.getValue();
-        fldAccessOpRef.setValue(op2);
-        List<Mutable<ILogicalOperator>> faInpList = fieldAccessOp.getInputs();
-        faInpList.clear();
-        faInpList.add(new MutableObject<ILogicalOperator>(inputOfOp2.getValue()));
-        inputOfOp2.setValue(fieldAccessOp);
-        // typing
-        context.computeAndSetTypeEnvironmentForOperator(fieldAccessOp);
-        context.computeAndSetTypeEnvironmentForOperator(op2);
-        propagateFieldAccessRec(inputOfOp2, context, finalAnnot);
-    }
-
-    private ILogicalExpression getFirstExpr(AssignOperator assign) {
-        return assign.getExpressions().get(0).getValue();
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/34d81630/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/PushGroupByThroughProduct.java
----------------------------------------------------------------------
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/PushGroupByThroughProduct.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/PushGroupByThroughProduct.java
deleted file mode 100644
index 647c3ee..0000000
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/PushGroupByThroughProduct.java
+++ /dev/null
@@ -1,172 +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.asterix.optimizer.rules;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-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.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.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.AbstractBinaryJoinOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.visitors.VariableUtilities;
-import edu.uci.ics.hyracks.algebricks.core.algebra.util.OperatorManipulationUtil;
-import edu.uci.ics.hyracks.algebricks.core.algebra.util.OperatorPropertiesUtil;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-public class PushGroupByThroughProduct implements IAlgebraicRewriteRule {
-
-    private enum PushTestResult {
-        FALSE,
-        TRUE,
-        REPEATED_DECORS
-    }
-
-    @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.GROUP) {
-            return false;
-        }
-        Mutable<ILogicalOperator> opRef2 = op1.getInputs().get(0);
-        AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue();
-        if (op2.getOperatorTag() != LogicalOperatorTag.INNERJOIN) {
-            return false;
-        }
-        InnerJoinOperator join = (InnerJoinOperator) op2;
-        if (!OperatorPropertiesUtil.isAlwaysTrueCond(join.getCondition().getValue())) {
-            // not a product
-            return false;
-        }
-        GroupByOperator gby = (GroupByOperator) op1;
-
-        List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> decorToPush = new ArrayList<Pair<LogicalVariable, Mutable<ILogicalExpression>>>();
-        List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> decorNotToPush = new ArrayList<Pair<LogicalVariable, Mutable<ILogicalExpression>>>();
-
-        Mutable<ILogicalOperator> opLeftRef = join.getInputs().get(0);
-        ILogicalOperator opLeft = opLeftRef.getValue();
-        switch (canPushThrough(gby, opLeft, decorToPush, decorNotToPush)) {
-            case REPEATED_DECORS: {
-                return false;
-            }
-            case TRUE: {
-                push(opRef, opRef2, 0, decorToPush, decorNotToPush, context);
-                return true;
-            }
-            case FALSE: {
-                decorToPush.clear();
-                Mutable<ILogicalOperator> opRightRef = join.getInputs().get(1);
-                ILogicalOperator opRight = opRightRef.getValue();
-                if (canPushThrough(gby, opRight, decorToPush, decorNotToPush) == PushTestResult.TRUE) {
-                    push(opRef, opRef2, 1, decorToPush, decorNotToPush, context);
-                    return true;
-                } else {
-                    return false;
-                }
-            }
-            default: {
-                throw new IllegalStateException();
-            }
-        }
-    }
-
-    private void push(Mutable<ILogicalOperator> opRefGby, Mutable<ILogicalOperator> opRefJoin, int branch,
-            List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> decorToPush,
-            List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> decorNotToPush, IOptimizationContext context)
-            throws AlgebricksException {
-        GroupByOperator gby = (GroupByOperator) opRefGby.getValue();
-        AbstractBinaryJoinOperator join = (AbstractBinaryJoinOperator) opRefJoin.getValue();
-        gby.getDecorList().clear();
-        gby.getDecorList().addAll(decorToPush);
-        for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : decorNotToPush) {
-            LogicalVariable v1 = p.first;
-            VariableReferenceExpression varRef = (VariableReferenceExpression) p.second.getValue();
-            LogicalVariable v2 = varRef.getVariableReference();
-            OperatorManipulationUtil.substituteVarRec(join, v2, v1, true, context);
-        }
-        Mutable<ILogicalOperator> branchRef = join.getInputs().get(branch);
-        ILogicalOperator opBranch = branchRef.getValue();
-        opRefJoin.setValue(opBranch);
-        branchRef.setValue(gby);
-        opRefGby.setValue(join);
-    }
-
-    private PushTestResult canPushThrough(GroupByOperator gby, ILogicalOperator branch,
-            List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> toPush,
-            List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> notToPush) throws AlgebricksException {
-        Collection<LogicalVariable> fromBranch = new HashSet<LogicalVariable>();
-        VariableUtilities.getLiveVariables(branch, fromBranch);
-        Collection<LogicalVariable> usedInGbyExprList = new ArrayList<LogicalVariable>();
-        for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : gby.getGroupByList()) {
-            p.second.getValue().getUsedVariables(usedInGbyExprList);
-        }
-
-        if (!fromBranch.containsAll(usedInGbyExprList)) {
-            return PushTestResult.FALSE;
-        }
-        Set<LogicalVariable> free = new HashSet<LogicalVariable>();
-        for (ILogicalPlan p : gby.getNestedPlans()) {
-            for (Mutable<ILogicalOperator> r : p.getRoots()) {
-                OperatorPropertiesUtil.getFreeVariablesInSelfOrDesc((AbstractLogicalOperator) r.getValue(), free);
-            }
-        }
-        if (!fromBranch.containsAll(free)) {
-            return PushTestResult.FALSE;
-        }
-
-        Set<LogicalVariable> decorVarRhs = new HashSet<LogicalVariable>();
-        decorVarRhs.clear();
-        for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : gby.getDecorList()) {
-            ILogicalExpression expr = p.second.getValue();
-            if (expr.getExpressionTag() != LogicalExpressionTag.VARIABLE) {
-                return PushTestResult.FALSE;
-            }
-            VariableReferenceExpression varRef = (VariableReferenceExpression) expr;
-            LogicalVariable v = varRef.getVariableReference();
-            if (decorVarRhs.contains(v)) {
-                return PushTestResult.REPEATED_DECORS;
-            }
-            decorVarRhs.add(v);
-
-            if (fromBranch.contains(v)) {
-                toPush.add(p);
-            } else {
-                notToPush.add(p);
-            }
-        }
-        return PushTestResult.TRUE;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/34d81630/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/PushProperJoinThroughProduct.java
----------------------------------------------------------------------
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/PushProperJoinThroughProduct.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/PushProperJoinThroughProduct.java
deleted file mode 100644
index 7d9d261..0000000
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/PushProperJoinThroughProduct.java
+++ /dev/null
@@ -1,107 +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.asterix.optimizer.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.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.AbstractBinaryJoinOperator;
-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.visitors.VariableUtilities;
-import edu.uci.ics.hyracks.algebricks.core.algebra.util.OperatorPropertiesUtil;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-public class PushProperJoinThroughProduct implements IAlgebraicRewriteRule {
-
-    private List<LogicalVariable> usedInCond1AndMaps = new ArrayList<LogicalVariable>();
-    private List<LogicalVariable> productLeftBranchVars = new ArrayList<LogicalVariable>();
-
-    @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();
-        LogicalOperatorTag tag1 = op.getOperatorTag();
-        if (tag1 != LogicalOperatorTag.INNERJOIN && tag1 != LogicalOperatorTag.LEFTOUTERJOIN) {
-            return false;
-        }
-        AbstractBinaryJoinOperator join1 = (AbstractBinaryJoinOperator) op;
-        ILogicalExpression cond1 = join1.getCondition().getValue();
-        // don't try to push a product down
-        if (OperatorPropertiesUtil.isAlwaysTrueCond(cond1)) {
-            return false;
-        }
-
-        Mutable<ILogicalOperator> opRef2 = op.getInputs().get(0);
-
-        AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue();
-        while (op2.isMap()) {
-            opRef2 = op2.getInputs().get(0);
-            op2 = (AbstractLogicalOperator) opRef2.getValue();
-        }
-
-        if (op2.getOperatorTag() != LogicalOperatorTag.INNERJOIN) {
-            return false;
-        }
-
-        InnerJoinOperator product = (InnerJoinOperator) op2;
-        if (!OperatorPropertiesUtil.isAlwaysTrueCond(product.getCondition().getValue())) {
-            return false;
-        }
-
-        usedInCond1AndMaps.clear();
-        cond1.getUsedVariables(usedInCond1AndMaps);
-        Mutable<ILogicalOperator> opIterRef = op.getInputs().get(0);
-        ILogicalOperator opIter = opIterRef.getValue();
-        do {
-            VariableUtilities.getUsedVariables(opIter, usedInCond1AndMaps);
-            opIterRef = opIter.getInputs().get(0);
-            opIter = opIterRef.getValue();
-        } while (opIter.isMap());
-
-        productLeftBranchVars.clear();
-        ILogicalOperator opLeft = op2.getInputs().get(0).getValue();
-        VariableUtilities.getLiveVariables(opLeft, productLeftBranchVars);
-
-        if (!OperatorPropertiesUtil.disjoint(usedInCond1AndMaps, productLeftBranchVars)) {
-            return false;
-        }
-
-        // now push the operators from in between joins, too
-        opIterRef = op.getInputs().get(0);
-        opIter = opIterRef.getValue();
-
-        Mutable<ILogicalOperator> op3Ref = product.getInputs().get(1);
-        ILogicalOperator op3 = op3Ref.getValue();
-
-        opRef2.setValue(op3);
-        op3Ref.setValue(join1);
-        opRef.setValue(product);
-        return true;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/34d81630/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/PushSimilarityFunctionsBelowJoin.java
----------------------------------------------------------------------
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/PushSimilarityFunctionsBelowJoin.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/PushSimilarityFunctionsBelowJoin.java
deleted file mode 100644
index d9e06f4..0000000
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/PushSimilarityFunctionsBelowJoin.java
+++ /dev/null
@@ -1,63 +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.asterix.optimizer.rules;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
-import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import edu.uci.ics.hyracks.algebricks.rewriter.rules.PushFunctionsBelowJoin;
-
-/**
- * Pushes similarity function-call expressions below a join if possible.
- * Assigns the similarity function-call 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 similarity 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 similarity functions.
- * Example:
- * Before plan:
- * assign [$$10] <- [funcA(funcB(simFuncX($$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] <- [simFuncX($$3, $$4)]
- * ...
- */
-public class PushSimilarityFunctionsBelowJoin extends PushFunctionsBelowJoin {
-
-    private static final Set<FunctionIdentifier> simFuncIdents = new HashSet<FunctionIdentifier>();
-    static {
-        simFuncIdents.add(AsterixBuiltinFunctions.SIMILARITY_JACCARD);
-        simFuncIdents.add(AsterixBuiltinFunctions.SIMILARITY_JACCARD_CHECK);
-        simFuncIdents.add(AsterixBuiltinFunctions.EDIT_DISTANCE);
-        simFuncIdents.add(AsterixBuiltinFunctions.EDIT_DISTANCE_CHECK);
-    }
-
-    public PushSimilarityFunctionsBelowJoin() {
-        super(simFuncIdents);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/34d81630/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/RemoveRedundantListifyRule.java
----------------------------------------------------------------------
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/RemoveRedundantListifyRule.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/RemoveRedundantListifyRule.java
deleted file mode 100644
index 05c68f4..0000000
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/RemoveRedundantListifyRule.java
+++ /dev/null
@@ -1,254 +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.asterix.optimizer.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.asterix.aql.util.FunctionUtils;
-import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.common.utils.ListSet;
-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.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.StatefulFunctionCallExpression;
-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.AbstractOperatorWithNestedPlans;
-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.RunningAggregateOperator;
-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.properties.UnpartitionedPropertyComputer;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-/*
- *
- *  unnest $x [[ at $p ]] <- $y
- *    aggregate $y <- function-call: listify@1(unresolved), Args:[$z]
- *       Rest 
- *   
- * if $y is not used above these operators, 
- * the plan fragment becomes
- *
- *  [[ runningaggregate $p <- tid]]
- *  assign $x <- $z
- *       Rest
- *  
- *
- */
-
-public class RemoveRedundantListifyRule implements IAlgebraicRewriteRule {
-    @Override
-    public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) {
-        return false;
-    }
-
-    @Override
-    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
-        // apply it only at the top of the plan
-        ILogicalOperator op = opRef.getValue();
-        if (context.checkIfInDontApplySet(this, op)) {
-            return false;
-        }
-        Set<LogicalVariable> varSet = new HashSet<LogicalVariable>();
-        return applyRuleDown(opRef, varSet, context);
-    }
-
-    private boolean applyRuleDown(Mutable<ILogicalOperator> opRef, Set<LogicalVariable> varSet,
-            IOptimizationContext context) throws AlgebricksException {
-        boolean changed = applies(opRef, varSet, context);
-        changed |= appliesForReverseCase(opRef, varSet, context);
-        AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
-        VariableUtilities.getUsedVariables(op, varSet);
-        if (op.hasNestedPlans()) {
-            // Variables used by the parent operators should be live at op.
-            Set<LogicalVariable> localLiveVars = new ListSet<LogicalVariable>();
-            VariableUtilities.getLiveVariables(op, localLiveVars);
-            varSet.retainAll(localLiveVars);
-            AbstractOperatorWithNestedPlans aonp = (AbstractOperatorWithNestedPlans) op;
-            for (ILogicalPlan p : aonp.getNestedPlans()) {
-                for (Mutable<ILogicalOperator> r : p.getRoots()) {
-                    if (applyRuleDown(r, varSet, context)) {
-                        changed = true;
-                    }
-                    context.addToDontApplySet(this, r.getValue());
-                }
-            }
-        }
-        for (Mutable<ILogicalOperator> i : op.getInputs()) {
-            if (applyRuleDown(i, varSet, context)) {
-                changed = true;
-            }
-            context.addToDontApplySet(this, i.getValue());
-        }
-        return changed;
-    }
-
-    private boolean applies(Mutable<ILogicalOperator> opRef, Set<LogicalVariable> varUsedAbove,
-            IOptimizationContext context) throws AlgebricksException {
-        AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue();
-        if (op1.getOperatorTag() != LogicalOperatorTag.UNNEST) {
-            return false;
-        }
-        UnnestOperator unnest1 = (UnnestOperator) op1;
-        ILogicalExpression expr = unnest1.getExpressionRef().getValue();
-        LogicalVariable unnestedVar;
-        switch (expr.getExpressionTag()) {
-            case VARIABLE:
-                unnestedVar = ((VariableReferenceExpression) expr).getVariableReference();
-                break;
-            case FUNCTION_CALL:
-                if (((AbstractFunctionCallExpression) expr).getFunctionIdentifier() != AsterixBuiltinFunctions.SCAN_COLLECTION) {
-                    return false;
-                }
-                AbstractFunctionCallExpression functionCall = (AbstractFunctionCallExpression) expr;
-                ILogicalExpression functionCallArgExpr = functionCall.getArguments().get(0).getValue();
-                if (functionCallArgExpr.getExpressionTag() != LogicalExpressionTag.VARIABLE) {
-                    return false;
-                }
-                unnestedVar = ((VariableReferenceExpression) functionCallArgExpr).getVariableReference();
-                break;
-            default:
-                return false;
-        }
-        if (varUsedAbove.contains(unnestedVar)) {
-            return false;
-        }
-
-        Mutable<ILogicalOperator> opRef2 = op1.getInputs().get(0);
-        AbstractLogicalOperator r = (AbstractLogicalOperator) opRef2.getValue();
-
-        if (r.getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
-            return false;
-        }
-        AggregateOperator agg = (AggregateOperator) r;
-        if (agg.getVariables().size() > 1) {
-            return false;
-        }
-        LogicalVariable aggVar = agg.getVariables().get(0);
-        ILogicalExpression aggFun = agg.getExpressions().get(0).getValue();
-        if (!aggVar.equals(unnestedVar)
-                || ((AbstractLogicalExpression) aggFun).getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
-            return false;
-        }
-        AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) aggFun;
-        if (!AsterixBuiltinFunctions.LISTIFY.equals(f.getFunctionIdentifier())) {
-            return false;
-        }
-        if (f.getArguments().size() != 1) {
-            return false;
-        }
-        ILogicalExpression arg0 = f.getArguments().get(0).getValue();
-        if (((AbstractLogicalExpression) arg0).getExpressionTag() != LogicalExpressionTag.VARIABLE) {
-            return false;
-        }
-        LogicalVariable paramVar = ((VariableReferenceExpression) arg0).getVariableReference();
-
-        ArrayList<LogicalVariable> assgnVars = new ArrayList<LogicalVariable>(1);
-        assgnVars.add(unnest1.getVariable());
-        ArrayList<Mutable<ILogicalExpression>> assgnExprs = new ArrayList<Mutable<ILogicalExpression>>(1);
-        assgnExprs.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(paramVar)));
-        AssignOperator assign = new AssignOperator(assgnVars, assgnExprs);
-        assign.getInputs().add(agg.getInputs().get(0));
-        context.computeAndSetTypeEnvironmentForOperator(assign);
-        LogicalVariable posVar = unnest1.getPositionalVariable();
-
-        if (posVar == null) {
-            opRef.setValue(assign);
-        } else {
-            ArrayList<LogicalVariable> raggVars = new ArrayList<LogicalVariable>(1);
-            raggVars.add(posVar);
-            ArrayList<Mutable<ILogicalExpression>> rAggExprs = new ArrayList<Mutable<ILogicalExpression>>(1);
-            StatefulFunctionCallExpression tidFun = new StatefulFunctionCallExpression(
-                    FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.TID), UnpartitionedPropertyComputer.INSTANCE);
-            rAggExprs.add(new MutableObject<ILogicalExpression>(tidFun));
-            RunningAggregateOperator rAgg = new RunningAggregateOperator(raggVars, rAggExprs);
-            rAgg.getInputs().add(new MutableObject<ILogicalOperator>(assign));
-            opRef.setValue(rAgg);
-            context.computeAndSetTypeEnvironmentForOperator(rAgg);
-        }
-
-        return true;
-    }
-
-    private boolean appliesForReverseCase(Mutable<ILogicalOperator> opRef, Set<LogicalVariable> varUsedAbove,
-            IOptimizationContext context) throws AlgebricksException {
-        AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue();
-        if (op1.getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
-            return false;
-        }
-        AggregateOperator agg = (AggregateOperator) op1;
-        if (agg.getVariables().size() > 1 || agg.getVariables().size() <= 0) {
-            return false;
-        }
-        LogicalVariable aggVar = agg.getVariables().get(0);
-        ILogicalExpression aggFun = agg.getExpressions().get(0).getValue();
-        AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) aggFun;
-        if (!AsterixBuiltinFunctions.LISTIFY.equals(f.getFunctionIdentifier())) {
-            return false;
-        }
-        if (f.getArguments().size() != 1) {
-            return false;
-        }
-        ILogicalExpression arg0 = f.getArguments().get(0).getValue();
-        if (((AbstractLogicalExpression) arg0).getExpressionTag() != LogicalExpressionTag.VARIABLE) {
-            return false;
-        }
-        LogicalVariable aggInputVar = ((VariableReferenceExpression) arg0).getVariableReference();
-
-        if (agg.getInputs().size() == 0) {
-            return false;
-        }
-        AbstractLogicalOperator op2 = (AbstractLogicalOperator) agg.getInputs().get(0).getValue();
-        if (op2.getOperatorTag() != LogicalOperatorTag.UNNEST) {
-            return false;
-        }
-        UnnestOperator unnest = (UnnestOperator) op2;
-        if (unnest.getPositionalVariable() != null) {
-            return false;
-        }
-        if (!unnest.getVariable().equals(aggInputVar)) {
-            return false;
-        }
-        List<LogicalVariable> unnestSource = new ArrayList<LogicalVariable>();
-        VariableUtilities.getUsedVariables(unnest, unnestSource);
-        if (unnestSource.size() > 1 || unnestSource.size() <= 0) {
-            return false;
-        }
-        ArrayList<LogicalVariable> assgnVars = new ArrayList<LogicalVariable>(1);
-        assgnVars.add(aggVar);
-        ArrayList<Mutable<ILogicalExpression>> assgnExprs = new ArrayList<Mutable<ILogicalExpression>>(1);
-        assgnExprs.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(unnestSource.get(0))));
-        AssignOperator assign = new AssignOperator(assgnVars, assgnExprs);
-        assign.getInputs().add(unnest.getInputs().get(0));
-        context.computeAndSetTypeEnvironmentForOperator(assign);
-        opRef.setValue(assign);
-        return true;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/34d81630/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/RemoveRedundantSelectRule.java
----------------------------------------------------------------------
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/RemoveRedundantSelectRule.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/RemoveRedundantSelectRule.java
deleted file mode 100644
index 2ed2d2e..0000000
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/RemoveRedundantSelectRule.java
+++ /dev/null
@@ -1,78 +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.asterix.optimizer.rules;
-
-import org.apache.commons.lang3.mutable.Mutable;
-
-import edu.uci.ics.asterix.om.base.ABoolean;
-import edu.uci.ics.asterix.om.constants.AsterixConstantValue;
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.IOptimizationContext;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.ConstantExpression;
-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;
-
-/**
- * This rule removes redundant select operator, e.g., select operators
- * in which the condition is TRUE.
- * Note that the ConstantFoldingRule will evaluate the condition expression
- * during compile time if it is possible.
- *
- * @author yingyib
- */
-public class RemoveRedundantSelectRule 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.SELECT) {
-            return false;
-        }
-        SelectOperator select = (SelectOperator) op;
-        ILogicalExpression cond = select.getCondition().getValue();
-        if (alwaysHold(cond)) {
-            opRef.setValue(select.getInputs().get(0).getValue());
-            return true;
-        }
-        return false;
-    }
-
-    /**
-     * Whether the condition expression always returns true.
-     * 
-     * @param cond
-     * @return true if the condition always holds; false otherwise.
-     */
-    private boolean alwaysHold(ILogicalExpression cond) {
-        if (cond.equals(ConstantExpression.TRUE)) {
-            return true;
-        }
-        if (cond.equals(new ConstantExpression(new AsterixConstantValue(ABoolean.TRUE)))) {
-            return true;
-        }
-        return false;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/34d81630/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/RemoveSortInFeedIngestionRule.java
----------------------------------------------------------------------
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/RemoveSortInFeedIngestionRule.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/RemoveSortInFeedIngestionRule.java
deleted file mode 100644
index 08daa40..0000000
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/RemoveSortInFeedIngestionRule.java
+++ /dev/null
@@ -1,72 +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.asterix.optimizer.rules;
-
-import org.apache.commons.lang3.mutable.Mutable;
-
-import edu.uci.ics.asterix.metadata.declared.AqlDataSource;
-import edu.uci.ics.asterix.metadata.declared.AqlDataSource.AqlDataSourceType;
-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.operators.logical.AbstractLogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.DataSourceScanOperator;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-public class RemoveSortInFeedIngestionRule 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.INSERT_DELETE) {
-            return false;
-        }
-
-        AbstractLogicalOperator insertOp = op;
-        AbstractLogicalOperator descendantOp = (AbstractLogicalOperator) op.getInputs().get(0).getValue();
-        boolean isSourceAFeed = false;
-        while (descendantOp != null) {
-            if (descendantOp.getOperatorTag() == LogicalOperatorTag.DATASOURCESCAN) {
-                AqlDataSource dataSource = (AqlDataSource) ((DataSourceScanOperator) descendantOp).getDataSource();
-                if (dataSource.getDatasourceType().equals(AqlDataSourceType.FEED)) {
-                    isSourceAFeed = true;
-                }
-                break;
-            }
-            if (descendantOp.getInputs().isEmpty()) {
-                break;
-            }
-            descendantOp = (AbstractLogicalOperator) descendantOp.getInputs().get(0).getValue();
-        }
-
-        if (isSourceAFeed) {
-            AbstractLogicalOperator prevOp = (AbstractLogicalOperator) insertOp.getInputs().get(0).getValue();
-            if (prevOp.getOperatorTag() == LogicalOperatorTag.ORDER) {
-                insertOp.getInputs().set(0, prevOp.getInputs().get(0));
-                return true;
-            }
-        }
-
-        return false;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/34d81630/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/RemoveUnusedOneToOneEquiJoinRule.java
----------------------------------------------------------------------
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/RemoveUnusedOneToOneEquiJoinRule.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/RemoveUnusedOneToOneEquiJoinRule.java
deleted file mode 100644
index d8a8a02..0000000
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/RemoveUnusedOneToOneEquiJoinRule.java
+++ /dev/null
@@ -1,213 +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.asterix.optimizer.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 edu.uci.ics.asterix.metadata.declared.DatasetDataSource;
-import edu.uci.ics.asterix.metadata.entities.InternalDatasetDetails;
-import edu.uci.ics.asterix.metadata.utils.DatasetUtils;
-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.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.DataSourceScanOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.visitors.VariableUtilities;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-/**
- * Removes join operators for which all of the following conditions are true:
- * 1. The live variables of one input branch of the join are not used in the upstream plan
- * 2. The join is an inner equi join
- * 3. The join condition only uses variables that correspond to primary keys of the same dataset
- * Notice that the last condition implies a 1:1 join, i.e., the join does not change the result cardinality.
- * Joins that satisfy the above conditions may be introduced by other rules
- * which use surrogate optimizations. Such an optimization aims to reduce data copies and communication costs by
- * using the primary keys as surrogates for the desired data items. Typically,
- * such a surrogate-based plan introduces a top-level join to finally resolve
- * the surrogates to the desired data items.
- * In case the upstream plan does not require the original data items at all, such a top-level join is unnecessary.
- * The purpose of this rule is to remove such unnecessary joins.
- */
-public class RemoveUnusedOneToOneEquiJoinRule implements IAlgebraicRewriteRule {
-
-    private final Set<LogicalVariable> parentsUsedVars = new HashSet<LogicalVariable>();
-    private final List<LogicalVariable> usedVars = new ArrayList<LogicalVariable>();
-    private final List<LogicalVariable> liveVars = new ArrayList<LogicalVariable>();
-    private final List<LogicalVariable> pkVars = new ArrayList<LogicalVariable>();
-    private final List<DataSourceScanOperator> dataScans = new ArrayList<DataSourceScanOperator>();
-    private boolean hasRun = false;
-
-    @Override
-    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
-        if (hasRun) {
-            return false;
-        }
-        hasRun = true;
-        if (removeUnusedJoin(opRef)) {
-            return true;
-        }
-        return false;
-    }
-
-    @Override
-    public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
-            throws AlgebricksException {
-        return false;
-    }
-
-    private boolean removeUnusedJoin(Mutable<ILogicalOperator> opRef) throws AlgebricksException {
-        AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
-        boolean modified = false;
-
-        usedVars.clear();
-        VariableUtilities.getUsedVariables(op, usedVars);
-        // Propagate used variables from parents downwards.
-        parentsUsedVars.addAll(usedVars);
-
-        int numInputs = op.getInputs().size();
-        for (int i = 0; i < numInputs; i++) {
-            Mutable<ILogicalOperator> childOpRef = op.getInputs().get(i);
-            int unusedJoinBranchIndex = removeJoinFromInputBranch(childOpRef);
-            if (unusedJoinBranchIndex >= 0) {
-                int usedBranchIndex = (unusedJoinBranchIndex == 0) ? 1 : 0;
-                // Remove join at input index i, by hooking up op's input i with 
-                // the join's branch at unusedJoinBranchIndex.
-                AbstractBinaryJoinOperator joinOp = (AbstractBinaryJoinOperator) childOpRef.getValue();
-                op.getInputs().set(i, joinOp.getInputs().get(usedBranchIndex));
-                modified = true;
-            }
-            // Descend into children.
-            if (removeUnusedJoin(childOpRef)) {
-                modified = true;
-            }
-        }
-        return modified;
-    }
-
-    private int removeJoinFromInputBranch(Mutable<ILogicalOperator> opRef) throws AlgebricksException {
-        AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
-        if (op.getOperatorTag() != LogicalOperatorTag.INNERJOIN) {
-            return -1;
-        }
-
-        AbstractBinaryJoinOperator joinOp = (AbstractBinaryJoinOperator) op;
-        // Make sure the join is an equi-join.
-        if (!isEquiJoin(joinOp.getCondition())) {
-            return -1;
-        }
-
-        int unusedJoinBranchIndex = -1;
-        for (int i = 0; i < joinOp.getInputs().size(); i++) {
-            liveVars.clear();
-            VariableUtilities.getLiveVariables(joinOp.getInputs().get(i).getValue(), liveVars);
-            liveVars.retainAll(parentsUsedVars);
-            if (liveVars.isEmpty()) {
-                // None of the live variables from this branch are used by its parents.
-                unusedJoinBranchIndex = i;
-                break;
-            }
-        }
-        if (unusedJoinBranchIndex < 0) {
-            // The variables from both branches are used in the upstream plan. We cannot remove this join.
-            return -1;
-        }
-
-        // Check whether one of the join branches is unused.
-        usedVars.clear();
-        VariableUtilities.getUsedVariables(joinOp, usedVars);
-
-        // Check whether all used variables originate from primary keys of exactly the same dataset.
-        // Collect a list of datascans whose primary key variables are used in the join condition.
-        gatherProducingDataScans(opRef, usedVars, dataScans);
-
-        // Check that all datascans scan the same dataset, and that the join condition
-        // only used primary key variables of those datascans.
-        for (int i = 0; i < dataScans.size(); i++) {
-            if (i > 0) {
-                DatasetDataSource prevAqlDataSource = (DatasetDataSource) dataScans.get(i - 1).getDataSource();
-                DatasetDataSource currAqlDataSource = (DatasetDataSource) dataScans.get(i).getDataSource();
-                if (!prevAqlDataSource.getDataset().equals(currAqlDataSource.getDataset())) {
-                    return -1;
-                }
-            }
-            // Remove from the used variables all the primary key vars of this dataset.
-            fillPKVars(dataScans.get(i), pkVars);
-            usedVars.removeAll(pkVars);
-        }
-        if (!usedVars.isEmpty()) {
-            // The join condition also uses some other variables that are not primary
-            // keys from datasource scans of the same dataset.
-            return -1;
-        }
-        return unusedJoinBranchIndex;
-    }
-
-    private void gatherProducingDataScans(Mutable<ILogicalOperator> opRef, List<LogicalVariable> joinUsedVars,
-            List<DataSourceScanOperator> dataScans) {
-        AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
-        if (op.getOperatorTag() != LogicalOperatorTag.DATASOURCESCAN) {
-            for (Mutable<ILogicalOperator> inputOp : op.getInputs()) {
-                gatherProducingDataScans(inputOp, joinUsedVars, dataScans);
-            }
-            return;
-        }
-        DataSourceScanOperator dataScan = (DataSourceScanOperator) op;
-        fillPKVars(dataScan, pkVars);
-        // Check if join uses all PK vars.
-        if (joinUsedVars.containsAll(pkVars)) {
-            dataScans.add(dataScan);
-        }
-    }
-
-    private void fillPKVars(DataSourceScanOperator dataScan, List<LogicalVariable> pkVars) {
-        pkVars.clear();
-        DatasetDataSource datasetDataSource = (DatasetDataSource) dataScan.getDataSource();
-        pkVars.clear();
-        if (datasetDataSource.getDataset().getDatasetDetails() instanceof InternalDatasetDetails) {
-            int numPKs = DatasetUtils.getPartitioningKeys(datasetDataSource.getDataset()).size();
-            for (int i = 0; i < numPKs; i++) {
-                pkVars.add(dataScan.getVariables().get(i));
-            }
-        }
-    }
-
-    private boolean isEquiJoin(Mutable<ILogicalExpression> conditionExpr) {
-        AbstractLogicalExpression expr = (AbstractLogicalExpression) conditionExpr.getValue();
-        if (expr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
-            AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr;
-            FunctionIdentifier funcIdent = funcExpr.getFunctionIdentifier();
-            if (funcIdent != AlgebricksBuiltinFunctions.AND && funcIdent != AlgebricksBuiltinFunctions.EQ) {
-                return false;
-            }
-        }
-        return true;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/34d81630/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/ReplaceSinkOpWithCommitOpRule.java
----------------------------------------------------------------------
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/ReplaceSinkOpWithCommitOpRule.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/ReplaceSinkOpWithCommitOpRule.java
deleted file mode 100644
index 8de761a..0000000
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/ReplaceSinkOpWithCommitOpRule.java
+++ /dev/null
@@ -1,116 +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.asterix.optimizer.rules;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.commons.lang3.mutable.Mutable;
-
-import edu.uci.ics.asterix.algebra.operators.CommitOperator;
-import edu.uci.ics.asterix.algebra.operators.physical.CommitPOperator;
-import edu.uci.ics.asterix.common.transactions.JobId;
-import edu.uci.ics.asterix.metadata.declared.AqlMetadataProvider;
-import edu.uci.ics.asterix.metadata.declared.DatasetDataSource;
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.IOptimizationContext;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalVariable;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ExtensionOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.IndexInsertDeleteOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.InsertDeleteOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.SinkOperator;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-
-public class ReplaceSinkOpWithCommitOpRule implements IAlgebraicRewriteRule {
-
-    @Override
-    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
-        // TODO Auto-generated method stub
-        return false;
-    }
-
-    @Override
-    public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
-            throws AlgebricksException {
-
-        AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
-        if (op.getOperatorTag() != LogicalOperatorTag.SINK) {
-            return false;
-        }
-        SinkOperator sinkOperator = (SinkOperator) op;
-
-        List<Mutable<ILogicalExpression>> primaryKeyExprs = null;
-        int datasetId = 0;
-        AbstractLogicalOperator descendantOp = (AbstractLogicalOperator) sinkOperator.getInputs().get(0).getValue();
-        while (descendantOp != null) {
-            if (descendantOp.getOperatorTag() == LogicalOperatorTag.INDEX_INSERT_DELETE) {
-                IndexInsertDeleteOperator indexInsertDeleteOperator = (IndexInsertDeleteOperator) descendantOp;
-                if (!indexInsertDeleteOperator.isBulkload()) {
-                    primaryKeyExprs = indexInsertDeleteOperator.getPrimaryKeyExpressions();
-                    datasetId = ((DatasetDataSource) indexInsertDeleteOperator.getDataSourceIndex().getDataSource())
-                            .getDataset().getDatasetId();
-                    break;
-                }
-            } else if (descendantOp.getOperatorTag() == LogicalOperatorTag.INSERT_DELETE) {
-                InsertDeleteOperator insertDeleteOperator = (InsertDeleteOperator) descendantOp;
-                if (!insertDeleteOperator.isBulkload()) {
-                    primaryKeyExprs = insertDeleteOperator.getPrimaryKeyExpressions();
-                    datasetId = ((DatasetDataSource) insertDeleteOperator.getDataSource()).getDataset().getDatasetId();
-                    break;
-                }
-            }
-            if (descendantOp.getInputs().size() < 1) {
-                break;
-            }
-            descendantOp = (AbstractLogicalOperator) descendantOp.getInputs().get(0).getValue();
-        }
-
-        if (primaryKeyExprs == null) {
-            return false;
-        }
-
-        //copy primaryKeyExprs
-        List<LogicalVariable> primaryKeyLogicalVars = new ArrayList<LogicalVariable>();
-        for (Mutable<ILogicalExpression> expr : primaryKeyExprs) {
-            VariableReferenceExpression varRefExpr = (VariableReferenceExpression) expr.getValue();
-            primaryKeyLogicalVars.add(new LogicalVariable(varRefExpr.getVariableReference().getId()));
-        }
-
-        //get JobId(TransactorId)
-        AqlMetadataProvider mp = (AqlMetadataProvider) context.getMetadataProvider();
-        JobId jobId = mp.getJobId();
-
-        //create the logical and physical operator
-        CommitOperator commitOperator = new CommitOperator(primaryKeyLogicalVars);
-        CommitPOperator commitPOperator = new CommitPOperator(jobId, datasetId, primaryKeyLogicalVars);
-        commitOperator.setPhysicalOperator(commitPOperator);
-
-        //create ExtensionOperator and put the commitOperator in it.
-        ExtensionOperator extensionOperator = new ExtensionOperator(commitOperator);
-        extensionOperator.setPhysicalOperator(commitPOperator);
-
-        //update plan link
-        extensionOperator.getInputs().add(sinkOperator.getInputs().get(0));
-        context.computeAndSetTypeEnvironmentForOperator(extensionOperator);
-        opRef.setValue(extensionOperator);
-        return true;
-    }
-
-}


Mime
View raw message