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

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

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/jobgen/impl/PlanCompiler.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/jobgen/impl/PlanCompiler.java b/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/jobgen/impl/PlanCompiler.java
deleted file mode 100644
index 3af57ad..0000000
--- a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/jobgen/impl/PlanCompiler.java
+++ /dev/null
@@ -1,125 +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.core.jobgen.impl;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-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.IHyracksJobBuilder;
-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.LogicalOperatorTag;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.IOperatorSchema;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ReplicateOperator;
-import edu.uci.ics.hyracks.api.job.IJobletEventListenerFactory;
-import edu.uci.ics.hyracks.api.job.IOperatorDescriptorRegistry;
-import edu.uci.ics.hyracks.api.job.JobSpecification;
-
-public class PlanCompiler {
-    private JobGenContext context;
-    private Map<Mutable<ILogicalOperator>, List<Mutable<ILogicalOperator>>> operatorVisitedToParents = new HashMap<Mutable<ILogicalOperator>, List<Mutable<ILogicalOperator>>>();
-
-    public PlanCompiler(JobGenContext context) {
-        this.context = context;
-    }
-
-    public JobGenContext getContext() {
-        return context;
-    }
-
-    public JobSpecification compilePlan(ILogicalPlan plan, IOperatorSchema outerPlanSchema,
-            IJobletEventListenerFactory jobEventListenerFactory) throws AlgebricksException {
-        JobSpecification spec = new JobSpecification(context.getFrameSize());
-        if (jobEventListenerFactory != null) {
-            spec.setJobletEventListenerFactory(jobEventListenerFactory);
-        }
-        List<ILogicalOperator> rootOps = new ArrayList<ILogicalOperator>();
-        IHyracksJobBuilder builder = new JobBuilder(spec, context.getClusterLocations());
-        for (Mutable<ILogicalOperator> opRef : plan.getRoots()) {
-            compileOpRef(opRef, spec, builder, outerPlanSchema);
-            rootOps.add(opRef.getValue());
-        }
-        reviseEdges(builder);
-        operatorVisitedToParents.clear();
-        builder.buildSpec(rootOps);
-        spec.setConnectorPolicyAssignmentPolicy(new ConnectorPolicyAssignmentPolicy());
-        // Do not do activity cluster planning because it is slow on large clusters
-        spec.setUseConnectorPolicyForScheduling(false);
-        return spec;
-    }
-
-    private void compileOpRef(Mutable<ILogicalOperator> opRef, IOperatorDescriptorRegistry spec,
-            IHyracksJobBuilder builder, IOperatorSchema outerPlanSchema) throws AlgebricksException {
-        ILogicalOperator op = opRef.getValue();
-        int n = op.getInputs().size();
-        IOperatorSchema[] schemas = new IOperatorSchema[n];
-        int i = 0;
-        for (Mutable<ILogicalOperator> opRef2 : op.getInputs()) {
-            List<Mutable<ILogicalOperator>> parents = operatorVisitedToParents.get(opRef2);
-            if (parents == null) {
-                parents = new ArrayList<Mutable<ILogicalOperator>>();
-                operatorVisitedToParents.put(opRef2, parents);
-                parents.add(opRef);
-                compileOpRef(opRef2, spec, builder, outerPlanSchema);
-                schemas[i++] = context.getSchema(opRef2.getValue());
-            } else {
-                if (!parents.contains(opRef))
-                    parents.add(opRef);
-                schemas[i++] = context.getSchema(opRef2.getValue());
-                continue;
-            }
-        }
-
-        IOperatorSchema opSchema = new OperatorSchemaImpl();
-        context.putSchema(op, opSchema);
-        op.getVariablePropagationPolicy().propagateVariables(opSchema, schemas);
-        op.contributeRuntimeOperator(builder, context, opSchema, schemas, outerPlanSchema);
-    }
-
-    private void reviseEdges(IHyracksJobBuilder builder) {
-        /**
-         * revise the edges for the case of replicate operator
-         */
-        for (Entry<Mutable<ILogicalOperator>, List<Mutable<ILogicalOperator>>> entry : operatorVisitedToParents
-                .entrySet()) {
-            Mutable<ILogicalOperator> child = entry.getKey();
-            List<Mutable<ILogicalOperator>> parents = entry.getValue();
-            if (parents.size() > 1) {
-                if (child.getValue().getOperatorTag() == LogicalOperatorTag.REPLICATE) {
-                    ReplicateOperator rop = (ReplicateOperator) child.getValue();
-                    if (rop.isBlocker()) {
-                        // make the order of the graph edges consistent with the order of rop's outputs
-                        List<Mutable<ILogicalOperator>> outputs = rop.getOutputs();
-                        for (Mutable<ILogicalOperator> parent : parents) {
-                            builder.contributeGraphEdge(child.getValue(), outputs.indexOf(parent), parent.getValue(), 0);
-                        }
-                    } else {
-                        int i = 0;
-                        for (Mutable<ILogicalOperator> parent : parents) {
-                            builder.contributeGraphEdge(child.getValue(), i, parent.getValue(), 0);
-                            i++;
-                        }
-                    }
-                }
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/AbstractRuleController.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/AbstractRuleController.java b/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/AbstractRuleController.java
deleted file mode 100644
index e7b469a..0000000
--- a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/AbstractRuleController.java
+++ /dev/null
@@ -1,130 +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.core.rewriter.base;
-
-import java.util.Collection;
-import java.util.logging.Level;
-
-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.operators.logical.AbstractLogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractOperatorWithNestedPlans;
-import edu.uci.ics.hyracks.algebricks.core.algebra.prettyprint.LogicalOperatorPrettyPrintVisitor;
-import edu.uci.ics.hyracks.algebricks.core.algebra.prettyprint.PlanPrettyPrinter;
-import edu.uci.ics.hyracks.algebricks.core.config.AlgebricksConfig;
-
-public abstract class AbstractRuleController {
-
-    protected IOptimizationContext context;
-
-    public AbstractRuleController() {
-    }
-
-    public void setContext(IOptimizationContext context) {
-        this.context = context;
-    }
-
-    /**
-     * Each rewriting strategy may differ in the
-     * 
-     * @param root
-     * @param ruleClasses
-     * @return true iff one of the rules in the collection fired
-     */
-    public abstract boolean rewriteWithRuleCollection(Mutable<ILogicalOperator> root,
-            Collection<IAlgebraicRewriteRule> rules) throws AlgebricksException;
-
-    /**
-     * @param opRef
-     * @param rule
-     * @return true if any rewrite was fired, either on opRef or any operator
-     *         under it.
-     */
-    protected boolean rewriteOperatorRef(Mutable<ILogicalOperator> opRef, IAlgebraicRewriteRule rule)
-            throws AlgebricksException {
-        return rewriteOperatorRef(opRef, rule, true, false);
-    }
-
-    private String getPlanString(Mutable<ILogicalOperator> opRef) throws AlgebricksException {
-        if (AlgebricksConfig.ALGEBRICKS_LOGGER.isLoggable(Level.FINE)) {
-            StringBuilder sb = new StringBuilder();
-            LogicalOperatorPrettyPrintVisitor pvisitor = context.getPrettyPrintVisitor();
-            PlanPrettyPrinter.printOperator((AbstractLogicalOperator) opRef.getValue(), sb, pvisitor, 0);
-            return sb.toString();
-        }
-        return null;
-    }
-
-    private void printRuleApplication(IAlgebraicRewriteRule rule, String beforePlan, String afterPlan)
-            throws AlgebricksException {
-        if (AlgebricksConfig.ALGEBRICKS_LOGGER.isLoggable(Level.FINE)) {
-            AlgebricksConfig.ALGEBRICKS_LOGGER.fine(">>>> Rule " + rule.getClass() + " fired.\n");
-            AlgebricksConfig.ALGEBRICKS_LOGGER.fine(">>>> Before plan\n" + beforePlan + "\n");
-            AlgebricksConfig.ALGEBRICKS_LOGGER.fine(">>>> After plan\n" + afterPlan + "\n");
-        }
-    }
-
-    protected boolean rewriteOperatorRef(Mutable<ILogicalOperator> opRef, IAlgebraicRewriteRule rule,
-            boolean enterNestedPlans, boolean fullDFS) throws AlgebricksException {
-
-        String preBeforePlan = getPlanString(opRef);
-        if (rule.rewritePre(opRef, context)) {
-            String preAfterPlan = getPlanString(opRef);
-            printRuleApplication(rule, preBeforePlan, preAfterPlan);
-            return true;
-        }
-        boolean rewritten = false;
-        AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
-
-        for (Mutable<ILogicalOperator> inp : op.getInputs()) {
-            if (rewriteOperatorRef(inp, rule, enterNestedPlans, fullDFS)) {
-                rewritten = true;
-                if (!fullDFS) {
-                    break;
-                }
-            }
-        }
-
-        if (op.hasNestedPlans() && enterNestedPlans) {
-            AbstractOperatorWithNestedPlans o2 = (AbstractOperatorWithNestedPlans) op;
-            for (ILogicalPlan p : o2.getNestedPlans()) {
-                for (Mutable<ILogicalOperator> r : p.getRoots()) {
-                    if (rewriteOperatorRef(r, rule, enterNestedPlans, fullDFS)) {
-                        rewritten = true;
-                        if (!fullDFS) {
-                            break;
-                        }
-                    }
-                }
-                if (rewritten && !fullDFS) {
-                    break;
-                }
-            }
-        }
-
-        String postBeforePlan = getPlanString(opRef);
-        if (rule.rewritePost(opRef, context)) {
-            String postAfterPlan = getPlanString(opRef);
-            printRuleApplication(rule, postBeforePlan, postAfterPlan);
-            return true;
-        }
-
-        return rewritten;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/AlgebricksOptimizationContext.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/AlgebricksOptimizationContext.java b/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/AlgebricksOptimizationContext.java
deleted file mode 100644
index 361dad3..0000000
--- a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/AlgebricksOptimizationContext.java
+++ /dev/null
@@ -1,299 +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.core.rewriter.base;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.EquivalenceClass;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.IOptimizationContext;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalVariable;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IExpressionEvalSizeComputer;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IExpressionTypeComputer;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IMergeAggregationExpressionFactory;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.INullableTypeComputer;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IVariableEvalSizeEnvironment;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
-import edu.uci.ics.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
-import edu.uci.ics.hyracks.algebricks.core.algebra.prettyprint.LogicalOperatorPrettyPrintVisitor;
-import edu.uci.ics.hyracks.algebricks.core.algebra.properties.FunctionalDependency;
-import edu.uci.ics.hyracks.algebricks.core.algebra.properties.ILogicalPropertiesVector;
-
-public class AlgebricksOptimizationContext implements IOptimizationContext {
-
-    private int varCounter;
-    private final IExpressionEvalSizeComputer expressionEvalSizeComputer;
-    private final IMergeAggregationExpressionFactory mergeAggregationExpressionFactory;
-    private final PhysicalOptimizationConfig physicalOptimizationConfig;
-    private final IVariableEvalSizeEnvironment varEvalSizeEnv = new IVariableEvalSizeEnvironment() {
-
-        Map<LogicalVariable, Integer> varSizeMap = new HashMap<LogicalVariable, Integer>();
-
-        @Override
-        public void setVariableEvalSize(LogicalVariable var, int size) {
-            varSizeMap.put(var, size);
-        }
-
-        @Override
-        public int getVariableEvalSize(LogicalVariable var) {
-            return varSizeMap.get(var);
-        }
-    };
-
-    private Map<ILogicalOperator, IVariableTypeEnvironment> typeEnvMap = new HashMap<ILogicalOperator, IVariableTypeEnvironment>();
-
-    private Map<ILogicalOperator, HashSet<ILogicalOperator>> alreadyCompared = new HashMap<ILogicalOperator, HashSet<ILogicalOperator>>();
-    private Map<IAlgebraicRewriteRule, HashSet<ILogicalOperator>> dontApply = new HashMap<IAlgebraicRewriteRule, HashSet<ILogicalOperator>>();
-    private Map<LogicalVariable, FunctionalDependency> recordToPrimaryKey = new HashMap<LogicalVariable, FunctionalDependency>();
-
-    @SuppressWarnings("unchecked")
-    private IMetadataProvider metadataProvider;
-    private HashSet<LogicalVariable> notToBeInlinedVars = new HashSet<LogicalVariable>();
-
-    protected final Map<ILogicalOperator, List<FunctionalDependency>> fdGlobalMap = new HashMap<ILogicalOperator, List<FunctionalDependency>>();
-    protected final Map<ILogicalOperator, Map<LogicalVariable, EquivalenceClass>> eqClassGlobalMap = new HashMap<ILogicalOperator, Map<LogicalVariable, EquivalenceClass>>();
-
-    protected final Map<ILogicalOperator, ILogicalPropertiesVector> logicalProps = new HashMap<ILogicalOperator, ILogicalPropertiesVector>();
-    private final IExpressionTypeComputer expressionTypeComputer;
-    private final INullableTypeComputer nullableTypeComputer;
-    private final LogicalOperatorPrettyPrintVisitor prettyPrintVisitor;
-
-    public AlgebricksOptimizationContext(int varCounter, IExpressionEvalSizeComputer expressionEvalSizeComputer,
-            IMergeAggregationExpressionFactory mergeAggregationExpressionFactory,
-            IExpressionTypeComputer expressionTypeComputer, INullableTypeComputer nullableTypeComputer,
-            PhysicalOptimizationConfig physicalOptimizationConfig) {
-        this(varCounter, expressionEvalSizeComputer, mergeAggregationExpressionFactory, expressionTypeComputer,
-                nullableTypeComputer, physicalOptimizationConfig, new LogicalOperatorPrettyPrintVisitor());
-    }
-
-    public AlgebricksOptimizationContext(int varCounter, IExpressionEvalSizeComputer expressionEvalSizeComputer,
-            IMergeAggregationExpressionFactory mergeAggregationExpressionFactory,
-            IExpressionTypeComputer expressionTypeComputer, INullableTypeComputer nullableTypeComputer,
-            PhysicalOptimizationConfig physicalOptimizationConfig, LogicalOperatorPrettyPrintVisitor prettyPrintVisitor) {
-        this.varCounter = varCounter;
-        this.expressionEvalSizeComputer = expressionEvalSizeComputer;
-        this.mergeAggregationExpressionFactory = mergeAggregationExpressionFactory;
-        this.expressionTypeComputer = expressionTypeComputer;
-        this.nullableTypeComputer = nullableTypeComputer;
-        this.physicalOptimizationConfig = physicalOptimizationConfig;
-        this.prettyPrintVisitor = prettyPrintVisitor;
-    }
-
-    public int getVarCounter() {
-        return varCounter;
-    }
-
-    public void setVarCounter(int varCounter) {
-        this.varCounter = varCounter;
-    }
-
-    public LogicalVariable newVar() {
-        varCounter++;
-        LogicalVariable var = new LogicalVariable(varCounter);
-        return var;
-    }
-
-    @SuppressWarnings("unchecked")
-    public IMetadataProvider getMetadataProvider() {
-        return metadataProvider;
-    }
-
-    public void setMetadataDeclarations(IMetadataProvider<?, ?> metadataProvider) {
-        this.metadataProvider = metadataProvider;
-    }
-
-    public boolean checkIfInDontApplySet(IAlgebraicRewriteRule rule, ILogicalOperator op) {
-        HashSet<ILogicalOperator> operators = dontApply.get(rule);
-        if (operators == null) {
-            return false;
-        } else {
-            return operators.contains(op);
-        }
-    }
-
-    public void addToDontApplySet(IAlgebraicRewriteRule rule, ILogicalOperator op) {
-        HashSet<ILogicalOperator> operators = dontApply.get(rule);
-        if (operators == null) {
-            HashSet<ILogicalOperator> os = new HashSet<ILogicalOperator>();
-            os.add(op);
-            dontApply.put(rule, os);
-        } else {
-            operators.add(op);
-        }
-
-    }
-
-    /*
-     * returns true if op1 and op2 have already been compared
-     */
-    @Override
-    public boolean checkAndAddToAlreadyCompared(ILogicalOperator op1, ILogicalOperator op2) {
-        HashSet<ILogicalOperator> ops = alreadyCompared.get(op1);
-        if (ops == null) {
-            HashSet<ILogicalOperator> newEntry = new HashSet<ILogicalOperator>();
-            newEntry.add(op2);
-            alreadyCompared.put(op1, newEntry);
-            return false;
-        } else {
-            if (ops.contains(op2)) {
-                return true;
-            } else {
-                ops.add(op2);
-                return false;
-            }
-        }
-    }
-    
-    @Override
-    public void removeFromAlreadyCompared(ILogicalOperator op1) {
-        alreadyCompared.remove(op1);
-    }
-
-    public void addNotToBeInlinedVar(LogicalVariable var) {
-        notToBeInlinedVars.add(var);
-    }
-
-    public boolean shouldNotBeInlined(LogicalVariable var) {
-        return notToBeInlinedVars.contains(var);
-    }
-
-    public void addPrimaryKey(FunctionalDependency pk) {
-        assert (pk.getTail().size() == 1);
-        LogicalVariable recordVar = pk.getTail().get(0);
-        recordToPrimaryKey.put(recordVar, pk);
-    }
-
-    public List<LogicalVariable> findPrimaryKey(LogicalVariable recordVar) {
-        FunctionalDependency fd = recordToPrimaryKey.get(recordVar);
-        if (fd == null) {
-            return null;
-        }
-        return fd.getHead();
-    }
-
-    @Override
-    public Map<LogicalVariable, EquivalenceClass> getEquivalenceClassMap(ILogicalOperator op) {
-        return eqClassGlobalMap.get(op);
-    }
-
-    @Override
-    public List<FunctionalDependency> getFDList(ILogicalOperator op) {
-        return fdGlobalMap.get(op);
-    }
-
-    @Override
-    public void putEquivalenceClassMap(ILogicalOperator op, Map<LogicalVariable, EquivalenceClass> eqClassMap) {
-        this.eqClassGlobalMap.put(op, eqClassMap);
-    }
-
-    @Override
-    public void putFDList(ILogicalOperator op, List<FunctionalDependency> fdList) {
-        this.fdGlobalMap.put(op, fdList);
-    }
-
-    @Override
-    public ILogicalPropertiesVector getLogicalPropertiesVector(ILogicalOperator op) {
-        return logicalProps.get(op);
-    }
-
-    @Override
-    public void putLogicalPropertiesVector(ILogicalOperator op, ILogicalPropertiesVector v) {
-        logicalProps.put(op, v);
-    }
-
-    @Override
-    public IExpressionEvalSizeComputer getExpressionEvalSizeComputer() {
-        return expressionEvalSizeComputer;
-    }
-
-    @Override
-    public IVariableEvalSizeEnvironment getVariableEvalSizeEnvironment() {
-        return varEvalSizeEnv;
-    }
-
-    public IMergeAggregationExpressionFactory getMergeAggregationExpressionFactory() {
-        return mergeAggregationExpressionFactory;
-    }
-
-    public PhysicalOptimizationConfig getPhysicalOptimizationConfig() {
-        return physicalOptimizationConfig;
-    }
-
-    @Override
-    public IVariableTypeEnvironment getOutputTypeEnvironment(ILogicalOperator op) {
-        return typeEnvMap.get(op);
-    }
-
-    @Override
-    public void setOutputTypeEnvironment(ILogicalOperator op, IVariableTypeEnvironment env) {
-        typeEnvMap.put(op, env);
-    }
-
-    @Override
-    public IExpressionTypeComputer getExpressionTypeComputer() {
-        return expressionTypeComputer;
-    }
-
-    @Override
-    public INullableTypeComputer getNullableTypeComputer() {
-        return nullableTypeComputer;
-    }
-
-    @Override
-    public void invalidateTypeEnvironmentForOperator(ILogicalOperator op) {
-        typeEnvMap.put(op, null);
-    }
-
-    @Override
-    public void computeAndSetTypeEnvironmentForOperator(ILogicalOperator op) throws AlgebricksException {
-        setOutputTypeEnvironment(op, op.computeOutputTypeEnvironment(this));
-    }
-
-    @Override
-    public void updatePrimaryKeys(Map<LogicalVariable, LogicalVariable> mappedVars) {
-        for (Map.Entry<LogicalVariable, FunctionalDependency> me : recordToPrimaryKey.entrySet()) {
-            FunctionalDependency fd = me.getValue();
-            List<LogicalVariable> hd = new ArrayList<LogicalVariable>();
-            for (LogicalVariable v : fd.getHead()) {
-                LogicalVariable v2 = mappedVars.get(v);
-                if (v2 == null) {
-                    hd.add(v);
-                } else {
-                    hd.add(v2);
-                }
-            }
-            List<LogicalVariable> tl = new ArrayList<LogicalVariable>();
-            for (LogicalVariable v : fd.getTail()) {
-                LogicalVariable v2 = mappedVars.get(v);
-                if (v2 == null) {
-                    tl.add(v);
-                } else {
-                    tl.add(v2);
-                }
-            }
-            me.setValue(new FunctionalDependency(hd, tl));
-        }
-    }
-    
-    @Override
-    public LogicalOperatorPrettyPrintVisitor getPrettyPrintVisitor() {
-        return prettyPrintVisitor;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/HeuristicOptimizer.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/HeuristicOptimizer.java b/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/HeuristicOptimizer.java
deleted file mode 100644
index 17c6900..0000000
--- a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/HeuristicOptimizer.java
+++ /dev/null
@@ -1,125 +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.core.rewriter.base;
-
-import java.util.List;
-
-import org.apache.commons.lang3.mutable.Mutable;
-
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.common.utils.Pair;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.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.PhysicalOperatorTag;
-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.prettyprint.PlanPrettyPrinter;
-import edu.uci.ics.hyracks.algebricks.core.config.AlgebricksConfig;
-
-public class HeuristicOptimizer {
-
-    public static PhysicalOperatorTag[] hyraxOperators = new PhysicalOperatorTag[] {
-            PhysicalOperatorTag.DATASOURCE_SCAN, PhysicalOperatorTag.BTREE_SEARCH,
-            PhysicalOperatorTag.EXTERNAL_GROUP_BY, PhysicalOperatorTag.HASH_GROUP_BY, PhysicalOperatorTag.HDFS_READER,
-            PhysicalOperatorTag.HYBRID_HASH_JOIN, PhysicalOperatorTag.IN_MEMORY_HASH_JOIN,
-            PhysicalOperatorTag.NESTED_LOOP, PhysicalOperatorTag.PRE_SORTED_DISTINCT_BY,
-            PhysicalOperatorTag.PRE_CLUSTERED_GROUP_BY, PhysicalOperatorTag.SPLIT, PhysicalOperatorTag.STABLE_SORT,
-            PhysicalOperatorTag.UNION_ALL };
-    public static PhysicalOperatorTag[] hyraxOperatorsBelowWhichJobGenIsDisabled = new PhysicalOperatorTag[] {};
-
-    public static boolean isHyraxOp(PhysicalOperatorTag opTag) {
-        for (PhysicalOperatorTag t : hyraxOperators) {
-            if (t == opTag) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    private IOptimizationContext context;
-    private List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> logicalRewrites;
-    private List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> physicalRewrites;
-    private ILogicalPlan plan;
-
-    public HeuristicOptimizer(ILogicalPlan plan,
-            List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> logicalRewrites,
-            List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> physicalRewrites,
-            IOptimizationContext context) {
-        this.plan = plan;
-        this.context = context;
-        this.logicalRewrites = logicalRewrites;
-        this.physicalRewrites = physicalRewrites;
-    }
-
-    public void optimize() throws AlgebricksException {
-        if (plan == null) {
-            return;
-        }
-        if (AlgebricksConfig.DEBUG) {
-            AlgebricksConfig.ALGEBRICKS_LOGGER.fine("Starting logical optimizations.\n");
-        }
-
-        StringBuilder sb = new StringBuilder();
-        PlanPrettyPrinter.printPlan(plan, sb, context.getPrettyPrintVisitor(), 0);
-        AlgebricksConfig.ALGEBRICKS_LOGGER.fine("Logical Plan:\n" + sb.toString());
-        runOptimizationSets(plan, logicalRewrites);
-        computeSchemaBottomUpForPlan(plan);
-        runPhysicalOptimizations(plan, physicalRewrites);
-        StringBuilder sb2 = new StringBuilder();
-        PlanPrettyPrinter.printPlan(plan, sb2, context.getPrettyPrintVisitor(), 0);
-        AlgebricksConfig.ALGEBRICKS_LOGGER.info("Optimized Plan:\n" + sb2.toString());
-    }
-
-    private void runOptimizationSets(ILogicalPlan plan,
-            List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> optimSet) throws AlgebricksException {
-        for (Pair<AbstractRuleController, List<IAlgebraicRewriteRule>> ruleList : optimSet) {
-            for (Mutable<ILogicalOperator> r : plan.getRoots()) {
-                ruleList.first.setContext(context);
-                ruleList.first.rewriteWithRuleCollection(r, ruleList.second);
-            }
-        }
-    }
-
-    private static void computeSchemaBottomUpForPlan(ILogicalPlan p) throws AlgebricksException {
-        for (Mutable<ILogicalOperator> r : p.getRoots()) {
-            computeSchemaBottomUpForOp((AbstractLogicalOperator) r.getValue());
-        }
-    }
-
-    private static void computeSchemaBottomUpForOp(AbstractLogicalOperator op) throws AlgebricksException {
-        for (Mutable<ILogicalOperator> i : op.getInputs()) {
-            computeSchemaBottomUpForOp((AbstractLogicalOperator) i.getValue());
-        }
-        if (op.hasNestedPlans()) {
-            AbstractOperatorWithNestedPlans a = (AbstractOperatorWithNestedPlans) op;
-            for (ILogicalPlan p : a.getNestedPlans()) {
-                computeSchemaBottomUpForPlan(p);
-            }
-        }
-        op.recomputeSchema();
-    }
-
-    private void runPhysicalOptimizations(ILogicalPlan plan,
-            List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> physicalRewrites)
-            throws AlgebricksException {
-        if (AlgebricksConfig.DEBUG) {
-            AlgebricksConfig.ALGEBRICKS_LOGGER.fine("Starting physical optimizations.\n");
-        }
-        // PhysicalOptimizationsUtil.computeFDsAndEquivalenceClasses(plan);
-        runOptimizationSets(plan, physicalRewrites);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/IAlgebraicRewriteRule.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/IAlgebraicRewriteRule.java b/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/IAlgebraicRewriteRule.java
deleted file mode 100644
index 6bf0b72..0000000
--- a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/IAlgebraicRewriteRule.java
+++ /dev/null
@@ -1,28 +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.core.rewriter.base;
-
-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;
-
-public interface IAlgebraicRewriteRule {
-    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException;
-
-    public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
-            throws AlgebricksException;
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/IOptimizationContextFactory.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/IOptimizationContextFactory.java b/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/IOptimizationContextFactory.java
deleted file mode 100644
index 70b7f64..0000000
--- a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/IOptimizationContextFactory.java
+++ /dev/null
@@ -1,29 +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.core.rewriter.base;
-
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.IOptimizationContext;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IExpressionEvalSizeComputer;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IExpressionTypeComputer;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IMergeAggregationExpressionFactory;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.INullableTypeComputer;
-
-public interface IOptimizationContextFactory {
-    public IOptimizationContext createOptimizationContext(int varCounter,
-            IExpressionEvalSizeComputer expressionEvalSizeComputer,
-            IMergeAggregationExpressionFactory mergeAggregationExpressionFactory,
-            IExpressionTypeComputer expressionTypeComputer, INullableTypeComputer nullableTypeComputer,
-            PhysicalOptimizationConfig physicalOptimizationConfig);
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/PhysicalOptimizationConfig.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/PhysicalOptimizationConfig.java b/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/PhysicalOptimizationConfig.java
deleted file mode 100644
index 47d2266..0000000
--- a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/rewriter/base/PhysicalOptimizationConfig.java
+++ /dev/null
@@ -1,156 +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.core.rewriter.base;
-
-import java.util.Properties;
-
-public class PhysicalOptimizationConfig {
-    private static final int MB = 1048576;
-    
-    private static final String FRAMESIZE = "FRAMESIZE";
-    private static final String MAX_FRAMES_EXTERNAL_SORT = "MAX_FRAMES_EXTERNAL_SORT";
-    private static final String MAX_FRAMES_EXTERNAL_GROUP_BY = "MAX_FRAMES_EXTERNAL_GROUP_BY";
-    private static final String MAX_FRAMES_LEFT_INPUT_HYBRID_HASH = "MAX_FRAMES_LEFT_INPUT_HYBRID_HASH";
-    private static final String MAX_FRAMES_HYBRID_HASH = "MAX_FRAMES_HYBRID_HASH";
-    private static final String FUDGE_FACTOR = "FUDGE_FACTOR";
-    private static final String MAX_RECORDS_PER_FRAME = "MAX_RECORDS_PER_FRAME";
-    
-    private static final String DEFAULT_HASH_GROUP_TABLE_SIZE = "DEFAULT_HASH_GROUP_TABLE_SIZE";
-    private static final String DEFAULT_EXTERNAL_GROUP_TABLE_SIZE = "DEFAULT_EXTERNAL_GROUP_TABLE_SIZE";
-    private static final String DEFAULT_IN_MEM_HASH_JOIN_TABLE_SIZE = "DEFAULT_IN_MEM_HASH_JOIN_TABLE_SIZE";
-
-    private Properties properties = new Properties();
-
-    public PhysicalOptimizationConfig() {
-        int frameSize = 32768;
-        setInt(FRAMESIZE, frameSize);
-        setInt(MAX_FRAMES_EXTERNAL_SORT, (int) (((long) 32 * MB) / frameSize));
-        setInt(MAX_FRAMES_EXTERNAL_GROUP_BY, (int) (((long) 32 * MB) / frameSize));
-
-        // use http://www.rsok.com/~jrm/printprimes.html to find prime numbers
-        setInt(DEFAULT_HASH_GROUP_TABLE_SIZE, 10485767);
-        setInt(DEFAULT_EXTERNAL_GROUP_TABLE_SIZE, 10485767);
-        setInt(DEFAULT_IN_MEM_HASH_JOIN_TABLE_SIZE, 10485767);
-    }
-
-    public int getFrameSize() {
-        return getInt(FRAMESIZE, 32768);
-    }
-
-    public void setFrameSize(int frameSize) {
-        setInt(FRAMESIZE, frameSize);
-    }
-    
-    public double getFudgeFactor() {
-        return getDouble(FUDGE_FACTOR, 1.3);
-    }
-
-    public void setFudgeFactor(double fudgeFactor) {
-        setDouble(FUDGE_FACTOR, fudgeFactor);
-    }
-    
-    public int getMaxRecordsPerFrame() {
-        return getInt(MAX_RECORDS_PER_FRAME, 512);
-    }
-
-    public void setMaxRecordsPerFrame(int maxRecords) {
-        setInt(MAX_RECORDS_PER_FRAME, maxRecords);
-    }
-
-    public int getMaxFramesLeftInputHybridHash() {
-        int frameSize = getFrameSize();
-        return getInt(MAX_FRAMES_LEFT_INPUT_HYBRID_HASH, (int) (140L * 1024 * MB / frameSize));
-    }
-
-    public void setMaxFramesLeftInputHybridHash(int frameLimit) {
-        setInt(MAX_FRAMES_LEFT_INPUT_HYBRID_HASH, frameLimit);
-    }
-    
-    public int getMaxFramesHybridHash() {
-        int frameSize = getFrameSize();
-        return getInt(MAX_FRAMES_HYBRID_HASH, (int) (64L * MB / frameSize));
-    }
-
-    public void setMaxFramesHybridHash(int frameLimit) {
-        setInt(MAX_FRAMES_HYBRID_HASH, frameLimit);
-    }
-
-    public int getMaxFramesExternalGroupBy() {
-        int frameSize = getFrameSize();
-        return getInt(MAX_FRAMES_EXTERNAL_GROUP_BY, (int) (((long) 256 * MB) / frameSize));
-    }
-
-    public void setMaxFramesExternalGroupBy(int frameLimit) {
-        setInt(MAX_FRAMES_EXTERNAL_GROUP_BY, frameLimit);
-    }
-    
-    public int getMaxFramesExternalSort() {
-        int frameSize = getFrameSize();
-        return getInt(MAX_FRAMES_EXTERNAL_SORT, (int) (((long) 32 * MB) / frameSize));
-    }
-
-    public void setMaxFramesExternalSort(int frameLimit) {
-        setInt(MAX_FRAMES_EXTERNAL_SORT, frameLimit);
-    }
-
-    public int getHashGroupByTableSize() {
-        return getInt(DEFAULT_HASH_GROUP_TABLE_SIZE, 10485767);
-    }
-
-    public void setHashGroupByTableSize(int tableSize) {
-        setInt(DEFAULT_HASH_GROUP_TABLE_SIZE, tableSize);
-    }
-
-    public int getExternalGroupByTableSize() {
-        return getInt(DEFAULT_EXTERNAL_GROUP_TABLE_SIZE, 10485767);
-    }
-
-    public void setExternalGroupByTableSize(int tableSize) {
-        setInt(DEFAULT_EXTERNAL_GROUP_TABLE_SIZE, tableSize);
-    }
-
-    public int getInMemHashJoinTableSize() {
-        return getInt(DEFAULT_IN_MEM_HASH_JOIN_TABLE_SIZE, 10485767);
-    }
-
-    public void setInMemHashJoinTableSize(int tableSize) {
-        setInt(DEFAULT_IN_MEM_HASH_JOIN_TABLE_SIZE, tableSize);
-    }
-
-    private void setInt(String property, int value) {
-        properties.setProperty(property, Integer.toString(value));
-    }
-
-    private int getInt(String property, int defaultValue) {
-        String value = properties.getProperty(property);
-        if (value == null)
-            return defaultValue;
-        else
-            return Integer.parseInt(value);
-    }
-    
-    private void setDouble(String property, double value) {
-        properties.setProperty(property, Double.toString(value));
-    }
-
-    private double getDouble(String property, double defaultValue) {
-        String value = properties.getProperty(property);
-        if (value == null)
-            return defaultValue;
-        else
-            return Double.parseDouble(value);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/utils/Substitution.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/utils/Substitution.java b/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/utils/Substitution.java
deleted file mode 100644
index 3ef4316..0000000
--- a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/utils/Substitution.java
+++ /dev/null
@@ -1,25 +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.core.utils;
-
-public class Substitution<T> {
-    public T substituted;
-    public T substitutedWith;
-
-    public Substitution(T substituted, T substitutedWith) {
-        this.substituted = substituted;
-        this.substitutedWith = substitutedWith;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/Counter.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/Counter.java b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/Counter.java
new file mode 100644
index 0000000..3dd4704
--- /dev/null
+++ b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/Counter.java
@@ -0,0 +1,38 @@
+/*
+ * 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.core.algebra.base;
+
+public class Counter {
+    private int counter = 0;
+
+    public Counter() {
+    }
+
+    public Counter(int initial) {
+        counter = initial;
+    }
+
+    public int get() {
+        return counter;
+    }
+
+    public void inc() {
+        ++counter;
+    }
+
+    public void set(int newStart) {
+        counter = newStart;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/EquivalenceClass.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/EquivalenceClass.java b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/EquivalenceClass.java
new file mode 100644
index 0000000..ab95c9c
--- /dev/null
+++ b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/EquivalenceClass.java
@@ -0,0 +1,143 @@
+/*
+ * 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.core.algebra.base;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import edu.uci.ics.hyracks.algebricks.common.utils.ListSet;
+
+public final class EquivalenceClass {
+    private Set<ILogicalExpression> expressionMembers = new ListSet<ILogicalExpression>();
+    private Set<LogicalVariable> members = new ListSet<LogicalVariable>();
+    private ILogicalExpression constRepresentative;
+    private LogicalVariable variableRepresentative;
+    private boolean representativeIsConst;
+
+    public EquivalenceClass(Collection<LogicalVariable> members, ILogicalExpression constRepresentative) {
+        this.members.addAll(members);
+        this.constRepresentative = constRepresentative;
+        representativeIsConst = true;
+    }
+
+    public EquivalenceClass(Collection<LogicalVariable> members, LogicalVariable variableRepresentative) {
+        this.members.addAll(members);
+        this.variableRepresentative = variableRepresentative;
+        representativeIsConst = false;
+    }
+
+    public EquivalenceClass(Collection<LogicalVariable> members, ILogicalExpression constRepresentative,
+            Collection<ILogicalExpression> expressionMembers) {
+        this(members, constRepresentative);
+        this.expressionMembers.addAll(expressionMembers);
+    }
+
+    public EquivalenceClass(Collection<LogicalVariable> members, LogicalVariable variableRepresentative,
+            Collection<ILogicalExpression> expressionMembers) {
+        this(members, variableRepresentative);
+        this.expressionMembers.addAll(expressionMembers);
+    }
+
+    public boolean representativeIsConst() {
+        return representativeIsConst;
+    }
+
+    public Collection<LogicalVariable> getMembers() {
+        return members;
+    }
+
+    public Collection<ILogicalExpression> getExpressionMembers() {
+        return expressionMembers;
+    }
+
+    public boolean contains(LogicalVariable var) {
+        return members.contains(var);
+    }
+
+    public boolean contains(ILogicalExpression expr) {
+        return expressionMembers.contains(expr);
+    }
+
+    public ILogicalExpression getConstRepresentative() {
+        return constRepresentative;
+    }
+
+    public LogicalVariable getVariableRepresentative() {
+        return variableRepresentative;
+    }
+
+    public void setConstRepresentative(ILogicalExpression constRepresentative) {
+        this.constRepresentative = constRepresentative;
+        this.representativeIsConst = true;
+    }
+
+    public void setVariableRepresentative(LogicalVariable variableRepresentative) {
+        this.variableRepresentative = variableRepresentative;
+        this.representativeIsConst = false;
+    }
+
+    public void merge(EquivalenceClass ec2) {
+        members.addAll(ec2.getMembers());
+        if (!representativeIsConst && ec2.representativeIsConst()) {
+            representativeIsConst = true;
+            constRepresentative = ec2.getConstRepresentative();
+        }
+        expressionMembers.addAll(ec2.getExpressionMembers());
+    }
+
+    public void addMember(LogicalVariable v) {
+        members.add(v);
+    }
+
+    public EquivalenceClass cloneEquivalenceClass() {
+        List<LogicalVariable> membersClone = new LinkedList<LogicalVariable>();
+        membersClone.addAll(members);
+        EquivalenceClass ec;
+        if (representativeIsConst()) {
+            ec = new EquivalenceClass(membersClone, constRepresentative);
+        } else {
+            ec = new EquivalenceClass(membersClone, variableRepresentative);
+        }
+        return ec;
+    }
+
+    @Override
+    public String toString() {
+        return "(<" + (representativeIsConst ? constRepresentative : variableRepresentative) + "> " + members + ";"
+                + expressionMembers + ")";
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (!(obj instanceof EquivalenceClass)) {
+            return false;
+        } else {
+            EquivalenceClass ec = (EquivalenceClass) obj;
+            if (!members.equals(ec.getMembers())) {
+                return false;
+            }
+            if (!expressionMembers.equals(ec.getExpressionMembers())) {
+                return false;
+            }
+            if (representativeIsConst) {
+                return ec.representativeIsConst() && (constRepresentative.equals(ec.getConstRepresentative()));
+            } else {
+                return !ec.representativeIsConst() && (variableRepresentative.equals(ec.getVariableRepresentative()));
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/IHyracksJobBuilder.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/IHyracksJobBuilder.java b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/IHyracksJobBuilder.java
new file mode 100644
index 0000000..4e341e4
--- /dev/null
+++ b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/IHyracksJobBuilder.java
@@ -0,0 +1,58 @@
+/*
+ * 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.core.algebra.base;
+
+import java.util.List;
+
+import edu.uci.ics.hyracks.algebricks.common.constraints.AlgebricksPartitionConstraint;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.runtime.base.IPushRuntimeFactory;
+import edu.uci.ics.hyracks.api.dataflow.IConnectorDescriptor;
+import edu.uci.ics.hyracks.api.dataflow.IOperatorDescriptor;
+import edu.uci.ics.hyracks.api.dataflow.value.RecordDescriptor;
+import edu.uci.ics.hyracks.api.job.JobSpecification;
+
+public interface IHyracksJobBuilder {
+    public enum TargetConstraint {
+        ONE,
+        SAME_COUNT
+    }
+
+    public void contributeHyracksOperator(ILogicalOperator op, IOperatorDescriptor opDesc);
+
+    public void contributeAlgebricksPartitionConstraint(IOperatorDescriptor opDesc, AlgebricksPartitionConstraint apc);
+
+    public void contributeMicroOperator(ILogicalOperator op, IPushRuntimeFactory runtime, RecordDescriptor recDesc);
+
+    public void contributeMicroOperator(ILogicalOperator op, IPushRuntimeFactory runtime, RecordDescriptor recDesc,
+            AlgebricksPartitionConstraint pc);
+
+    /**
+     * inputs are numbered starting from 0
+     */
+    public void contributeGraphEdge(ILogicalOperator src, int srcOutputIndex, ILogicalOperator dest, int destInputIndex);
+
+    public void contributeConnector(ILogicalOperator exchgOp, IConnectorDescriptor conn);
+
+    public void contributeConnectorWithTargetConstraint(ILogicalOperator exchgOp, IConnectorDescriptor conn,
+            TargetConstraint numberOfTargetPartitions);
+
+    public JobSpecification getJobSpec();
+
+    /**
+     * to be called only after all the graph information is added
+     */
+    public void buildSpec(List<ILogicalOperator> roots) throws AlgebricksException;
+}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/ILogicalExpression.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/ILogicalExpression.java b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/ILogicalExpression.java
new file mode 100644
index 0000000..c4ae9bc
--- /dev/null
+++ b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/ILogicalExpression.java
@@ -0,0 +1,72 @@
+/*
+ * 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.core.algebra.base;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang3.mutable.Mutable;
+
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.properties.FunctionalDependency;
+import edu.uci.ics.hyracks.algebricks.core.algebra.visitors.ILogicalExpressionVisitor;
+
+public interface ILogicalExpression {
+
+    public LogicalExpressionTag getExpressionTag();
+
+    public abstract <R, T> R accept(ILogicalExpressionVisitor<R, T> visitor, T arg) throws AlgebricksException;
+
+    public void getUsedVariables(Collection<LogicalVariable> vars);
+
+    public void substituteVar(LogicalVariable v1, LogicalVariable v2);
+
+    // constraints (e.g., FDs, equivalences)
+
+    /**
+     * @param fds
+     *            Output argument: functional dependencies that can be inferred
+     *            from this expression.
+     * @param equivClasses
+     *            Output argument: Equivalence classes that can be inferred from
+     *            this expression.
+     */
+    public void getConstraintsAndEquivClasses(Collection<FunctionalDependency> fds,
+            Map<LogicalVariable, EquivalenceClass> equivClasses);
+
+    /**
+     * @param fds
+     *            Output argument: functional dependencies that can be inferred
+     *            from this expression.
+     * @param outerVars
+     *            Input argument: variables coming from outer branch(es), e.g.,
+     *            the left branch of a left outer join.
+     */
+    public void getConstraintsForOuterJoin(Collection<FunctionalDependency> fds, Collection<LogicalVariable> outerVars);
+
+    /**
+     * @param conjs
+     *            Output argument: a list of expression whose conjunction, in
+     *            any order, can replace the current expression.
+     * @return true if the expression can be broken in at least two conjuncts,
+     *         false otherwise.
+     */
+    public boolean splitIntoConjuncts(List<Mutable<ILogicalExpression>> conjs);
+
+    public abstract ILogicalExpression cloneExpression();
+
+    public boolean isFunctional();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/ILogicalOperator.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/ILogicalOperator.java b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/ILogicalOperator.java
new file mode 100644
index 0000000..d91cac0
--- /dev/null
+++ b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/ILogicalOperator.java
@@ -0,0 +1,102 @@
+/*
+ * 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.core.algebra.base;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang3.mutable.Mutable;
+
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
+import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator.ExecutionMode;
+import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.IOperatorSchema;
+import edu.uci.ics.hyracks.algebricks.core.algebra.properties.IPhysicalPropertiesVector;
+import edu.uci.ics.hyracks.algebricks.core.algebra.properties.PhysicalRequirements;
+import edu.uci.ics.hyracks.algebricks.core.algebra.properties.VariablePropagationPolicy;
+import edu.uci.ics.hyracks.algebricks.core.algebra.typing.ITypingContext;
+import edu.uci.ics.hyracks.algebricks.core.algebra.visitors.ILogicalExpressionReferenceTransform;
+import edu.uci.ics.hyracks.algebricks.core.algebra.visitors.ILogicalOperatorVisitor;
+import edu.uci.ics.hyracks.algebricks.core.jobgen.impl.JobGenContext;
+
+public interface ILogicalOperator {
+
+    public LogicalOperatorTag getOperatorTag();
+
+    public ExecutionMode getExecutionMode();
+
+    public List<Mutable<ILogicalOperator>> getInputs();
+
+    boolean hasInputs();
+
+    public void recomputeSchema() throws AlgebricksException;
+
+    public List<LogicalVariable> getSchema();
+
+    /*
+     * 
+     * support for visitors
+     */
+
+    public boolean acceptExpressionTransform(ILogicalExpressionReferenceTransform transform) throws AlgebricksException;
+
+    public <R, T> R accept(ILogicalOperatorVisitor<R, T> visitor, T arg) throws AlgebricksException;
+
+    public boolean isMap();
+
+    public Map<String, Object> getAnnotations();
+
+    public void removeAnnotation(String annotationName);
+
+    public void contributeRuntimeOperator(IHyracksJobBuilder builder, JobGenContext context,
+            IOperatorSchema propagatedSchema, IOperatorSchema[] inputSchemas, IOperatorSchema outerPlanSchema)
+            throws AlgebricksException;
+
+    // variables
+
+    /**
+     * Get the variable propogation policy from this operator's input to its
+     * output.
+     * 
+     * @return The VariablePropogationPolicy.
+     */
+    public VariablePropagationPolicy getVariablePropagationPolicy();
+
+    public IVariableTypeEnvironment computeOutputTypeEnvironment(ITypingContext ctx) throws AlgebricksException;
+
+    public IVariableTypeEnvironment computeInputTypeEnvironment(ITypingContext ctx) throws AlgebricksException;
+
+    // structural properties
+
+    /**
+     * @return for each child, one vector of required physical properties
+     */
+
+    public PhysicalRequirements getRequiredPhysicalPropertiesForChildren(IPhysicalPropertiesVector requiredProperties);
+
+    /**
+     * @return the physical properties that this operator delivers, based on
+     *         what its children deliver
+     */
+
+    public IPhysicalPropertiesVector getDeliveredPhysicalProperties();
+
+    public void computeDeliveredPhysicalProperties(IOptimizationContext context) throws AlgebricksException;
+
+    /**
+     * Indicates whether the expressions used by this operator must be variable reference expressions.
+     */
+    public boolean requiresVariableReferenceExpressions();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/ILogicalPlan.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/ILogicalPlan.java b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/ILogicalPlan.java
new file mode 100644
index 0000000..6db8f8d
--- /dev/null
+++ b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/ILogicalPlan.java
@@ -0,0 +1,23 @@
+/*
+ * 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.core.algebra.base;
+
+import java.util.List;
+
+import org.apache.commons.lang3.mutable.Mutable;
+
+public interface ILogicalPlan {
+    public List<Mutable<ILogicalOperator>> getRoots();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/ILogicalPlanAndMetadata.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/ILogicalPlanAndMetadata.java b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/ILogicalPlanAndMetadata.java
new file mode 100644
index 0000000..06f619b
--- /dev/null
+++ b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/ILogicalPlanAndMetadata.java
@@ -0,0 +1,26 @@
+/*
+ * 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.core.algebra.base;
+
+import edu.uci.ics.hyracks.algebricks.common.constraints.AlgebricksPartitionConstraint;
+import edu.uci.ics.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
+
+public interface ILogicalPlanAndMetadata {
+    public ILogicalPlan getPlan();
+
+    public IMetadataProvider<?, ?> getMetadataProvider();
+
+    public AlgebricksPartitionConstraint getClusterLocations();
+}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/IOptimizationContext.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/IOptimizationContext.java b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/IOptimizationContext.java
new file mode 100644
index 0000000..9b9273a
--- /dev/null
+++ b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/IOptimizationContext.java
@@ -0,0 +1,90 @@
+/*
+ * 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.core.algebra.base;
+
+import java.util.List;
+import java.util.Map;
+
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IExpressionEvalSizeComputer;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IMergeAggregationExpressionFactory;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IVariableEvalSizeEnvironment;
+import edu.uci.ics.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
+import edu.uci.ics.hyracks.algebricks.core.algebra.prettyprint.LogicalOperatorPrettyPrintVisitor;
+import edu.uci.ics.hyracks.algebricks.core.algebra.properties.FunctionalDependency;
+import edu.uci.ics.hyracks.algebricks.core.algebra.properties.ILogicalPropertiesVector;
+import edu.uci.ics.hyracks.algebricks.core.algebra.typing.ITypingContext;
+import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
+import edu.uci.ics.hyracks.algebricks.core.rewriter.base.PhysicalOptimizationConfig;
+
+public interface IOptimizationContext extends ITypingContext {
+
+    public abstract int getVarCounter();
+
+    public abstract void setVarCounter(int varCounter);
+
+    public abstract LogicalVariable newVar();
+
+    public abstract IMetadataProvider<?, ?> getMetadataProvider();
+
+    public abstract void setMetadataDeclarations(IMetadataProvider<?, ?> metadataProvider);
+
+    public abstract boolean checkIfInDontApplySet(IAlgebraicRewriteRule rule, ILogicalOperator op);
+
+    public abstract void addToDontApplySet(IAlgebraicRewriteRule rule, ILogicalOperator op);
+
+    /*
+     * returns true if op1 and op2 have already been compared
+     */
+    public abstract boolean checkAndAddToAlreadyCompared(ILogicalOperator op1, ILogicalOperator op2);
+    
+    public abstract void removeFromAlreadyCompared(ILogicalOperator op1);
+
+    public abstract void addNotToBeInlinedVar(LogicalVariable var);
+
+    public abstract boolean shouldNotBeInlined(LogicalVariable var);
+
+    public abstract void addPrimaryKey(FunctionalDependency pk);
+
+    public abstract List<LogicalVariable> findPrimaryKey(LogicalVariable recordVar);
+
+    public abstract void putEquivalenceClassMap(ILogicalOperator op, Map<LogicalVariable, EquivalenceClass> eqClassMap);
+
+    public abstract Map<LogicalVariable, EquivalenceClass> getEquivalenceClassMap(ILogicalOperator op);
+
+    public abstract void putFDList(ILogicalOperator op, List<FunctionalDependency> fdList);
+
+    public abstract List<FunctionalDependency> getFDList(ILogicalOperator op);
+
+    public abstract void putLogicalPropertiesVector(ILogicalOperator op, ILogicalPropertiesVector v);
+
+    public abstract ILogicalPropertiesVector getLogicalPropertiesVector(ILogicalOperator op);
+
+    public abstract IExpressionEvalSizeComputer getExpressionEvalSizeComputer();
+
+    public abstract IVariableEvalSizeEnvironment getVariableEvalSizeEnvironment();
+
+    public abstract IMergeAggregationExpressionFactory getMergeAggregationExpressionFactory();
+
+    public abstract PhysicalOptimizationConfig getPhysicalOptimizationConfig();
+
+    public abstract void invalidateTypeEnvironmentForOperator(ILogicalOperator op);
+
+    public abstract void computeAndSetTypeEnvironmentForOperator(ILogicalOperator op) throws AlgebricksException;
+
+    public abstract void updatePrimaryKeys(Map<LogicalVariable, LogicalVariable> mappedVars);
+    
+    public abstract LogicalOperatorPrettyPrintVisitor getPrettyPrintVisitor();
+}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/IPhysicalOperator.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/IPhysicalOperator.java b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/IPhysicalOperator.java
new file mode 100644
index 0000000..dafe300
--- /dev/null
+++ b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/IPhysicalOperator.java
@@ -0,0 +1,75 @@
+/*
+ * 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.core.algebra.base;
+
+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.operators.logical.IOperatorSchema;
+import edu.uci.ics.hyracks.algebricks.core.algebra.properties.IPhysicalPropertiesVector;
+import edu.uci.ics.hyracks.algebricks.core.algebra.properties.PhysicalRequirements;
+import edu.uci.ics.hyracks.algebricks.core.jobgen.impl.JobGenContext;
+
+public interface IPhysicalOperator {
+
+    public PhysicalOperatorTag getOperatorTag();
+
+    /**
+     * @param op
+     *            the logical operator this physical operator annotates
+     * @param reqdByParent
+     *            parent's requirements, which are not enforced for now, as we
+     *            only explore one plan
+     * @return for each child, one vector of required physical properties
+     */
+    public PhysicalRequirements getRequiredPropertiesForChildren(ILogicalOperator op,
+            IPhysicalPropertiesVector reqdByParent);
+
+    /**
+     * @return the physical properties that this operator delivers, based on
+     *         what its children deliver
+     */
+    public IPhysicalPropertiesVector getDeliveredProperties();
+
+    public void computeDeliveredProperties(ILogicalOperator op, IOptimizationContext context)
+            throws AlgebricksException;
+
+    public void contributeRuntimeOperator(IHyracksJobBuilder builder, JobGenContext context, ILogicalOperator op,
+            IOperatorSchema propagatedSchema, IOperatorSchema[] inputSchemas, IOperatorSchema outerPlanSchema)
+            throws AlgebricksException;
+
+    public void disableJobGenBelowMe();
+
+    public boolean isJobGenDisabledBelowMe();
+
+    public boolean isMicroOperator();
+
+    public void setHostQueryContext(Object context);
+
+    public Object getHostQueryContext();
+
+    /**
+     * @return labels (0 or 1) for each input and output indicating the dependency between them.
+     *         The edges labeled as 1 must wait for the edges with label 0.
+     */
+    public Pair<int[], int[]> getInputOutputDependencyLabels(ILogicalOperator op);
+
+    /*
+     * This is needed to have a kind of cost based decision on whether to merge the shared subplans and materialize the result.
+     * If the subgraph whose result we would like to materialize has an operator that is computationally expensive, we assume
+     * it is cheaper to materialize the result of this subgraph and read from the file rather than recomputing it.
+     */
+    public boolean expensiveThanMaterialization();
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/LogicalExpressionTag.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/LogicalExpressionTag.java b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/LogicalExpressionTag.java
new file mode 100644
index 0000000..83bc702
--- /dev/null
+++ b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/LogicalExpressionTag.java
@@ -0,0 +1,19 @@
+/*
+ * 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.core.algebra.base;
+
+public enum LogicalExpressionTag {
+    FUNCTION_CALL, VARIABLE, CONSTANT
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/LogicalOperatorTag.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/LogicalOperatorTag.java b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/LogicalOperatorTag.java
new file mode 100644
index 0000000..9ddd927
--- /dev/null
+++ b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/LogicalOperatorTag.java
@@ -0,0 +1,51 @@
+/*
+ * 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.core.algebra.base;
+
+public enum LogicalOperatorTag {
+    AGGREGATE,
+    ASSIGN,
+    DATASOURCESCAN,
+    DISTINCT,
+    DISTRIBUTE_RESULT,
+    EMPTYTUPLESOURCE,
+    EXCHANGE,
+    EXTENSION_OPERATOR,
+    EXTERNAL_LOOKUP,
+    GROUP,
+    INDEX_INSERT_DELETE,
+    INNERJOIN,
+    INSERT_DELETE,
+    LEFTOUTERJOIN,
+    LIMIT,
+    MATERIALIZE,
+    NESTEDTUPLESOURCE,
+    ORDER,
+    PARTITIONINGSPLIT,
+    PROJECT,
+    REPLICATE,
+    RUNNINGAGGREGATE,
+    SCRIPT,
+    SELECT,
+    SINK,
+    SUBPLAN,
+    TOKENIZE,
+    UNIONALL,
+    UNNEST,
+    UNNEST_MAP,
+    UPDATE,
+    WRITE,
+    WRITE_RESULT,
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/LogicalVariable.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/LogicalVariable.java b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/LogicalVariable.java
new file mode 100644
index 0000000..07596b1
--- /dev/null
+++ b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/LogicalVariable.java
@@ -0,0 +1,51 @@
+/*
+ * 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.core.algebra.base;
+
+/**
+ * Represents a logical variable in an asterix logical plan.
+ * 
+ * @author Vinayak R. Borkar [vborkar@ics.uci.edu]
+ */
+public final class LogicalVariable {
+    private final int id;
+
+    public LogicalVariable(int id) {
+        this.id = id;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    @Override
+    public String toString() {
+        return "$$" + id;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (!(obj instanceof LogicalVariable)) {
+            return false;
+        } else {
+            return id == ((LogicalVariable) obj).getId();
+        }
+    }
+
+    @Override
+    public int hashCode() {
+        return id;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/OperatorAnnotations.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/OperatorAnnotations.java b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/OperatorAnnotations.java
new file mode 100644
index 0000000..251edca
--- /dev/null
+++ b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/OperatorAnnotations.java
@@ -0,0 +1,27 @@
+/*
+ * 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.core.algebra.base;
+
+public interface OperatorAnnotations {
+    // hints
+    public static final String USE_HASH_GROUP_BY = "USE_HASH_GROUP_BY"; // -->
+    public static final String USE_EXTERNAL_GROUP_BY = "USE_EXTERNAL_GROUP_BY"; // -->
+    public static final String USE_RANGE_CONNECTOR = "USE_RANGE_CONNECTOR"; // -->
+    // Boolean
+    public static final String CARDINALITY = "CARDINALITY"; // -->
+    // Integer
+    public static final String MAX_NUMBER_FRAMES = "MAX_NUMBER_FRAMES"; // -->
+    // Integer
+}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb-hyracks/blob/9939b48e/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/PhysicalOperatorTag.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/PhysicalOperatorTag.java b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/PhysicalOperatorTag.java
new file mode 100644
index 0000000..0c9e89a
--- /dev/null
+++ b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/base/PhysicalOperatorTag.java
@@ -0,0 +1,72 @@
+/*
+ * 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.core.algebra.base;
+
+public enum PhysicalOperatorTag {
+    AGGREGATE,
+    ASSIGN,
+    BROADCAST_EXCHANGE,
+    BTREE_SEARCH,
+    BULKLOAD,
+    DATASOURCE_SCAN,
+    DISTRIBUTE_RESULT,
+    EMPTY_TUPLE_SOURCE,
+    EXTENSION_OPERATOR,
+    EXTERNAL_GROUP_BY,
+    EXTERNAL_LOOKUP,
+    HASH_GROUP_BY,
+    HASH_PARTITION_EXCHANGE,
+    HASH_PARTITION_MERGE_EXCHANGE,
+    HDFS_READER,
+    HYBRID_HASH_JOIN,
+    IN_MEMORY_HASH_JOIN,
+    IN_MEMORY_STABLE_SORT,
+    INDEX_BULKLOAD,
+    INDEX_INSERT_DELETE,
+    INSERT_DELETE,
+    LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH,
+    MATERIALIZE,
+    MICRO_PRE_CLUSTERED_GROUP_BY,
+    NESTED_LOOP,
+    NESTED_TUPLE_SOURCE,
+    ONE_TO_ONE_EXCHANGE,
+    PARTITIONINGSPLIT,
+    PRE_CLUSTERED_GROUP_BY,
+    PRE_SORTED_DISTINCT_BY,
+    RANDOM_PARTITION_EXCHANGE,
+    RANDOM_MERGE_EXCHANGE,
+    RANGE_PARTITION_EXCHANGE,
+    RANGE_PARTITION_MERGE_EXCHANGE,
+    RTREE_SEARCH,
+    RUNNING_AGGREGATE,
+    SINGLE_PARTITION_INVERTED_INDEX_SEARCH,
+    SINK,
+    SINK_WRITE,
+    SORT_GROUP_BY,
+    SORT_MERGE_EXCHANGE,
+    SPLIT,
+    STABLE_SORT,
+    STATS,
+    STREAM_LIMIT,
+    STREAM_PROJECT,
+    STREAM_SELECT,
+    STRING_STREAM_SCRIPT,
+    SUBPLAN,
+    TOKENIZE,
+    UNION_ALL,
+    UNNEST,
+    UPDATE,
+    WRITE_RESULT,
+}