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:56 UTC
[43/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/algebra/operators/logical/visitors/OperatorDeepCopyVisitor.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/algebra/operators/logical/visitors/OperatorDeepCopyVisitor.java b/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/algebra/operators/logical/visitors/OperatorDeepCopyVisitor.java
deleted file mode 100644
index e62dbf8..0000000
--- a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/algebra/operators/logical/visitors/OperatorDeepCopyVisitor.java
+++ /dev/null
@@ -1,368 +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.algebra.operators.logical.visitors;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.commons.lang3.mutable.Mutable;
-import org.apache.commons.lang3.mutable.MutableObject;
-
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.common.utils.Pair;
-import edu.uci.ics.hyracks.algebricks.common.utils.Triple;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalPlan;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalVariable;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.AbstractLogicalExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AssignOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.DataSourceScanOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.DistinctOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.DistributeResultOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.EmptyTupleSourceOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ExchangeOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ExtensionOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ExternalDataLookupOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.IndexInsertDeleteOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.InsertDeleteOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.LeftOuterJoinOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.LimitOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.MaterializeOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.NestedTupleSourceOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.OrderOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.OrderOperator.IOrder;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.PartitioningSplitOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ProjectOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ReplicateOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.RunningAggregateOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ScriptOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.SelectOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.SinkOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.SubplanOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.TokenizeOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.UnionAllOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.UnnestMapOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.UnnestOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.WriteOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.WriteResultOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.util.OperatorManipulationUtil;
-import edu.uci.ics.hyracks.algebricks.core.algebra.visitors.ILogicalOperatorVisitor;
-
-public class OperatorDeepCopyVisitor implements ILogicalOperatorVisitor<ILogicalOperator, Void> {
-
- @Override
- public ILogicalOperator visitAggregateOperator(AggregateOperator op, Void arg) throws AlgebricksException {
- ArrayList<LogicalVariable> newList = new ArrayList<LogicalVariable>();
- ArrayList<Mutable<ILogicalExpression>> newExpressions = new ArrayList<Mutable<ILogicalExpression>>();
- newList.addAll(op.getVariables());
- deepCopyExpressionRefs(newExpressions, op.getExpressions());
- return new AggregateOperator(newList, newExpressions);
- }
-
- @Override
- public ILogicalOperator visitRunningAggregateOperator(RunningAggregateOperator op, Void arg)
- throws AlgebricksException {
- ArrayList<LogicalVariable> newList = new ArrayList<LogicalVariable>();
- ArrayList<Mutable<ILogicalExpression>> newExpressions = new ArrayList<Mutable<ILogicalExpression>>();
- newList.addAll(op.getVariables());
- deepCopyExpressionRefs(newExpressions, op.getExpressions());
- return new RunningAggregateOperator(newList, newExpressions);
- }
-
- @Override
- public ILogicalOperator visitEmptyTupleSourceOperator(EmptyTupleSourceOperator op, Void arg)
- throws AlgebricksException {
- return new EmptyTupleSourceOperator();
- }
-
- @Override
- public ILogicalOperator visitGroupByOperator(GroupByOperator op, Void arg) throws AlgebricksException {
- List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> groupByList = new ArrayList<Pair<LogicalVariable, Mutable<ILogicalExpression>>>();
- List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> decoList = new ArrayList<Pair<LogicalVariable, Mutable<ILogicalExpression>>>();
- ArrayList<ILogicalPlan> newSubplans = new ArrayList<ILogicalPlan>();
- for (Pair<LogicalVariable, Mutable<ILogicalExpression>> pair : op.getGroupByList())
- groupByList.add(new Pair<LogicalVariable, Mutable<ILogicalExpression>>(pair.first,
- deepCopyExpressionRef(pair.second)));
- for (Pair<LogicalVariable, Mutable<ILogicalExpression>> pair : op.getDecorList())
- decoList.add(new Pair<LogicalVariable, Mutable<ILogicalExpression>>(pair.first,
- deepCopyExpressionRef(pair.second)));
- for (ILogicalPlan plan : op.getNestedPlans()) {
- newSubplans.add(OperatorManipulationUtil.deepCopy(plan));
- }
- return new GroupByOperator(groupByList, decoList, newSubplans);
- }
-
- @Override
- public ILogicalOperator visitLimitOperator(LimitOperator op, Void arg) throws AlgebricksException {
- return new LimitOperator(deepCopyExpressionRef(op.getMaxObjects()).getValue(), deepCopyExpressionRef(
- op.getOffset()).getValue(), op.isTopmostLimitOp());
- }
-
- @Override
- public ILogicalOperator visitInnerJoinOperator(InnerJoinOperator op, Void arg) throws AlgebricksException {
- return new InnerJoinOperator(deepCopyExpressionRef(op.getCondition()), op.getInputs().get(0), op.getInputs()
- .get(1));
- }
-
- @Override
- public ILogicalOperator visitLeftOuterJoinOperator(LeftOuterJoinOperator op, Void arg) throws AlgebricksException {
- return new LeftOuterJoinOperator(deepCopyExpressionRef(op.getCondition()), op.getInputs().get(0), op
- .getInputs().get(1));
- }
-
- @Override
- public ILogicalOperator visitNestedTupleSourceOperator(NestedTupleSourceOperator op, Void arg)
- throws AlgebricksException {
- return new NestedTupleSourceOperator(null);
- }
-
- @Override
- public ILogicalOperator visitOrderOperator(OrderOperator op, Void arg) throws AlgebricksException {
- return new OrderOperator(this.deepCopyOrderAndExpression(op.getOrderExpressions()));
- }
-
- @Override
- public ILogicalOperator visitAssignOperator(AssignOperator op, Void arg) throws AlgebricksException {
- ArrayList<LogicalVariable> newList = new ArrayList<LogicalVariable>();
- ArrayList<Mutable<ILogicalExpression>> newExpressions = new ArrayList<Mutable<ILogicalExpression>>();
- newList.addAll(op.getVariables());
- deepCopyExpressionRefs(newExpressions, op.getExpressions());
- return new AssignOperator(newList, newExpressions);
- }
-
- @Override
- public ILogicalOperator visitSelectOperator(SelectOperator op, Void arg) throws AlgebricksException {
- return new SelectOperator(deepCopyExpressionRef(op.getCondition()), op.getRetainNull(),
- op.getNullPlaceholderVariable());
- }
-
- @Override
- public ILogicalOperator visitProjectOperator(ProjectOperator op, Void arg) throws AlgebricksException {
- ArrayList<LogicalVariable> newList = new ArrayList<LogicalVariable>();
- newList.addAll(op.getVariables());
- return new ProjectOperator(newList);
- }
-
- @Override
- public ILogicalOperator visitPartitioningSplitOperator(PartitioningSplitOperator op, Void arg)
- throws AlgebricksException {
- ArrayList<Mutable<ILogicalExpression>> newExpressions = new ArrayList<Mutable<ILogicalExpression>>();
- deepCopyExpressionRefs(newExpressions, op.getExpressions());
- return new PartitioningSplitOperator(newExpressions, op.getDefaultBranchIndex());
- }
-
- @Override
- public ILogicalOperator visitReplicateOperator(ReplicateOperator op, Void arg) throws AlgebricksException {
- return new ReplicateOperator(op.getOutputArity());
- }
-
- @Override
- public ILogicalOperator visitScriptOperator(ScriptOperator op, Void arg) throws AlgebricksException {
- ArrayList<LogicalVariable> newInputList = new ArrayList<LogicalVariable>();
- ArrayList<LogicalVariable> newOutputList = new ArrayList<LogicalVariable>();
- newInputList.addAll(op.getInputVariables());
- newOutputList.addAll(op.getOutputVariables());
- return new ScriptOperator(op.getScriptDescription(), newInputList, newOutputList);
- }
-
- @Override
- public ILogicalOperator visitSubplanOperator(SubplanOperator op, Void arg) throws AlgebricksException {
- ArrayList<ILogicalPlan> newSubplans = new ArrayList<ILogicalPlan>();
- for (ILogicalPlan plan : op.getNestedPlans()) {
- newSubplans.add(OperatorManipulationUtil.deepCopy(plan));
- }
- return new SubplanOperator(newSubplans);
- }
-
- @Override
- public ILogicalOperator visitUnionOperator(UnionAllOperator op, Void arg) throws AlgebricksException {
- List<Triple<LogicalVariable, LogicalVariable, LogicalVariable>> newVarMap = new ArrayList<Triple<LogicalVariable, LogicalVariable, LogicalVariable>>();
- List<Triple<LogicalVariable, LogicalVariable, LogicalVariable>> varMap = op.getVariableMappings();
- for (Triple<LogicalVariable, LogicalVariable, LogicalVariable> triple : varMap)
- newVarMap.add(new Triple<LogicalVariable, LogicalVariable, LogicalVariable>(triple.first, triple.second,
- triple.third));
- return new UnionAllOperator(newVarMap);
- }
-
- @Override
- public ILogicalOperator visitUnnestOperator(UnnestOperator op, Void arg) throws AlgebricksException {
- return new UnnestOperator(op.getVariable(), deepCopyExpressionRef(op.getExpressionRef()),
- op.getPositionalVariable(), op.getPositionalVariableType(), op.getPositionWriter());
- }
-
- @Override
- public ILogicalOperator visitUnnestMapOperator(UnnestMapOperator op, Void arg) throws AlgebricksException {
- ArrayList<LogicalVariable> newInputList = new ArrayList<LogicalVariable>();
- newInputList.addAll(op.getVariables());
- return new UnnestMapOperator(newInputList, deepCopyExpressionRef(op.getExpressionRef()), new ArrayList<Object>(
- op.getVariableTypes()), op.propagatesInput());
- }
-
- @Override
- public ILogicalOperator visitDataScanOperator(DataSourceScanOperator op, Void arg) throws AlgebricksException {
- ArrayList<LogicalVariable> newInputList = new ArrayList<LogicalVariable>();
- newInputList.addAll(op.getVariables());
- return new DataSourceScanOperator(newInputList, op.getDataSource());
- }
-
- @Override
- public ILogicalOperator visitDistinctOperator(DistinctOperator op, Void arg) throws AlgebricksException {
- ArrayList<Mutable<ILogicalExpression>> newExpressions = new ArrayList<Mutable<ILogicalExpression>>();
- deepCopyExpressionRefs(newExpressions, op.getExpressions());
- return new DistinctOperator(newExpressions);
- }
-
- @Override
- public ILogicalOperator visitExchangeOperator(ExchangeOperator op, Void arg) throws AlgebricksException {
- return new ExchangeOperator();
- }
-
- @Override
- public ILogicalOperator visitWriteOperator(WriteOperator op, Void arg) throws AlgebricksException {
- ArrayList<Mutable<ILogicalExpression>> newExpressions = new ArrayList<Mutable<ILogicalExpression>>();
- deepCopyExpressionRefs(newExpressions, op.getExpressions());
- return new WriteOperator(newExpressions, op.getDataSink());
- }
-
- @Override
- public ILogicalOperator visitDistributeResultOperator(DistributeResultOperator op, Void arg)
- throws AlgebricksException {
- ArrayList<Mutable<ILogicalExpression>> newExpressions = new ArrayList<Mutable<ILogicalExpression>>();
- deepCopyExpressionRefs(newExpressions, op.getExpressions());
- return new DistributeResultOperator(newExpressions, op.getDataSink());
- }
-
- @Override
- public ILogicalOperator visitWriteResultOperator(WriteResultOperator op, Void arg) throws AlgebricksException {
- ArrayList<Mutable<ILogicalExpression>> newKeyExpressions = new ArrayList<Mutable<ILogicalExpression>>();
- deepCopyExpressionRefs(newKeyExpressions, op.getKeyExpressions());
- List<Mutable<ILogicalExpression>> newLSMComponentFilterExpressions = new ArrayList<Mutable<ILogicalExpression>>();
- deepCopyExpressionRefs(newKeyExpressions, op.getAdditionalFilteringExpressions());
- WriteResultOperator writeResultOp = new WriteResultOperator(op.getDataSource(),
- deepCopyExpressionRef(op.getPayloadExpression()), newKeyExpressions);
- writeResultOp.setAdditionalFilteringExpressions(newLSMComponentFilterExpressions);
- return writeResultOp;
- }
-
- @Override
- public ILogicalOperator visitInsertDeleteOperator(InsertDeleteOperator op, Void arg) throws AlgebricksException {
- List<Mutable<ILogicalExpression>> newKeyExpressions = new ArrayList<Mutable<ILogicalExpression>>();
- deepCopyExpressionRefs(newKeyExpressions, op.getPrimaryKeyExpressions());
- List<Mutable<ILogicalExpression>> newLSMComponentFilterExpressions = new ArrayList<Mutable<ILogicalExpression>>();
- deepCopyExpressionRefs(newKeyExpressions, op.getAdditionalFilteringExpressions());
- InsertDeleteOperator insertDeleteOp = new InsertDeleteOperator(op.getDataSource(),
- deepCopyExpressionRef(op.getPayloadExpression()), newKeyExpressions, op.getOperation(), op.isBulkload());
- insertDeleteOp.setAdditionalFilteringExpressions(newLSMComponentFilterExpressions);
- return insertDeleteOp;
- }
-
- @Override
- public ILogicalOperator visitIndexInsertDeleteOperator(IndexInsertDeleteOperator op, Void arg)
- throws AlgebricksException {
- List<Mutable<ILogicalExpression>> newPrimaryKeyExpressions = new ArrayList<Mutable<ILogicalExpression>>();
- deepCopyExpressionRefs(newPrimaryKeyExpressions, op.getPrimaryKeyExpressions());
- List<Mutable<ILogicalExpression>> newSecondaryKeyExpressions = new ArrayList<Mutable<ILogicalExpression>>();
- deepCopyExpressionRefs(newSecondaryKeyExpressions, op.getSecondaryKeyExpressions());
- Mutable<ILogicalExpression> newFilterExpression = new MutableObject<ILogicalExpression>(
- ((AbstractLogicalExpression) op.getFilterExpression()).cloneExpression());
- List<Mutable<ILogicalExpression>> newLSMComponentFilterExpressions = new ArrayList<Mutable<ILogicalExpression>>();
- deepCopyExpressionRefs(newLSMComponentFilterExpressions, op.getAdditionalFilteringExpressions());
- IndexInsertDeleteOperator indexInsertDeleteOp = new IndexInsertDeleteOperator(op.getDataSourceIndex(),
- newPrimaryKeyExpressions, newSecondaryKeyExpressions, newFilterExpression, op.getOperation(),
- op.isBulkload());
- indexInsertDeleteOp.setAdditionalFilteringExpressions(newLSMComponentFilterExpressions);
- return indexInsertDeleteOp;
- }
-
- @Override
- public ILogicalOperator visitTokenizeOperator(TokenizeOperator op, Void arg) throws AlgebricksException {
- List<Mutable<ILogicalExpression>> newPrimaryKeyExpressions = new ArrayList<Mutable<ILogicalExpression>>();
- deepCopyExpressionRefs(newPrimaryKeyExpressions, op.getPrimaryKeyExpressions());
- List<Mutable<ILogicalExpression>> newSecondaryKeyExpressions = new ArrayList<Mutable<ILogicalExpression>>();
- deepCopyExpressionRefs(newSecondaryKeyExpressions, op.getSecondaryKeyExpressions());
- List<LogicalVariable> newTokenizeVars = new ArrayList<LogicalVariable>();
- deepCopyVars(newTokenizeVars, op.getTokenizeVars());
- Mutable<ILogicalExpression> newFilterExpression = new MutableObject<ILogicalExpression>(
- ((AbstractLogicalExpression) op.getFilterExpression()).cloneExpression());
- List<Object> newTokenizeVarTypes = new ArrayList<Object>();
- deepCopyObjects(newTokenizeVarTypes, op.getTokenizeVarTypes());
-
- TokenizeOperator tokenizeOp = new TokenizeOperator(op.getDataSourceIndex(), newPrimaryKeyExpressions,
- newSecondaryKeyExpressions, newTokenizeVars, newFilterExpression, op.getOperation(), op.isBulkload(),
- op.isPartitioned(), newTokenizeVarTypes);
- return tokenizeOp;
- }
-
- @Override
- public ILogicalOperator visitSinkOperator(SinkOperator op, Void arg) throws AlgebricksException {
- return new SinkOperator();
- }
-
- private void deepCopyExpressionRefs(List<Mutable<ILogicalExpression>> newExprs,
- List<Mutable<ILogicalExpression>> oldExprs) {
- for (Mutable<ILogicalExpression> oldExpr : oldExprs)
- newExprs.add(new MutableObject<ILogicalExpression>(((AbstractLogicalExpression) oldExpr.getValue())
- .cloneExpression()));
- }
-
- private Mutable<ILogicalExpression> deepCopyExpressionRef(Mutable<ILogicalExpression> oldExpr) {
- return new MutableObject<ILogicalExpression>(((AbstractLogicalExpression) oldExpr.getValue()).cloneExpression());
- }
-
- private List<LogicalVariable> deepCopyVars(List<LogicalVariable> newVars, List<LogicalVariable> oldVars) {
- for (LogicalVariable oldVar : oldVars)
- newVars.add(oldVar);
- return newVars;
- }
-
- private List<Object> deepCopyObjects(List<Object> newObjs, List<Object> oldObjs) {
- for (Object oldObj : oldObjs)
- newObjs.add(oldObj);
- return newObjs;
- }
-
- private List<Pair<IOrder, Mutable<ILogicalExpression>>> deepCopyOrderAndExpression(
- List<Pair<IOrder, Mutable<ILogicalExpression>>> ordersAndExprs) {
- List<Pair<IOrder, Mutable<ILogicalExpression>>> newOrdersAndExprs = new ArrayList<Pair<IOrder, Mutable<ILogicalExpression>>>();
- for (Pair<IOrder, Mutable<ILogicalExpression>> pair : ordersAndExprs)
- newOrdersAndExprs.add(new Pair<IOrder, Mutable<ILogicalExpression>>(pair.first,
- deepCopyExpressionRef(pair.second)));
- return newOrdersAndExprs;
- }
-
- @Override
- public ILogicalOperator visitExtensionOperator(ExtensionOperator op, Void arg) throws AlgebricksException {
- return new ExtensionOperator(op.getNewInstanceOfDelegateOperator());
- }
-
- @Override
- public ILogicalOperator visitExternalDataLookupOperator(ExternalDataLookupOperator op, Void arg)
- throws AlgebricksException {
- ArrayList<LogicalVariable> newInputList = new ArrayList<LogicalVariable>();
- newInputList.addAll(op.getVariables());
- return new ExternalDataLookupOperator(newInputList, deepCopyExpressionRef(op.getExpressionRef()),
- new ArrayList<Object>(op.getVariableTypes()), op.isPropagateInput(), op.getDataSource());
- }
-
- @Override
- public ILogicalOperator visitMaterializeOperator(MaterializeOperator op, Void arg) throws AlgebricksException {
- return new MaterializeOperator();
- }
-}
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/algebra/operators/logical/visitors/ProducedVariableVisitor.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/algebra/operators/logical/visitors/ProducedVariableVisitor.java b/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/algebra/operators/logical/visitors/ProducedVariableVisitor.java
deleted file mode 100644
index 1fa97a6..0000000
--- a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/algebra/operators/logical/visitors/ProducedVariableVisitor.java
+++ /dev/null
@@ -1,275 +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.algebra.operators.logical.visitors;
-
-import java.util.ArrayList;
-import java.util.Collection;
-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.common.utils.Triple;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalPlan;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalVariable;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AssignOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.DataSourceScanOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.DistinctOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.DistributeResultOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.EmptyTupleSourceOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ExchangeOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ExtensionOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ExternalDataLookupOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.IndexInsertDeleteOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.InsertDeleteOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.LeftOuterJoinOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.LimitOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.MaterializeOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.NestedTupleSourceOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.OrderOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.PartitioningSplitOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ProjectOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ReplicateOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.RunningAggregateOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ScriptOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.SelectOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.SinkOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.SubplanOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.TokenizeOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.UnionAllOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.UnnestMapOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.UnnestOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.WriteOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.WriteResultOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.visitors.ILogicalOperatorVisitor;
-
-public class ProducedVariableVisitor implements ILogicalOperatorVisitor<Void, Void> {
-
- private Collection<LogicalVariable> producedVariables;
-
- public ProducedVariableVisitor(Collection<LogicalVariable> producedVariables) throws AlgebricksException {
- this.producedVariables = producedVariables;
- }
-
- @Override
- public Void visitAggregateOperator(AggregateOperator op, Void arg) throws AlgebricksException {
- producedVariables.addAll(op.getVariables());
- return null;
- }
-
- @Override
- public Void visitAssignOperator(AssignOperator op, Void arg) throws AlgebricksException {
- producedVariables.addAll(op.getVariables());
- return null;
- }
-
- @Override
- public Void visitDataScanOperator(DataSourceScanOperator op, Void arg) throws AlgebricksException {
- producedVariables.addAll(op.getVariables());
- return null;
- }
-
- @Override
- public Void visitDistinctOperator(DistinctOperator op, Void arg) {
- return null;
- }
-
- @Override
- public Void visitEmptyTupleSourceOperator(EmptyTupleSourceOperator op, Void arg) throws AlgebricksException {
- return null;
- }
-
- @Override
- public Void visitExchangeOperator(ExchangeOperator op, Void arg) throws AlgebricksException {
- return null;
- }
-
- @Override
- public Void visitGroupByOperator(GroupByOperator op, Void arg) throws AlgebricksException {
- for (ILogicalPlan p : op.getNestedPlans()) {
- for (Mutable<ILogicalOperator> r : p.getRoots()) {
- VariableUtilities.getLiveVariables(r.getValue(), producedVariables);
- }
- }
- for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : op.getGroupByList()) {
- if (p.first != null) {
- producedVariables.add(p.first);
- }
- }
- for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : op.getDecorList()) {
- if (p.first != null) {
- producedVariables.add(p.first);
- }
- }
- return null;
- }
-
- @Override
- public Void visitInnerJoinOperator(InnerJoinOperator op, Void arg) throws AlgebricksException {
- return null;
- }
-
- @Override
- public Void visitLeftOuterJoinOperator(LeftOuterJoinOperator op, Void arg) throws AlgebricksException {
- return null;
- }
-
- @Override
- public Void visitLimitOperator(LimitOperator op, Void arg) throws AlgebricksException {
- return null;
- }
-
- @Override
- public Void visitNestedTupleSourceOperator(NestedTupleSourceOperator op, Void arg) throws AlgebricksException {
- return null;
- }
-
- @Override
- public Void visitOrderOperator(OrderOperator op, Void arg) throws AlgebricksException {
- return null;
- }
-
- @Override
- public Void visitPartitioningSplitOperator(PartitioningSplitOperator op, Void arg) throws AlgebricksException {
- return null;
- }
-
- @Override
- public Void visitProjectOperator(ProjectOperator op, Void arg) throws AlgebricksException {
- return null;
- }
-
- @Override
- public Void visitRunningAggregateOperator(RunningAggregateOperator op, Void arg) throws AlgebricksException {
- producedVariables.addAll(op.getVariables());
- return null;
- }
-
- @Override
- public Void visitScriptOperator(ScriptOperator op, Void arg) throws AlgebricksException {
- List<LogicalVariable> usedVariables = new ArrayList<LogicalVariable>();
- VariableUtilities.getUsedVariables(op, usedVariables);
- for (LogicalVariable v : op.getOutputVariables()) {
- if (!usedVariables.contains(v)) {
- producedVariables.add(v);
- }
- }
- return null;
- }
-
- @Override
- public Void visitSelectOperator(SelectOperator op, Void arg) throws AlgebricksException {
- return null;
- }
-
- @Override
- public Void visitSubplanOperator(SubplanOperator op, Void arg) throws AlgebricksException {
- for (ILogicalPlan p : op.getNestedPlans()) {
- for (Mutable<ILogicalOperator> r : p.getRoots()) {
- VariableUtilities.getLiveVariables(r.getValue(), producedVariables);
- }
- }
- return null;
- }
-
- @Override
- public Void visitUnionOperator(UnionAllOperator op, Void arg) throws AlgebricksException {
- for (Triple<LogicalVariable, LogicalVariable, LogicalVariable> t : op.getVariableMappings()) {
- producedVariables.add(t.third);
- }
- return null;
- }
-
- @Override
- public Void visitUnnestMapOperator(UnnestMapOperator op, Void arg) throws AlgebricksException {
- producedVariables.addAll(op.getVariables());
- return null;
- }
-
- @Override
- public Void visitUnnestOperator(UnnestOperator op, Void arg) throws AlgebricksException {
- producedVariables.addAll(op.getVariables());
- LogicalVariable positionalVariable = op.getPositionalVariable();
- if (positionalVariable != null) {
- if (!producedVariables.contains(positionalVariable))
- producedVariables.add(positionalVariable);
- }
- return null;
- }
-
- @Override
- public Void visitWriteOperator(WriteOperator op, Void arg) throws AlgebricksException {
- return null;
- }
-
- @Override
- public Void visitDistributeResultOperator(DistributeResultOperator op, Void arg) throws AlgebricksException {
- return null;
- }
-
- @Override
- public Void visitWriteResultOperator(WriteResultOperator op, Void arg) throws AlgebricksException {
- return null;
- }
-
- @Override
- public Void visitReplicateOperator(ReplicateOperator op, Void arg) throws AlgebricksException {
- return null;
- }
-
- @Override
- public Void visitMaterializeOperator(MaterializeOperator op, Void arg) throws AlgebricksException {
- return null;
- }
-
- @Override
- public Void visitInsertDeleteOperator(InsertDeleteOperator op, Void arg) throws AlgebricksException {
- return null;
- }
-
- @Override
- public Void visitIndexInsertDeleteOperator(IndexInsertDeleteOperator op, Void arg) throws AlgebricksException {
- return null;
- }
-
- @Override
- public Void visitTokenizeOperator(TokenizeOperator op, Void arg) throws AlgebricksException {
- producedVariables.addAll(op.getTokenizeVars());
- return null;
- }
-
- @Override
- public Void visitSinkOperator(SinkOperator op, Void arg) throws AlgebricksException {
- return null;
- }
-
- @Override
- public Void visitExtensionOperator(ExtensionOperator op, Void arg) throws AlgebricksException {
- op.getDelegate().getProducedVariables(producedVariables);
- return null;
- }
-
- @Override
- public Void visitExternalDataLookupOperator(ExternalDataLookupOperator op, Void arg) throws AlgebricksException {
- producedVariables.add(op.getVariables().get(0));
- return null;
- }
-}
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/algebra/operators/logical/visitors/SchemaVariableVisitor.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/algebra/operators/logical/visitors/SchemaVariableVisitor.java b/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/algebra/operators/logical/visitors/SchemaVariableVisitor.java
deleted file mode 100644
index 0b37b92..0000000
--- a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/algebra/operators/logical/visitors/SchemaVariableVisitor.java
+++ /dev/null
@@ -1,330 +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.algebra.operators.logical.visitors;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.apache.commons.lang3.mutable.Mutable;
-
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.common.utils.Pair;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalPlan;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalExpressionTag;
-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.AggregateOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AssignOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.DataSourceScanOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.DistinctOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.DistributeResultOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.EmptyTupleSourceOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ExchangeOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ExtensionOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ExternalDataLookupOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.IndexInsertDeleteOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.InsertDeleteOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.LeftOuterJoinOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.LimitOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.MaterializeOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.NestedTupleSourceOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.OrderOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.PartitioningSplitOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ProjectOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ReplicateOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.RunningAggregateOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ScriptOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.SelectOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.SinkOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.SubplanOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.TokenizeOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.UnionAllOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.UnnestMapOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.UnnestOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.WriteOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.WriteResultOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.visitors.ILogicalOperatorVisitor;
-
-public class SchemaVariableVisitor implements ILogicalOperatorVisitor<Void, Void> {
-
- private Collection<LogicalVariable> schemaVariables;
-
- public SchemaVariableVisitor(Collection<LogicalVariable> schemaVariables) {
- this.schemaVariables = schemaVariables;
- }
-
- @Override
- public Void visitAggregateOperator(AggregateOperator op, Void arg) throws AlgebricksException {
- schemaVariables.addAll(op.getVariables());
- return null;
- }
-
- @Override
- public Void visitAssignOperator(AssignOperator op, Void arg) throws AlgebricksException {
- standardLayout(op);
- return null;
- }
-
- @Override
- public Void visitDataScanOperator(DataSourceScanOperator op, Void arg) throws AlgebricksException {
- standardLayout(op);
- return null;
- }
-
- @Override
- public Void visitDistinctOperator(DistinctOperator op, Void arg) throws AlgebricksException {
- List<LogicalVariable> allLiveVars = new ArrayList<LogicalVariable>();
- for (Mutable<ILogicalOperator> c : op.getInputs()) {
- VariableUtilities.getLiveVariables(c.getValue(), allLiveVars);
- }
- VariableUtilities.getProducedVariables(op, allLiveVars);
- /** put distinct vars first */
- schemaVariables.addAll(op.getDistinctByVarList());
- /** then other live vars */
- for (LogicalVariable var : allLiveVars) {
- if (!schemaVariables.contains(var)) {
- schemaVariables.add(var);
- }
- }
- return null;
- }
-
- @Override
- public Void visitEmptyTupleSourceOperator(EmptyTupleSourceOperator op, Void arg) throws AlgebricksException {
- standardLayout(op);
- return null;
- }
-
- @Override
- public Void visitExchangeOperator(ExchangeOperator op, Void arg) throws AlgebricksException {
- standardLayout(op);
- return null;
- }
-
- @Override
- public Void visitGroupByOperator(GroupByOperator op, Void arg) throws AlgebricksException {
- for (ILogicalPlan p : op.getNestedPlans()) {
- for (Mutable<ILogicalOperator> r : p.getRoots()) {
- VariableUtilities.getLiveVariables(r.getValue(), schemaVariables);
- }
- }
- for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : op.getGroupByList()) {
- if (p.first != null) {
- schemaVariables.add(p.first);
- }
- }
- for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : op.getDecorList()) {
- if (p.first != null) {
- schemaVariables.add(p.first);
- } else {
- ILogicalExpression e = p.second.getValue();
- if (e.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
- schemaVariables.add(((VariableReferenceExpression) e).getVariableReference());
- }
- }
- }
- return null;
- }
-
- @Override
- public Void visitInnerJoinOperator(InnerJoinOperator op, Void arg) throws AlgebricksException {
- standardLayout(op);
- return null;
- }
-
- @Override
- public Void visitLeftOuterJoinOperator(LeftOuterJoinOperator op, Void arg) throws AlgebricksException {
- standardLayout(op);
- return null;
- }
-
- @Override
- public Void visitLimitOperator(LimitOperator op, Void arg) throws AlgebricksException {
- standardLayout(op);
- return null;
- }
-
- @Override
- public Void visitNestedTupleSourceOperator(NestedTupleSourceOperator op, Void arg) throws AlgebricksException {
- VariableUtilities.getLiveVariables(op.getSourceOperator(), schemaVariables);
- return null;
- }
-
- @Override
- public Void visitOrderOperator(OrderOperator op, Void arg) throws AlgebricksException {
- standardLayout(op);
- return null;
- }
-
- @Override
- public Void visitPartitioningSplitOperator(PartitioningSplitOperator op, Void arg) throws AlgebricksException {
- standardLayout(op);
- return null;
- }
-
- @Override
- public Void visitProjectOperator(ProjectOperator op, Void arg) throws AlgebricksException {
- schemaVariables.addAll(op.getVariables());
- return null;
- }
-
- @Override
- public Void visitRunningAggregateOperator(RunningAggregateOperator op, Void arg) throws AlgebricksException {
- // VariableUtilities.getProducedVariables(op, schemaVariables);
- standardLayout(op);
- return null;
- }
-
- @Override
- public Void visitScriptOperator(ScriptOperator op, Void arg) throws AlgebricksException {
- schemaVariables.addAll(op.getOutputVariables());
- return null;
- }
-
- @Override
- public Void visitSelectOperator(SelectOperator op, Void arg) throws AlgebricksException {
- standardLayout(op);
- return null;
- }
-
- @Override
- public Void visitSubplanOperator(SubplanOperator op, Void arg) throws AlgebricksException {
- for (Mutable<ILogicalOperator> c : op.getInputs()) {
- VariableUtilities.getLiveVariables(c.getValue(), schemaVariables);
- }
- VariableUtilities.getProducedVariables(op, schemaVariables);
- for (ILogicalPlan p : op.getNestedPlans()) {
- for (Mutable<ILogicalOperator> r : p.getRoots()) {
- VariableUtilities.getLiveVariables(r.getValue(), schemaVariables);
- }
- }
- return null;
- }
-
- @Override
- public Void visitUnionOperator(UnionAllOperator op, Void arg) throws AlgebricksException {
- VariableUtilities.getProducedVariables(op, schemaVariables);
- return null;
- }
-
- @Override
- public Void visitUnnestMapOperator(UnnestMapOperator op, Void arg) throws AlgebricksException {
- if (op.propagatesInput()) {
- standardLayout(op);
- } else {
- VariableUtilities.getProducedVariables(op, schemaVariables);
- }
- return null;
- }
-
- @Override
- public Void visitUnnestOperator(UnnestOperator op, Void arg) throws AlgebricksException {
- standardLayout(op);
- return null;
- }
-
- @Override
- public Void visitWriteOperator(WriteOperator op, Void arg) throws AlgebricksException {
- standardLayout(op);
- return null;
- }
-
- @Override
- public Void visitDistributeResultOperator(DistributeResultOperator op, Void arg) throws AlgebricksException {
- standardLayout(op);
- return null;
- }
-
- @Override
- public Void visitWriteResultOperator(WriteResultOperator op, Void arg) throws AlgebricksException {
- standardLayout(op);
- return null;
- }
-
- private void standardLayout(ILogicalOperator op) throws AlgebricksException {
- for (Mutable<ILogicalOperator> c : op.getInputs()) {
- VariableUtilities.getLiveVariables(c.getValue(), schemaVariables);
- }
- VariableUtilities.getProducedVariables(op, schemaVariables);
- }
-
- @Override
- public Void visitReplicateOperator(ReplicateOperator op, Void arg) throws AlgebricksException {
- standardLayout(op);
- return null;
- }
-
- @Override
- public Void visitMaterializeOperator(MaterializeOperator op, Void arg) throws AlgebricksException {
- standardLayout(op);
- return null;
- }
-
- @Override
- public Void visitInsertDeleteOperator(InsertDeleteOperator op, Void arg) throws AlgebricksException {
- standardLayout(op);
- return null;
- }
-
- @Override
- public Void visitIndexInsertDeleteOperator(IndexInsertDeleteOperator op, Void arg) throws AlgebricksException {
- standardLayout(op);
- return null;
- }
-
- @Override
- public Void visitTokenizeOperator(TokenizeOperator op, Void arg) throws AlgebricksException {
- standardLayout(op);
- return null;
- }
-
- @Override
- public Void visitSinkOperator(SinkOperator op, Void arg) throws AlgebricksException {
- standardLayout(op);
- return null;
- }
-
- @Override
- public Void visitExtensionOperator(ExtensionOperator op, Void arg) throws AlgebricksException {
- standardLayout(op);
- return null;
- }
-
- @Override
- public Void visitExternalDataLookupOperator(ExternalDataLookupOperator op, Void arg) throws AlgebricksException {
- ArrayList<LogicalVariable> liveVariables = new ArrayList<LogicalVariable>();
- ArrayList<LogicalVariable> usedVariables = new ArrayList<LogicalVariable>();
- //get used variables
- op.getExpressionRef().getValue().getUsedVariables(usedVariables);
- //live variables - used variables
- for (Mutable<ILogicalOperator> c : op.getInputs()) {
- VariableUtilities.getLiveVariables(c.getValue(), liveVariables);
- }
- for (LogicalVariable v : liveVariables) {
- if (!usedVariables.contains(v)) {
- schemaVariables.add(v);
- }
- }
- VariableUtilities.getProducedVariables(op, schemaVariables);
- //+ produced variables
- return null;
- }
-
-}
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/algebra/operators/logical/visitors/SubstituteVariableVisitor.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/algebra/operators/logical/visitors/SubstituteVariableVisitor.java b/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/algebra/operators/logical/visitors/SubstituteVariableVisitor.java
deleted file mode 100644
index 695078a..0000000
--- a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/algebra/operators/logical/visitors/SubstituteVariableVisitor.java
+++ /dev/null
@@ -1,469 +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.algebra.operators.logical.visitors;
-
-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.common.utils.Pair;
-import edu.uci.ics.hyracks.algebricks.common.utils.Triple;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalPlan;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalVariable;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AssignOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.DataSourceScanOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.DistinctOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.DistributeResultOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.EmptyTupleSourceOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ExchangeOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ExtensionOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ExternalDataLookupOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.IndexInsertDeleteOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.InsertDeleteOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.LeftOuterJoinOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.LimitOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.MaterializeOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.NestedTupleSourceOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.OrderOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.OrderOperator.IOrder;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.PartitioningSplitOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ProjectOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ReplicateOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.RunningAggregateOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ScriptOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.SelectOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.SinkOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.SubplanOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.TokenizeOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.UnionAllOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.UnnestMapOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.UnnestOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.WriteOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.WriteResultOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.properties.OrderColumn;
-import edu.uci.ics.hyracks.algebricks.core.algebra.typing.ITypingContext;
-import edu.uci.ics.hyracks.algebricks.core.algebra.util.OperatorManipulationUtil;
-import edu.uci.ics.hyracks.algebricks.core.algebra.visitors.ILogicalOperatorVisitor;
-
-public class SubstituteVariableVisitor implements ILogicalOperatorVisitor<Void, Pair<LogicalVariable, LogicalVariable>> {
-
- private final boolean goThroughNts;
- private final ITypingContext ctx;
-
- public SubstituteVariableVisitor(boolean goThroughNts, ITypingContext ctx) {
- this.goThroughNts = goThroughNts;
- this.ctx = ctx;
- }
-
- @Override
- public Void visitAggregateOperator(AggregateOperator op, Pair<LogicalVariable, LogicalVariable> pair)
- throws AlgebricksException {
- List<LogicalVariable> variables = op.getVariables();
- int n = variables.size();
- for (int i = 0; i < n; i++) {
- if (variables.get(i).equals(pair.first)) {
- variables.set(i, pair.second);
- } else {
- op.getExpressions().get(i).getValue().substituteVar(pair.first, pair.second);
- }
- }
- substVarTypes(op, pair);
- return null;
- }
-
- @Override
- public Void visitAssignOperator(AssignOperator op, Pair<LogicalVariable, LogicalVariable> pair)
- throws AlgebricksException {
- List<LogicalVariable> variables = op.getVariables();
- int n = variables.size();
- for (int i = 0; i < n; i++) {
- if (variables.get(i).equals(pair.first)) {
- variables.set(i, pair.second);
- } else {
- op.getExpressions().get(i).getValue().substituteVar(pair.first, pair.second);
- }
- }
- // Substitute variables stored in ordering property
- if (op.getExplicitOrderingProperty() != null) {
- List<OrderColumn> orderColumns = op.getExplicitOrderingProperty().getOrderColumns();
- for (int i = 0; i < orderColumns.size(); i++) {
- OrderColumn oc = orderColumns.get(i);
- if (oc.getColumn().equals(pair.first)) {
- orderColumns.set(i, new OrderColumn(pair.second, oc.getOrder()));
- }
- }
- }
- substVarTypes(op, pair);
- return null;
- }
-
- @Override
- public Void visitDataScanOperator(DataSourceScanOperator op, Pair<LogicalVariable, LogicalVariable> pair)
- throws AlgebricksException {
- List<LogicalVariable> variables = op.getVariables();
- for (int i = 0; i < variables.size(); i++) {
- if (variables.get(i) == pair.first) {
- variables.set(i, pair.second);
- return null;
- }
- }
- substVarTypes(op, pair);
- return null;
- }
-
- @Override
- public Void visitDistinctOperator(DistinctOperator op, Pair<LogicalVariable, LogicalVariable> pair)
- throws AlgebricksException {
- for (Mutable<ILogicalExpression> eRef : op.getExpressions()) {
- eRef.getValue().substituteVar(pair.first, pair.second);
- }
- substVarTypes(op, pair);
- return null;
- }
-
- @Override
- public Void visitEmptyTupleSourceOperator(EmptyTupleSourceOperator op, Pair<LogicalVariable, LogicalVariable> pair) {
- // does not use any variable
- return null;
- }
-
- @Override
- public Void visitExchangeOperator(ExchangeOperator op, Pair<LogicalVariable, LogicalVariable> pair) {
- // does not use any variable
- return null;
- }
-
- @Override
- public Void visitGroupByOperator(GroupByOperator op, Pair<LogicalVariable, LogicalVariable> pair)
- throws AlgebricksException {
- subst(pair.first, pair.second, op.getGroupByList());
- subst(pair.first, pair.second, op.getDecorList());
- for (ILogicalPlan p : op.getNestedPlans()) {
- for (Mutable<ILogicalOperator> r : p.getRoots()) {
- OperatorManipulationUtil.substituteVarRec((AbstractLogicalOperator) r.getValue(), pair.first,
- pair.second, goThroughNts, ctx);
- }
- }
- substVarTypes(op, pair);
- return null;
- }
-
- @Override
- public Void visitInnerJoinOperator(InnerJoinOperator op, Pair<LogicalVariable, LogicalVariable> pair)
- throws AlgebricksException {
- op.getCondition().getValue().substituteVar(pair.first, pair.second);
- substVarTypes(op, pair);
- return null;
- }
-
- @Override
- public Void visitLeftOuterJoinOperator(LeftOuterJoinOperator op, Pair<LogicalVariable, LogicalVariable> pair)
- throws AlgebricksException {
- op.getCondition().getValue().substituteVar(pair.first, pair.second);
- substVarTypes(op, pair);
- return null;
- }
-
- @Override
- public Void visitLimitOperator(LimitOperator op, Pair<LogicalVariable, LogicalVariable> pair)
- throws AlgebricksException {
- op.getMaxObjects().getValue().substituteVar(pair.first, pair.second);
- ILogicalExpression offset = op.getOffset().getValue();
- if (offset != null) {
- offset.substituteVar(pair.first, pair.second);
- }
- substVarTypes(op, pair);
- return null;
- }
-
- @Override
- public Void visitNestedTupleSourceOperator(NestedTupleSourceOperator op, Pair<LogicalVariable, LogicalVariable> pair)
- throws AlgebricksException {
- return null;
- }
-
- @Override
- public Void visitOrderOperator(OrderOperator op, Pair<LogicalVariable, LogicalVariable> pair)
- throws AlgebricksException {
- for (Pair<IOrder, Mutable<ILogicalExpression>> oe : op.getOrderExpressions()) {
- oe.second.getValue().substituteVar(pair.first, pair.second);
- }
- substVarTypes(op, pair);
- return null;
- }
-
- @Override
- public Void visitPartitioningSplitOperator(PartitioningSplitOperator op, Pair<LogicalVariable, LogicalVariable> pair)
- throws AlgebricksException {
- for (Mutable<ILogicalExpression> e : op.getExpressions()) {
- e.getValue().substituteVar(pair.first, pair.second);
- }
- substVarTypes(op, pair);
- return null;
- }
-
- @Override
- public Void visitProjectOperator(ProjectOperator op, Pair<LogicalVariable, LogicalVariable> pair)
- throws AlgebricksException {
- List<LogicalVariable> usedVariables = op.getVariables();
- int n = usedVariables.size();
- for (int i = 0; i < n; i++) {
- LogicalVariable v = usedVariables.get(i);
- if (v.equals(pair.first)) {
- usedVariables.set(i, pair.second);
- }
- }
- substVarTypes(op, pair);
- return null;
- }
-
- @Override
- public Void visitRunningAggregateOperator(RunningAggregateOperator op, Pair<LogicalVariable, LogicalVariable> pair)
- throws AlgebricksException {
- List<LogicalVariable> variables = op.getVariables();
- int n = variables.size();
- for (int i = 0; i < n; i++) {
- if (variables.get(i).equals(pair.first)) {
- variables.set(i, pair.second);
- } else {
- op.getExpressions().get(i).getValue().substituteVar(pair.first, pair.second);
- }
- }
- substVarTypes(op, pair);
- return null;
- }
-
- @Override
- public Void visitScriptOperator(ScriptOperator op, Pair<LogicalVariable, LogicalVariable> pair)
- throws AlgebricksException {
- substInArray(op.getInputVariables(), pair.first, pair.second);
- substInArray(op.getOutputVariables(), pair.first, pair.second);
- substVarTypes(op, pair);
- return null;
- }
-
- @Override
- public Void visitSelectOperator(SelectOperator op, Pair<LogicalVariable, LogicalVariable> pair) {
- op.getCondition().getValue().substituteVar(pair.first, pair.second);
- return null;
- }
-
- @Override
- public Void visitSubplanOperator(SubplanOperator op, Pair<LogicalVariable, LogicalVariable> pair)
- throws AlgebricksException {
- for (ILogicalPlan p : op.getNestedPlans()) {
- for (Mutable<ILogicalOperator> r : p.getRoots()) {
- OperatorManipulationUtil.substituteVarRec((AbstractLogicalOperator) r.getValue(), pair.first,
- pair.second, goThroughNts, ctx);
- }
- }
- return null;
- }
-
- @Override
- public Void visitUnionOperator(UnionAllOperator op, Pair<LogicalVariable, LogicalVariable> pair)
- throws AlgebricksException {
- List<Triple<LogicalVariable, LogicalVariable, LogicalVariable>> varMap = op.getVariableMappings();
- for (Triple<LogicalVariable, LogicalVariable, LogicalVariable> t : varMap) {
- if (t.first.equals(pair.first)) {
- t.first = pair.second;
- }
- if (t.second.equals(pair.first)) {
- t.second = pair.second;
- }
- if (t.third.equals(pair.first)) {
- t.third = pair.second;
- }
- }
- substVarTypes(op, pair);
- return null;
- }
-
- @Override
- public Void visitUnnestMapOperator(UnnestMapOperator op, Pair<LogicalVariable, LogicalVariable> pair)
- throws AlgebricksException {
- List<LogicalVariable> variables = op.getVariables();
- for (int i = 0; i < variables.size(); i++) {
- if (variables.get(i) == pair.first) {
- variables.set(i, pair.second);
- return null;
- }
- }
- op.getExpressionRef().getValue().substituteVar(pair.first, pair.second);
- substVarTypes(op, pair);
- return null;
- }
-
- @Override
- public Void visitUnnestOperator(UnnestOperator op, Pair<LogicalVariable, LogicalVariable> pair)
- throws AlgebricksException {
- List<LogicalVariable> variables = op.getVariables();
- for (int i = 0; i < variables.size(); i++) {
- if (variables.get(i) == pair.first) {
- variables.set(i, pair.second);
- return null;
- }
- }
- op.getExpressionRef().getValue().substituteVar(pair.first, pair.second);
- substVarTypes(op, pair);
- return null;
- }
-
- @Override
- public Void visitWriteOperator(WriteOperator op, Pair<LogicalVariable, LogicalVariable> pair)
- throws AlgebricksException {
- for (Mutable<ILogicalExpression> e : op.getExpressions()) {
- e.getValue().substituteVar(pair.first, pair.second);
- }
- substVarTypes(op, pair);
- return null;
- }
-
- @Override
- public Void visitDistributeResultOperator(DistributeResultOperator op, Pair<LogicalVariable, LogicalVariable> pair)
- throws AlgebricksException {
- for (Mutable<ILogicalExpression> e : op.getExpressions()) {
- e.getValue().substituteVar(pair.first, pair.second);
- }
- substVarTypes(op, pair);
- return null;
- }
-
- @Override
- public Void visitWriteResultOperator(WriteResultOperator op, Pair<LogicalVariable, LogicalVariable> pair)
- throws AlgebricksException {
- op.getPayloadExpression().getValue().substituteVar(pair.first, pair.second);
- for (Mutable<ILogicalExpression> e : op.getKeyExpressions()) {
- e.getValue().substituteVar(pair.first, pair.second);
- }
- substVarTypes(op, pair);
- return null;
- }
-
- private void subst(LogicalVariable v1, LogicalVariable v2,
- List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> varExprPairList) {
- for (Pair<LogicalVariable, Mutable<ILogicalExpression>> ve : varExprPairList) {
- if (ve.first != null && ve.first.equals(v1)) {
- ve.first = v2;
- return;
- }
- ve.second.getValue().substituteVar(v1, v2);
- }
- }
-
- private void substInArray(ArrayList<LogicalVariable> varArray, LogicalVariable v1, LogicalVariable v2) {
- for (int i = 0; i < varArray.size(); i++) {
- LogicalVariable v = varArray.get(i);
- if (v == v1) {
- varArray.set(i, v2);
- }
- }
- }
-
- @Override
- public Void visitReplicateOperator(ReplicateOperator op, Pair<LogicalVariable, LogicalVariable> arg)
- throws AlgebricksException {
- op.substituteVar(arg.first, arg.second);
- return null;
- }
-
- @Override
- public Void visitMaterializeOperator(MaterializeOperator op, Pair<LogicalVariable, LogicalVariable> arg)
- throws AlgebricksException {
- return null;
- }
-
- @Override
- public Void visitInsertDeleteOperator(InsertDeleteOperator op, Pair<LogicalVariable, LogicalVariable> pair)
- throws AlgebricksException {
- op.getPayloadExpression().getValue().substituteVar(pair.first, pair.second);
- for (Mutable<ILogicalExpression> e : op.getPrimaryKeyExpressions()) {
- e.getValue().substituteVar(pair.first, pair.second);
- }
- substVarTypes(op, pair);
- return null;
- }
-
- @Override
- public Void visitIndexInsertDeleteOperator(IndexInsertDeleteOperator op, Pair<LogicalVariable, LogicalVariable> pair)
- throws AlgebricksException {
- for (Mutable<ILogicalExpression> e : op.getPrimaryKeyExpressions()) {
- e.getValue().substituteVar(pair.first, pair.second);
- }
- for (Mutable<ILogicalExpression> e : op.getSecondaryKeyExpressions()) {
- e.getValue().substituteVar(pair.first, pair.second);
- }
- substVarTypes(op, pair);
- return null;
- }
-
- @Override
- public Void visitTokenizeOperator(TokenizeOperator op, Pair<LogicalVariable, LogicalVariable> pair)
- throws AlgebricksException {
- for (Mutable<ILogicalExpression> e : op.getPrimaryKeyExpressions()) {
- e.getValue().substituteVar(pair.first, pair.second);
- }
- for (Mutable<ILogicalExpression> e : op.getSecondaryKeyExpressions()) {
- e.getValue().substituteVar(pair.first, pair.second);
- }
- substVarTypes(op, pair);
- return null;
- }
-
- @Override
- public Void visitSinkOperator(SinkOperator op, Pair<LogicalVariable, LogicalVariable> pair)
- throws AlgebricksException {
- return null;
- }
-
- private void substVarTypes(ILogicalOperator op, Pair<LogicalVariable, LogicalVariable> arg)
- throws AlgebricksException {
- if (ctx == null) {
- return;
- }
- IVariableTypeEnvironment env = ctx.getOutputTypeEnvironment(op);
- env.substituteProducedVariable(arg.first, arg.second);
- }
-
- @Override
- public Void visitExtensionOperator(ExtensionOperator op, Pair<LogicalVariable, LogicalVariable> arg)
- throws AlgebricksException {
- return null;
- }
-
- @Override
- public Void visitExternalDataLookupOperator(ExternalDataLookupOperator op,
- Pair<LogicalVariable, LogicalVariable> pair) throws AlgebricksException {
- List<LogicalVariable> variables = op.getVariables();
- for (int i = 0; i < variables.size(); i++) {
- if (variables.get(i) == pair.first) {
- variables.set(i, pair.second);
- return null;
- }
- }
- op.getExpressionRef().getValue().substituteVar(pair.first, pair.second);
- substVarTypes(op, pair);
- return null;
- }
-}
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/algebra/operators/logical/visitors/UsedVariableVisitor.java
----------------------------------------------------------------------
diff --git a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/algebra/operators/logical/visitors/UsedVariableVisitor.java b/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/algebra/operators/logical/visitors/UsedVariableVisitor.java
deleted file mode 100644
index 8169ad0..0000000
--- a/algebricks/algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/algebra/operators/logical/visitors/UsedVariableVisitor.java
+++ /dev/null
@@ -1,407 +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.algebra.operators.logical.visitors;
-
-import java.util.Collection;
-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.common.utils.Triple;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalPlan;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.IPhysicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalVariable;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AssignOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.DataSourceScanOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.DistinctOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.DistributeResultOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.EmptyTupleSourceOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ExchangeOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ExtensionOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ExternalDataLookupOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.IndexInsertDeleteOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.InsertDeleteOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.LeftOuterJoinOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.LimitOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.MaterializeOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.NestedTupleSourceOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.OrderOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.OrderOperator.IOrder;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.PartitioningSplitOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ProjectOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ReplicateOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.RunningAggregateOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ScriptOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.SelectOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.SinkOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.SubplanOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.TokenizeOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.UnionAllOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.UnnestMapOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.UnnestOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.WriteOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.WriteResultOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.physical.HashPartitionExchangePOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.physical.HashPartitionMergeExchangePOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.physical.RangePartitionMergePOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.physical.RangePartitionPOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.physical.SortMergeExchangePOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.properties.OrderColumn;
-import edu.uci.ics.hyracks.algebricks.core.algebra.visitors.ILogicalOperatorVisitor;
-
-public class UsedVariableVisitor implements ILogicalOperatorVisitor<Void, Void> {
-
- private Collection<LogicalVariable> usedVariables;
-
- public UsedVariableVisitor(Collection<LogicalVariable> usedVariables) {
- this.usedVariables = usedVariables;
- }
-
- @Override
- public Void visitAggregateOperator(AggregateOperator op, Void arg) {
- for (Mutable<ILogicalExpression> exprRef : op.getExpressions()) {
- exprRef.getValue().getUsedVariables(usedVariables);
- }
- return null;
- }
-
- @Override
- public Void visitAssignOperator(AssignOperator op, Void arg) {
- for (Mutable<ILogicalExpression> exprRef : op.getExpressions()) {
- exprRef.getValue().getUsedVariables(usedVariables);
- }
- return null;
- }
-
- @Override
- public Void visitDataScanOperator(DataSourceScanOperator op, Void arg) {
- if (op.getAdditionalFilteringExpressions() != null) {
- for (Mutable<ILogicalExpression> e : op.getAdditionalFilteringExpressions()) {
- e.getValue().getUsedVariables(usedVariables);
- }
- }
- return null;
- }
-
- @Override
- public Void visitDistinctOperator(DistinctOperator op, Void arg) {
- for (Mutable<ILogicalExpression> eRef : op.getExpressions()) {
- eRef.getValue().getUsedVariables(usedVariables);
- }
- return null;
- }
-
- @Override
- public Void visitEmptyTupleSourceOperator(EmptyTupleSourceOperator op, Void arg) {
- // does not use any variable
- return null;
- }
-
- @Override
- public Void visitExchangeOperator(ExchangeOperator op, Void arg) throws AlgebricksException {
- // Used variables depend on the physical operator.
- if (op.getPhysicalOperator() != null) {
- IPhysicalOperator physOp = op.getPhysicalOperator();
- switch (physOp.getOperatorTag()) {
- case BROADCAST_EXCHANGE:
- case ONE_TO_ONE_EXCHANGE:
- case RANDOM_MERGE_EXCHANGE: {
- // No variables used.
- break;
- }
- case HASH_PARTITION_EXCHANGE: {
- HashPartitionExchangePOperator concreteOp = (HashPartitionExchangePOperator) physOp;
- usedVariables.addAll(concreteOp.getHashFields());
- break;
- }
- case HASH_PARTITION_MERGE_EXCHANGE: {
- HashPartitionMergeExchangePOperator concreteOp = (HashPartitionMergeExchangePOperator) physOp;
- usedVariables.addAll(concreteOp.getPartitionFields());
- for (OrderColumn orderCol : concreteOp.getOrderColumns()) {
- usedVariables.add(orderCol.getColumn());
- }
- break;
- }
- case SORT_MERGE_EXCHANGE: {
- SortMergeExchangePOperator concreteOp = (SortMergeExchangePOperator) physOp;
- for (OrderColumn orderCol : concreteOp.getSortColumns()) {
- usedVariables.add(orderCol.getColumn());
- }
- break;
- }
- case RANGE_PARTITION_EXCHANGE: {
- RangePartitionPOperator concreteOp = (RangePartitionPOperator) physOp;
- for (OrderColumn partCol : concreteOp.getPartitioningFields()) {
- usedVariables.add(partCol.getColumn());
- }
- break;
- }
- case RANGE_PARTITION_MERGE_EXCHANGE: {
- RangePartitionMergePOperator concreteOp = (RangePartitionMergePOperator) physOp;
- for (OrderColumn partCol : concreteOp.getPartitioningFields()) {
- usedVariables.add(partCol.getColumn());
- }
- break;
- }
- default: {
- throw new AlgebricksException("Unhandled physical operator tag '" + physOp.getOperatorTag() + "'.");
- }
- }
- }
- return null;
- }
-
- @Override
- public Void visitGroupByOperator(GroupByOperator op, Void arg) throws AlgebricksException {
- for (ILogicalPlan p : op.getNestedPlans()) {
- for (Mutable<ILogicalOperator> r : p.getRoots()) {
- VariableUtilities.getUsedVariablesInDescendantsAndSelf(r.getValue(), usedVariables);
- }
- }
- for (Pair<LogicalVariable, Mutable<ILogicalExpression>> g : op.getGroupByList()) {
- g.second.getValue().getUsedVariables(usedVariables);
- }
- for (Pair<LogicalVariable, Mutable<ILogicalExpression>> g : op.getDecorList()) {
- g.second.getValue().getUsedVariables(usedVariables);
- }
- return null;
- }
-
- @Override
- public Void visitInnerJoinOperator(InnerJoinOperator op, Void arg) {
- op.getCondition().getValue().getUsedVariables(usedVariables);
- return null;
- }
-
- @Override
- public Void visitLeftOuterJoinOperator(LeftOuterJoinOperator op, Void arg) {
- op.getCondition().getValue().getUsedVariables(usedVariables);
- return null;
- }
-
- @Override
- public Void visitLimitOperator(LimitOperator op, Void arg) {
- op.getMaxObjects().getValue().getUsedVariables(usedVariables);
- ILogicalExpression offsetExpr = op.getOffset().getValue();
- if (offsetExpr != null) {
- offsetExpr.getUsedVariables(usedVariables);
- }
- return null;
- }
-
- @Override
- public Void visitNestedTupleSourceOperator(NestedTupleSourceOperator op, Void arg) {
- // does not use any variable
- return null;
- }
-
- @Override
- public Void visitOrderOperator(OrderOperator op, Void arg) {
- for (Pair<IOrder, Mutable<ILogicalExpression>> oe : op.getOrderExpressions()) {
- oe.second.getValue().getUsedVariables(usedVariables);
- }
- return null;
- }
-
- @Override
- public Void visitPartitioningSplitOperator(PartitioningSplitOperator op, Void arg) {
- for (Mutable<ILogicalExpression> e : op.getExpressions()) {
- e.getValue().getUsedVariables(usedVariables);
- }
- return null;
- }
-
- @Override
- public Void visitProjectOperator(ProjectOperator op, Void arg) {
- List<LogicalVariable> parameterVariables = op.getVariables();
- for (LogicalVariable v : parameterVariables) {
- if (!usedVariables.contains(v)) {
- usedVariables.add(v);
- }
- }
- return null;
- }
-
- @Override
- public Void visitRunningAggregateOperator(RunningAggregateOperator op, Void arg) {
- for (Mutable<ILogicalExpression> exprRef : op.getExpressions()) {
- exprRef.getValue().getUsedVariables(usedVariables);
- }
- return null;
- }
-
- @Override
- public Void visitScriptOperator(ScriptOperator op, Void arg) {
- List<LogicalVariable> parameterVariables = op.getInputVariables();
- for (LogicalVariable v : parameterVariables) {
- if (!usedVariables.contains(v)) {
- usedVariables.add(v);
- }
- }
- return null;
- }
-
- @Override
- public Void visitSelectOperator(SelectOperator op, Void arg) {
- op.getCondition().getValue().getUsedVariables(usedVariables);
- return null;
- }
-
- @Override
- public Void visitSubplanOperator(SubplanOperator op, Void arg) throws AlgebricksException {
- for (ILogicalPlan p : op.getNestedPlans()) {
- for (Mutable<ILogicalOperator> r : p.getRoots()) {
- VariableUtilities.getUsedVariablesInDescendantsAndSelf(r.getValue(), usedVariables);
- }
- }
- return null;
- }
-
- @Override
- public Void visitUnionOperator(UnionAllOperator op, Void arg) {
- for (Triple<LogicalVariable, LogicalVariable, LogicalVariable> m : op.getVariableMappings()) {
- if (!usedVariables.contains(m.first)) {
- usedVariables.add(m.first);
- }
- if (!usedVariables.contains(m.second)) {
- usedVariables.add(m.second);
- }
- }
- return null;
- }
-
- @Override
- public Void visitUnnestMapOperator(UnnestMapOperator op, Void arg) {
- op.getExpressionRef().getValue().getUsedVariables(usedVariables);
- if (op.getAdditionalFilteringExpressions() != null) {
- for (Mutable<ILogicalExpression> e : op.getAdditionalFilteringExpressions()) {
- e.getValue().getUsedVariables(usedVariables);
- }
- }
- return null;
- }
-
- @Override
- public Void visitUnnestOperator(UnnestOperator op, Void arg) {
- op.getExpressionRef().getValue().getUsedVariables(usedVariables);
- return null;
- }
-
- @Override
- public Void visitWriteOperator(WriteOperator op, Void arg) {
- for (Mutable<ILogicalExpression> expr : op.getExpressions()) {
- expr.getValue().getUsedVariables(usedVariables);
- }
- return null;
- }
-
- @Override
- public Void visitDistributeResultOperator(DistributeResultOperator op, Void arg) {
- for (Mutable<ILogicalExpression> expr : op.getExpressions()) {
- expr.getValue().getUsedVariables(usedVariables);
- }
- return null;
- }
-
- @Override
- public Void visitWriteResultOperator(WriteResultOperator op, Void arg) {
- op.getPayloadExpression().getValue().getUsedVariables(usedVariables);
- for (Mutable<ILogicalExpression> e : op.getKeyExpressions()) {
- e.getValue().getUsedVariables(usedVariables);
- }
- if (op.getAdditionalFilteringExpressions() != null) {
- for (Mutable<ILogicalExpression> e : op.getAdditionalFilteringExpressions()) {
- e.getValue().getUsedVariables(usedVariables);
- }
- }
- return null;
- }
-
- @Override
- public Void visitInsertDeleteOperator(InsertDeleteOperator op, Void arg) {
- op.getPayloadExpression().getValue().getUsedVariables(usedVariables);
- for (Mutable<ILogicalExpression> e : op.getPrimaryKeyExpressions()) {
- e.getValue().getUsedVariables(usedVariables);
- }
- if (op.getAdditionalFilteringExpressions() != null) {
- for (Mutable<ILogicalExpression> e : op.getAdditionalFilteringExpressions()) {
- e.getValue().getUsedVariables(usedVariables);
- }
- }
- return null;
- }
-
- @Override
- public Void visitIndexInsertDeleteOperator(IndexInsertDeleteOperator op, Void arg) {
- for (Mutable<ILogicalExpression> e : op.getPrimaryKeyExpressions()) {
- e.getValue().getUsedVariables(usedVariables);
- }
- for (Mutable<ILogicalExpression> e : op.getSecondaryKeyExpressions()) {
- e.getValue().getUsedVariables(usedVariables);
- }
- if (op.getAdditionalFilteringExpressions() != null) {
- for (Mutable<ILogicalExpression> e : op.getAdditionalFilteringExpressions()) {
- e.getValue().getUsedVariables(usedVariables);
- }
- }
- return null;
- }
-
- @Override
- public Void visitTokenizeOperator(TokenizeOperator op, Void arg) {
- for (Mutable<ILogicalExpression> e : op.getPrimaryKeyExpressions()) {
- e.getValue().getUsedVariables(usedVariables);
- }
- for (Mutable<ILogicalExpression> e : op.getSecondaryKeyExpressions()) {
- e.getValue().getUsedVariables(usedVariables);
- }
- return null;
- }
-
- @Override
- public Void visitSinkOperator(SinkOperator op, Void arg) {
- return null;
- }
-
- @Override
- public Void visitReplicateOperator(ReplicateOperator op, Void arg) throws AlgebricksException {
- return null;
- }
-
- @Override
- public Void visitMaterializeOperator(MaterializeOperator op, Void arg) throws AlgebricksException {
- return null;
- }
-
- @Override
- public Void visitExtensionOperator(ExtensionOperator op, Void arg) throws AlgebricksException {
- op.getDelegate().getUsedVariables(usedVariables);
- return null;
- }
-
- @Override
- public Void visitExternalDataLookupOperator(ExternalDataLookupOperator op, Void arg) throws AlgebricksException {
- op.getExpressionRef().getValue().getUsedVariables(usedVariables);
- return null;
- }
-
-}