You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vxquery.apache.org by pr...@apache.org on 2013/08/31 00:08:05 UTC
svn commit: r1519100 - in
/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules:
EliminateSubplanForSinglePathsRule.java
RemoveUnusedSortDistinctNodesRule.java util/ util/CardinalityRuleToolbox.java
Author: prestonc
Date: Fri Aug 30 22:08:05 2013
New Revision: 1519100
URL: http://svn.apache.org/r1519100
Log:
Add the DISTRIBUTE_RESULT operator to the switch statements and moved the cardinality static function to a util class.
Added:
incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/util/
incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/util/CardinalityRuleToolbox.java (with props)
Modified:
incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/EliminateSubplanForSinglePathsRule.java
incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/RemoveUnusedSortDistinctNodesRule.java
Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/EliminateSubplanForSinglePathsRule.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/EliminateSubplanForSinglePathsRule.java?rev=1519100&r1=1519099&r2=1519100&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/EliminateSubplanForSinglePathsRule.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/EliminateSubplanForSinglePathsRule.java Fri Aug 30 22:08:05 2013
@@ -19,14 +19,13 @@ package org.apache.vxquery.compiler.rewr
import org.apache.commons.lang3.mutable.Mutable;
import org.apache.vxquery.compiler.rewriter.VXQueryOptimizationContext;
import org.apache.vxquery.compiler.rewriter.rules.propagationpolicies.cardinality.Cardinality;
+import org.apache.vxquery.compiler.rewriter.rules.util.CardinalityRuleToolbox;
import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.IOptimizationContext;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractOperatorWithNestedPlans;
-import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.NestedTupleSourceOperator;
import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.SubplanOperator;
import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
@@ -67,7 +66,7 @@ public class EliminateSubplanForSinglePa
// Set cardinality in the context. Must update each time the rule is run.
VXQueryOptimizationContext vxqueryContext = (VXQueryOptimizationContext) context;
- Cardinality cardinalityVariable = getProducerCardinality(opRef.getValue(), vxqueryContext);
+ Cardinality cardinalityVariable = CardinalityRuleToolbox.getProducerCardinality(opRef.getValue(), vxqueryContext);
if (op.getOperatorTag() == LogicalOperatorTag.SUBPLAN && cardinalityVariable == Cardinality.ONE) {
SubplanOperator subplan = (SubplanOperator) op;
@@ -88,7 +87,7 @@ public class EliminateSubplanForSinglePa
}
// Now with the new operator, update the variable mappings.
- cardinalityVariable = updateCardinalityVariable(op, cardinalityVariable, vxqueryContext);
+ cardinalityVariable = CardinalityRuleToolbox.updateCardinalityVariable(op, cardinalityVariable, vxqueryContext);
// Save propagated value.
vxqueryContext.putCardinalityOperatorMap(opRef.getValue(), cardinalityVariable);
@@ -107,81 +106,6 @@ public class EliminateSubplanForSinglePa
return op;
}
- /**
- * Get the Cardinality variable of the parent operator.
- *
- * @param op
- * @param vxqueryContext
- * @return
- */
- private Cardinality getProducerCardinality(ILogicalOperator op, VXQueryOptimizationContext vxqueryContext) {
- AbstractLogicalOperator producerOp = (AbstractLogicalOperator) op.getInputs().get(0).getValue();
- switch (producerOp.getOperatorTag()) {
- case EMPTYTUPLESOURCE:
- return Cardinality.ONE;
- case NESTEDTUPLESOURCE:
- NestedTupleSourceOperator nestedTuplesource = (NestedTupleSourceOperator) producerOp;
- return getProducerCardinality(nestedTuplesource.getDataSourceReference().getValue(), vxqueryContext);
- default:
- return vxqueryContext.getCardinalityOperatorMap(producerOp);
- }
- }
-
- private Cardinality updateCardinalityVariable(AbstractLogicalOperator op, Cardinality cardinalityVariable,
- VXQueryOptimizationContext vxqueryContext) {
- switch (op.getOperatorTag()) {
- case AGGREGATE:
- cardinalityVariable = Cardinality.ONE;
- break;
- case GROUP:
- case SUBPLAN:
- // Find the last operator to set a variable and call this function again.
- AbstractOperatorWithNestedPlans operatorWithNestedPlan = (AbstractOperatorWithNestedPlans) op;
- AbstractLogicalOperator lastOperator = (AbstractLogicalOperator) operatorWithNestedPlan
- .getNestedPlans().get(0).getRoots().get(0).getValue();
- cardinalityVariable = vxqueryContext.getCardinalityOperatorMap(lastOperator);
- break;
- case DATASOURCESCAN:
- case UNNEST:
- cardinalityVariable = Cardinality.MANY;
- break;
-
- // The following operators do not change the variable.
- case ASSIGN:
- case EMPTYTUPLESOURCE:
- case EXCHANGE:
- case LIMIT:
- case NESTEDTUPLESOURCE:
- case ORDER:
- case PROJECT:
- case SELECT:
- case WRITE:
- case WRITE_RESULT:
- break;
-
- // The following operators' analysis has not yet been implemented.
- case CLUSTER:
- case DISTINCT:
- case EXTENSION_OPERATOR:
- case INDEX_INSERT_DELETE:
- case INNERJOIN:
- case INSERT_DELETE:
- case LEFTOUTERJOIN:
- case PARTITIONINGSPLIT:
- case REPLICATE:
- case RUNNINGAGGREGATE:
- case SCRIPT:
- case SINK:
- case UNIONALL:
- case UNNEST_MAP:
- case UPDATE:
- default:
- throw new RuntimeException("Operator (" + op.getOperatorTag()
- + ") has not been implemented in rewrite rule.");
- }
- return cardinalityVariable;
- }
-
@Override
public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) {
return false;
Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/RemoveUnusedSortDistinctNodesRule.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/RemoveUnusedSortDistinctNodesRule.java?rev=1519100&r1=1519099&r2=1519100&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/RemoveUnusedSortDistinctNodesRule.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/RemoveUnusedSortDistinctNodesRule.java Fri Aug 30 22:08:05 2013
@@ -26,6 +26,7 @@ import org.apache.vxquery.compiler.rewri
import org.apache.vxquery.compiler.rewriter.rules.propagationpolicies.cardinality.Cardinality;
import org.apache.vxquery.compiler.rewriter.rules.propagationpolicies.documentorder.DocumentOrder;
import org.apache.vxquery.compiler.rewriter.rules.propagationpolicies.uniquenodes.UniqueNodes;
+import org.apache.vxquery.compiler.rewriter.rules.util.CardinalityRuleToolbox;
import org.apache.vxquery.functions.BuiltinOperators;
import org.apache.vxquery.functions.Function;
@@ -112,7 +113,8 @@ public class RemoveUnusedSortDistinctNod
VXQueryOptimizationContext vxqueryContext = (VXQueryOptimizationContext) context;
// Find the available variables.
- Cardinality cardinalityVariable = getProducerCardinality(opRef.getValue(), vxqueryContext);
+ Cardinality cardinalityVariable = CardinalityRuleToolbox.getProducerCardinality(opRef.getValue(),
+ vxqueryContext);
HashMap<Integer, DocumentOrder> documentOrderVariables = getProducerDocumentOrderVariableMap(opRef.getValue(),
vxqueryContext);
HashMap<Integer, UniqueNodes> uniqueNodesVariables = getProducerUniqueNodesVariableMap(opRef.getValue(),
@@ -152,7 +154,7 @@ public class RemoveUnusedSortDistinctNod
}
// Now with the new operator, update the variable mappings.
- cardinalityVariable = updateCardinalityVariable(op, cardinalityVariable, vxqueryContext);
+ cardinalityVariable = CardinalityRuleToolbox.updateCardinalityVariable(op, cardinalityVariable, vxqueryContext);
updateVariableMap(op, cardinalityVariable, documentOrderVariables, uniqueNodesVariables, vxqueryContext);
// Save propagated value.
@@ -192,26 +194,6 @@ public class RemoveUnusedSortDistinctNod
}
/**
- * Get the Cardinality variable of the parent operator.
- *
- * @param op
- * @param vxqueryContext
- * @return
- */
- private Cardinality getProducerCardinality(ILogicalOperator op, VXQueryOptimizationContext vxqueryContext) {
- AbstractLogicalOperator producerOp = (AbstractLogicalOperator) op.getInputs().get(0).getValue();
- switch (producerOp.getOperatorTag()) {
- case EMPTYTUPLESOURCE:
- return Cardinality.ONE;
- case NESTEDTUPLESOURCE:
- NestedTupleSourceOperator nestedTuplesource = (NestedTupleSourceOperator) producerOp;
- return getProducerCardinality(nestedTuplesource.getDataSourceReference().getValue(), vxqueryContext);
- default:
- return vxqueryContext.getCardinalityOperatorMap(producerOp);
- }
- }
-
- /**
* Get the DocumentOrder variable map of the parent operator.
*
* @param op
@@ -339,61 +321,6 @@ public class RemoveUnusedSortDistinctNod
}
}
- private Cardinality updateCardinalityVariable(AbstractLogicalOperator op, Cardinality cardinalityVariable,
- VXQueryOptimizationContext vxqueryContext) {
- switch (op.getOperatorTag()) {
- case AGGREGATE:
- cardinalityVariable = Cardinality.ONE;
- break;
- case GROUP:
- case SUBPLAN:
- // Find the last operator to set a variable and call this function again.
- AbstractOperatorWithNestedPlans operatorWithNestedPlan = (AbstractOperatorWithNestedPlans) op;
- AbstractLogicalOperator lastOperator = (AbstractLogicalOperator) operatorWithNestedPlan
- .getNestedPlans().get(0).getRoots().get(0).getValue();
- cardinalityVariable = vxqueryContext.getCardinalityOperatorMap(lastOperator);
- break;
- case DATASOURCESCAN:
- case UNNEST:
- cardinalityVariable = Cardinality.MANY;
- break;
-
- // The following operators do not change the variable.
- case ASSIGN:
- case EMPTYTUPLESOURCE:
- case EXCHANGE:
- case LIMIT:
- case NESTEDTUPLESOURCE:
- case ORDER:
- case PROJECT:
- case SELECT:
- case WRITE:
- case WRITE_RESULT:
- break;
-
- // The following operators' analysis has not yet been implemented.
- case CLUSTER:
- case DISTINCT:
- case EXTENSION_OPERATOR:
- case INDEX_INSERT_DELETE:
- case INNERJOIN:
- case INSERT_DELETE:
- case LEFTOUTERJOIN:
- case PARTITIONINGSPLIT:
- case REPLICATE:
- case RUNNINGAGGREGATE:
- case SCRIPT:
- case SINK:
- case UNIONALL:
- case UNNEST_MAP:
- case UPDATE:
- default:
- throw new RuntimeException("Operator (" + op.getOperatorTag()
- + ") has not been implemented in rewrite rule.");
- }
- return cardinalityVariable;
- }
-
private void updateVariableMap(AbstractLogicalOperator op, Cardinality cardinalityVariable,
HashMap<Integer, DocumentOrder> documentOrderVariables, HashMap<Integer, UniqueNodes> uniqueNodesVariables,
VXQueryOptimizationContext vxqueryContext) {
@@ -485,6 +412,7 @@ public class RemoveUnusedSortDistinctNod
// The following operators do not change or add to the variable map.
case DATASOURCESCAN:
+ case DISTRIBUTE_RESULT:
case EMPTYTUPLESOURCE:
case EXCHANGE:
case NESTEDTUPLESOURCE:
Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/util/CardinalityRuleToolbox.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/util/CardinalityRuleToolbox.java?rev=1519100&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/util/CardinalityRuleToolbox.java (added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/util/CardinalityRuleToolbox.java Fri Aug 30 22:08:05 2013
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 at
+ *
+ * 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 org.apache.vxquery.compiler.rewriter.rules.util;
+
+import org.apache.vxquery.compiler.rewriter.VXQueryOptimizationContext;
+import org.apache.vxquery.compiler.rewriter.rules.propagationpolicies.cardinality.Cardinality;
+
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
+import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
+import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractOperatorWithNestedPlans;
+import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.NestedTupleSourceOperator;
+
+public class CardinalityRuleToolbox {
+ /**
+ * Get the Cardinality variable of the parent operator.
+ *
+ * @param op
+ * @param vxqueryContext
+ * @return
+ */
+ public static Cardinality getProducerCardinality(ILogicalOperator op, VXQueryOptimizationContext vxqueryContext) {
+ AbstractLogicalOperator producerOp = (AbstractLogicalOperator) op.getInputs().get(0).getValue();
+ switch (producerOp.getOperatorTag()) {
+ case EMPTYTUPLESOURCE:
+ return Cardinality.ONE;
+ case NESTEDTUPLESOURCE:
+ NestedTupleSourceOperator nestedTuplesource = (NestedTupleSourceOperator) producerOp;
+ return getProducerCardinality(nestedTuplesource.getDataSourceReference().getValue(), vxqueryContext);
+ default:
+ return vxqueryContext.getCardinalityOperatorMap(producerOp);
+ }
+ }
+
+ public static Cardinality updateCardinalityVariable(AbstractLogicalOperator op, Cardinality cardinalityVariable,
+ VXQueryOptimizationContext vxqueryContext) {
+ switch (op.getOperatorTag()) {
+ case AGGREGATE:
+ cardinalityVariable = Cardinality.ONE;
+ break;
+ case GROUP:
+ case SUBPLAN:
+ // Find the last operator to set a variable and call this function again.
+ AbstractOperatorWithNestedPlans operatorWithNestedPlan = (AbstractOperatorWithNestedPlans) op;
+ AbstractLogicalOperator lastOperator = (AbstractLogicalOperator) operatorWithNestedPlan
+ .getNestedPlans().get(0).getRoots().get(0).getValue();
+ cardinalityVariable = vxqueryContext.getCardinalityOperatorMap(lastOperator);
+ break;
+ case DATASOURCESCAN:
+ case UNNEST:
+ cardinalityVariable = Cardinality.MANY;
+ break;
+
+ // The following operators do not change the variable.
+ case ASSIGN:
+ case DISTRIBUTE_RESULT:
+ case EMPTYTUPLESOURCE:
+ case EXCHANGE:
+ case LIMIT:
+ case NESTEDTUPLESOURCE:
+ case ORDER:
+ case PROJECT:
+ case SELECT:
+ case WRITE:
+ case WRITE_RESULT:
+ break;
+
+ // The following operators' analysis has not yet been implemented.
+ case CLUSTER:
+ case DISTINCT:
+ case EXTENSION_OPERATOR:
+ case INDEX_INSERT_DELETE:
+ case INNERJOIN:
+ case INSERT_DELETE:
+ case LEFTOUTERJOIN:
+ case PARTITIONINGSPLIT:
+ case REPLICATE:
+ case RUNNINGAGGREGATE:
+ case SCRIPT:
+ case SINK:
+ case UNIONALL:
+ case UNNEST_MAP:
+ case UPDATE:
+ default:
+ throw new RuntimeException("Operator (" + op.getOperatorTag()
+ + ") has not been implemented in rewrite rule.");
+ }
+ return cardinalityVariable;
+ }
+}
Propchange: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/util/CardinalityRuleToolbox.java
------------------------------------------------------------------------------
svn:eol-style = native