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/05/15 22:45:46 UTC
svn commit: r1483074 - in
/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery:
compiler/rewriter/ compiler/rewriter/rules/ metadata/ xmlparser/
Author: prestonc
Date: Wed May 15 20:45:45 2013
New Revision: 1483074
URL: http://svn.apache.org/r1483074
Log:
Finished the last part of getting the id-from-node function to work properly. Now a combined node tree id and local id can be combined to produce a node id.
Added:
incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/AbstractCollectionRule.java (with props)
incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/SetCollectionDataSourceRule.java (with props)
Modified:
incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/RewriteRuleset.java
incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/IntroduceCollectionRule.java
incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryCollectionDataSource.java
incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryCollectionOperatorDescriptor.java
incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryMetadataProvider.java
incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/xmlparser/TreeNodeIdProvider.java
Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/RewriteRuleset.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/RewriteRuleset.java?rev=1483074&r1=1483073&r2=1483074&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/RewriteRuleset.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/RewriteRuleset.java Wed May 15 20:45:45 2013
@@ -24,6 +24,7 @@ import org.apache.vxquery.compiler.rewri
import org.apache.vxquery.compiler.rewriter.rules.IntroduceCollectionRule;
import org.apache.vxquery.compiler.rewriter.rules.IntroduceTwoStepAggregateRule;
import org.apache.vxquery.compiler.rewriter.rules.RemoveUnusedSortDistinctNodesRule;
+import org.apache.vxquery.compiler.rewriter.rules.SetCollectionDataSourceRule;
import edu.uci.ics.hyracks.algebricks.core.rewriter.base.HeuristicOptimizer;
import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
@@ -61,7 +62,11 @@ public class RewriteRuleset {
normalization.add(new ConsolidateAssignAggregateRule());
normalization.add(new RemoveUnusedAssignAndAggregateRule());
normalization.add(new EliminateUnnestAggregateSubplanRule());
+
+ normalization.add(new SetCollectionDataSourceRule());
normalization.add(new IntroduceCollectionRule());
+ normalization.add(new RemoveUnusedAssignAndAggregateRule());
+
normalization.add(new IntroduceTwoStepAggregateRule());
return normalization;
}
Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/AbstractCollectionRule.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/AbstractCollectionRule.java?rev=1483074&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/AbstractCollectionRule.java (added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/AbstractCollectionRule.java Wed May 15 20:45:45 2013
@@ -0,0 +1,153 @@
+/*
+ * 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;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+import org.apache.commons.lang3.mutable.Mutable;
+import org.apache.vxquery.compiler.algebricks.VXQueryConstantValue;
+import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
+import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.functions.BuiltinFunctions;
+import org.apache.vxquery.functions.BuiltinOperators;
+import org.apache.vxquery.types.BuiltinTypeRegistry;
+import org.apache.vxquery.types.Quantifier;
+import org.apache.vxquery.types.SequenceType;
+
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.IOptimizationContext;
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalExpressionTag;
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.ConstantExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
+import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AssignOperator;
+import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.UnnestOperator;
+import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+import edu.uci.ics.hyracks.dataflow.common.comm.util.ByteBufferInputStream;
+
+public abstract class AbstractCollectionRule implements IAlgebraicRewriteRule {
+ final ByteBufferInputStream bbis = new ByteBufferInputStream();
+ final DataInputStream di = new DataInputStream(bbis);
+ final UTF8StringPointable stringp = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
+ final TaggedValuePointable tvp = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
+
+ /**
+ * Get the constant value for the collection. Return null for not a collection.
+ */
+ protected String getCollectionName(Mutable<ILogicalOperator> opRef) throws AlgebricksException {
+ VXQueryConstantValue constantValue;
+
+ AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
+ if (op.getOperatorTag() != LogicalOperatorTag.UNNEST) {
+ return null;
+ }
+ UnnestOperator unnest = (UnnestOperator) op;
+
+ // Check if assign is for fn:Collection.
+ AbstractLogicalOperator op2 = (AbstractLogicalOperator) unnest.getInputs().get(0).getValue();
+ if (op2.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
+ return null;
+ }
+ AssignOperator assign = (AssignOperator) op2;
+
+ // Check to see if the expression is a function and fn:Collection.
+ ILogicalExpression logicalExpression = (ILogicalExpression) assign.getExpressions().get(0).getValue();
+ if (logicalExpression.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
+ return null;
+ }
+ AbstractFunctionCallExpression functionCall = (AbstractFunctionCallExpression) logicalExpression;
+ if (!functionCall.getFunctionIdentifier().equals(BuiltinFunctions.FN_COLLECTION_1.getFunctionIdentifier())) {
+ return null;
+ }
+
+ // Get the string assigned to the collection function.
+ AbstractLogicalOperator op3 = (AbstractLogicalOperator) assign.getInputs().get(0).getValue();
+ if (op3.getOperatorTag() == LogicalOperatorTag.ASSIGN) {
+ AssignOperator assign2 = (AssignOperator) op3;
+
+ // Check to see if the expression is a constant expression and type string.
+ ILogicalExpression logicalExpression2 = (ILogicalExpression) assign2.getExpressions().get(0).getValue();
+ if (logicalExpression2.getExpressionTag() != LogicalExpressionTag.CONSTANT) {
+ return null;
+ }
+ ConstantExpression constantExpression = (ConstantExpression) logicalExpression2;
+ constantValue = (VXQueryConstantValue) constantExpression.getValue();
+ if (constantValue.getType() != SequenceType.create(BuiltinTypeRegistry.XS_STRING, Quantifier.QUANT_ONE)) {
+ return null;
+ }
+ } else if (op3.getOperatorTag() == LogicalOperatorTag.EMPTYTUPLESOURCE) {
+ ILogicalExpression logicalExpression2 = (ILogicalExpression) functionCall.getArguments().get(0).getValue();
+ if (logicalExpression2.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
+ return null;
+ }
+ AbstractFunctionCallExpression functionCall2 = (AbstractFunctionCallExpression) logicalExpression2;
+ if (!functionCall2.getFunctionIdentifier().equals(BuiltinOperators.PROMOTE.getFunctionIdentifier())) {
+ return null;
+ }
+
+ ILogicalExpression logicalExpression3 = (ILogicalExpression) functionCall2.getArguments().get(0).getValue();
+ if (logicalExpression3.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
+ return null;
+ }
+ AbstractFunctionCallExpression functionCall3 = (AbstractFunctionCallExpression) logicalExpression3;
+ if (!functionCall3.getFunctionIdentifier().equals(BuiltinFunctions.FN_DATA_1.getFunctionIdentifier())) {
+ return null;
+ }
+
+ ILogicalExpression logicalExpression4 = (ILogicalExpression) functionCall3.getArguments().get(0).getValue();
+ if (logicalExpression4.getExpressionTag() != LogicalExpressionTag.CONSTANT) {
+ return null;
+ }
+ ConstantExpression constantExpression = (ConstantExpression) logicalExpression4;
+ constantValue = (VXQueryConstantValue) constantExpression.getValue();
+ if (constantValue.getType() != SequenceType.create(BuiltinTypeRegistry.XS_STRING, Quantifier.QUANT_ONE)) {
+ return null;
+ }
+ } else {
+ return null;
+ }
+
+ // Constant value is now in a TaggedValuePointable. Convert the value into a java String.
+ tvp.set(constantValue.getValue(), 0, constantValue.getValue().length);
+ String collectionName = null;
+ if (tvp.getTag() == ValueTag.XS_STRING_TAG) {
+ tvp.getValue(stringp);
+ try {
+ bbis.setByteBuffer(
+ ByteBuffer.wrap(Arrays.copyOfRange(stringp.getByteArray(), stringp.getStartOffset(),
+ stringp.getLength() + stringp.getStartOffset())), 0);
+ collectionName = di.readUTF();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return collectionName;
+ }
+
+ @Override
+ public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) {
+ return false;
+ }
+
+}
Propchange: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/AbstractCollectionRule.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/IntroduceCollectionRule.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/IntroduceCollectionRule.java?rev=1483074&r1=1483073&r2=1483074&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/IntroduceCollectionRule.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/IntroduceCollectionRule.java Wed May 15 20:45:45 2013
@@ -16,50 +16,19 @@
*/
package org.apache.vxquery.compiler.rewriter.rules;
-import java.io.DataInputStream;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
import org.apache.commons.lang3.mutable.Mutable;
-import org.apache.vxquery.compiler.algebricks.VXQueryConstantValue;
import org.apache.vxquery.compiler.rewriter.VXQueryOptimizationContext;
-import org.apache.vxquery.datamodel.accessors.SequencePointable;
-import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
-import org.apache.vxquery.datamodel.values.ValueTag;
-import org.apache.vxquery.functions.BuiltinFunctions;
-import org.apache.vxquery.functions.BuiltinOperators;
import org.apache.vxquery.metadata.VXQueryCollectionDataSource;
-import org.apache.vxquery.types.AnyItemType;
-import org.apache.vxquery.types.BuiltinTypeRegistry;
-import org.apache.vxquery.types.Quantifier;
-import org.apache.vxquery.types.SequenceType;
import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
import edu.uci.ics.hyracks.algebricks.core.algebra.base.IOptimizationContext;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalExpressionTag;
-import edu.uci.ics.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
-import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.ConstantExpression;
import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AssignOperator;
import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.DataSourceScanOperator;
import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.UnnestOperator;
-import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
-import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
-import edu.uci.ics.hyracks.dataflow.common.comm.util.ByteBufferInputStream;
-
-public class IntroduceCollectionRule implements IAlgebraicRewriteRule {
- final ByteBufferInputStream bbis = new ByteBufferInputStream();
- final DataInputStream di = new DataInputStream(bbis);
- final UTF8StringPointable stringp = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
- final TaggedValuePointable tvp = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
- final SequencePointable seqp = (SequencePointable) SequencePointable.FACTORY.createPointable();
+public class IntroduceCollectionRule extends AbstractCollectionRule {
/**
* Find the default query plan created for collection and updated it to use parallelization.
* The following is an example of of the operators we are looking with a constant for the collection name.
@@ -68,106 +37,27 @@ public class IntroduceCollectionRule imp
@Override
public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
VXQueryOptimizationContext vxqueryContext = (VXQueryOptimizationContext) context;
- VXQueryConstantValue constantValue;
-
- // Check if assign is for fn:Collection.
- AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
- if (op.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
- return false;
- }
- AssignOperator assign = (AssignOperator) op;
-
- // Check to see if the expression is a function and fn:Collection.
- ILogicalExpression logicalExpression = (ILogicalExpression) assign.getExpressions().get(0).getValue();
- if (logicalExpression.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
- return false;
- }
- AbstractFunctionCallExpression functionCall = (AbstractFunctionCallExpression) logicalExpression;
- if (!functionCall.getFunctionIdentifier().equals(BuiltinFunctions.FN_COLLECTION_1.getFunctionIdentifier())) {
- return false;
- }
-
- // Get the string assigned to the collection function.
- AbstractLogicalOperator op2 = (AbstractLogicalOperator) assign.getInputs().get(0).getValue();
- if (op2.getOperatorTag() == LogicalOperatorTag.ASSIGN) {
- AssignOperator assign2 = (AssignOperator) op2;
-
- // Check to see if the expression is a constant expression and type string.
- ILogicalExpression logicalExpression2 = (ILogicalExpression) assign2.getExpressions().get(0).getValue();
- if (logicalExpression2.getExpressionTag() != LogicalExpressionTag.CONSTANT) {
- return false;
- }
- ConstantExpression constantExpression = (ConstantExpression) logicalExpression2;
- constantValue = (VXQueryConstantValue) constantExpression.getValue();
- if (constantValue.getType() != SequenceType.create(BuiltinTypeRegistry.XS_STRING, Quantifier.QUANT_ONE)) {
- return false;
- }
- } else if (op2.getOperatorTag() == LogicalOperatorTag.EMPTYTUPLESOURCE) {
- ILogicalExpression logicalExpression2 = (ILogicalExpression) functionCall.getArguments().get(0).getValue();
- if (logicalExpression2.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
- return false;
- }
- AbstractFunctionCallExpression functionCall2 = (AbstractFunctionCallExpression) logicalExpression2;
- if (!functionCall2.getFunctionIdentifier().equals(BuiltinOperators.PROMOTE.getFunctionIdentifier())) {
- return false;
- }
-
- ILogicalExpression logicalExpression3 = (ILogicalExpression) functionCall2.getArguments().get(0).getValue();
- if (logicalExpression3.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
- return false;
- }
- AbstractFunctionCallExpression functionCall3 = (AbstractFunctionCallExpression) logicalExpression3;
- if (!functionCall3.getFunctionIdentifier().equals(BuiltinFunctions.FN_DATA_1.getFunctionIdentifier())) {
- return false;
- }
-
- ILogicalExpression logicalExpression4 = (ILogicalExpression) functionCall3.getArguments().get(0).getValue();
- if (logicalExpression4.getExpressionTag() != LogicalExpressionTag.CONSTANT) {
- return false;
- }
- ConstantExpression constantExpression = (ConstantExpression) logicalExpression4;
- constantValue = (VXQueryConstantValue) constantExpression.getValue();
- if (constantValue.getType() != SequenceType.create(BuiltinTypeRegistry.XS_STRING, Quantifier.QUANT_ONE)) {
- return false;
- }
- } else {
- return false;
- }
+ String collectionName = getCollectionName(opRef);
- // Constant value is now in a TaggedValuePointable. Convert the value into a java String.
- tvp.set(constantValue.getValue(), 0, constantValue.getValue().length);
- String collectionName = null;
- if (tvp.getTag() == ValueTag.XS_STRING_TAG) {
- tvp.getValue(stringp);
- try {
- bbis.setByteBuffer(
- ByteBuffer.wrap(Arrays.copyOfRange(stringp.getByteArray(), stringp.getStartOffset(),
- stringp.getLength() + stringp.getStartOffset())), 0);
- collectionName = di.readUTF();
- } catch (IOException e) {
- e.printStackTrace();
+ if (collectionName != null) {
+ // Build the new operator and update the query plan.
+ VXQueryCollectionDataSource ds = vxqueryContext.getCollectionDataSourceMap(collectionName);
+ if (ds != null) {
+ ds.setTotalDataSources(vxqueryContext.getCollectionDataSourceMapSize());
+
+ // Known to be true because of collection name.
+ AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
+ UnnestOperator unnest = (UnnestOperator) op;
+ AbstractLogicalOperator op2 = (AbstractLogicalOperator) unnest.getInputs().get(0).getValue();
+ AssignOperator assign = (AssignOperator) op2;
+
+ DataSourceScanOperator opNew = new DataSourceScanOperator(unnest.getVariables(), ds);
+ opNew.getInputs().addAll(assign.getInputs());
+ opRef.setValue(opNew);
+ return true;
}
}
-
- // Build the new operator and update the query plan.
- List<Object> types = new ArrayList<Object>();
- types.add(SequenceType.create(AnyItemType.INSTANCE, Quantifier.QUANT_STAR));
- VXQueryCollectionDataSource ds;
- if (vxqueryContext.getCollectionDataSourceMap(collectionName) != null) {
- ds = vxqueryContext.getCollectionDataSourceMap(collectionName);
- } else {
- int nextId = vxqueryContext.getCollectionDataSourceMapSize() + 1;
- ds = new VXQueryCollectionDataSource(nextId, collectionName, types.toArray());
- vxqueryContext.putCollectionDataSourceMap(collectionName, ds);
- }
- DataSourceScanOperator opNew = new DataSourceScanOperator(assign.getVariables(), ds);
- opNew.getInputs().addAll(assign.getInputs());
- opRef.setValue(opNew);
- return true;
- }
-
- @Override
- public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) {
return false;
}
-}
+
+}
\ No newline at end of file
Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/SetCollectionDataSourceRule.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/SetCollectionDataSourceRule.java?rev=1483074&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/SetCollectionDataSourceRule.java (added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/SetCollectionDataSourceRule.java Wed May 15 20:45:45 2013
@@ -0,0 +1,55 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang3.mutable.Mutable;
+import org.apache.vxquery.compiler.rewriter.VXQueryOptimizationContext;
+import org.apache.vxquery.metadata.VXQueryCollectionDataSource;
+import org.apache.vxquery.types.AnyItemType;
+import org.apache.vxquery.types.Quantifier;
+import org.apache.vxquery.types.SequenceType;
+
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalOperator;
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.IOptimizationContext;
+
+public class SetCollectionDataSourceRule extends AbstractCollectionRule {
+ /**
+ * Find the collection functions and generate the data source objects.
+ * Search pattern: unnest <- assign [function-call: collection] <- assign [constant: string]
+ */
+ @Override
+ public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
+ VXQueryOptimizationContext vxqueryContext = (VXQueryOptimizationContext) context;
+ String collectionName = getCollectionName(opRef);
+
+ // Build the new collection.
+ if (collectionName != null && vxqueryContext.getCollectionDataSourceMap(collectionName) == null) {
+ int collectionId = vxqueryContext.getCollectionDataSourceMapSize() + 1;
+ List<Object> types = new ArrayList<Object>();
+ types.add(SequenceType.create(AnyItemType.INSTANCE, Quantifier.QUANT_STAR));
+
+ VXQueryCollectionDataSource ds = new VXQueryCollectionDataSource(collectionId, collectionName,
+ types.toArray());
+ vxqueryContext.putCollectionDataSourceMap(collectionName, ds);
+ }
+ return false;
+ }
+}
Propchange: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/SetCollectionDataSourceRule.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryCollectionDataSource.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryCollectionDataSource.java?rev=1483074&r1=1483073&r2=1483074&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryCollectionDataSource.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryCollectionDataSource.java Wed May 15 20:45:45 2013
@@ -33,6 +33,7 @@ import edu.uci.ics.hyracks.algebricks.co
public class VXQueryCollectionDataSource implements IDataSource<String> {
private final int dataSourceId;
private final String collectionName;
+ private int totalDataSources;
private final Object[] types;
@@ -52,6 +53,14 @@ public class VXQueryCollectionDataSource
};
}
+ public int getTotalDataSources() {
+ return totalDataSources;
+ }
+
+ public void setTotalDataSources(int totalDataSources) {
+ this.totalDataSources = totalDataSources;
+ }
+
public int getDataSourceId() {
return dataSourceId;
}
Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryCollectionOperatorDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryCollectionOperatorDescriptor.java?rev=1483074&r1=1483073&r2=1483074&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryCollectionOperatorDescriptor.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryCollectionOperatorDescriptor.java Wed May 15 20:45:45 2013
@@ -40,14 +40,16 @@ import edu.uci.ics.hyracks.dataflow.std.
public class VXQueryCollectionOperatorDescriptor extends AbstractSingleActivityOperatorDescriptor {
private static final long serialVersionUID = 1L;
- private int dataSourceId;
+ private short dataSourceId;
+ private short totalDataSources;
private String collectionName;
public VXQueryCollectionOperatorDescriptor(IOperatorDescriptorRegistry spec, String collectionName,
- int dataSourceId, RecordDescriptor rDesc) {
+ int dataSourceId, int totalDataSources, RecordDescriptor rDesc) {
super(spec, 1, 1);
- this.dataSourceId = dataSourceId;
this.collectionName = collectionName;
+ this.dataSourceId = (short) dataSourceId;
+ this.totalDataSources = (short) totalDataSources;
recordDescriptors[0] = rDesc;
}
@@ -62,8 +64,8 @@ public class VXQueryCollectionOperatorDe
final FrameTupleAppender appender = new FrameTupleAppender(ctx.getFrameSize());
final InputSource in = new InputSource();
final ArrayBackedValueStorage abvsFileNode = new ArrayBackedValueStorage();
- final int partitionId = ctx.getTaskAttemptId().getTaskId().getPartition();
- final ITreeNodeIdProvider nodeIdProvider = new TreeNodeIdProvider((short) partitionId, (short) dataSourceId);
+ final short partitionId = (short) ctx.getTaskAttemptId().getTaskId().getPartition();
+ final ITreeNodeIdProvider nodeIdProvider = new TreeNodeIdProvider(partitionId, dataSourceId, totalDataSources);
return new AbstractUnaryInputUnaryOutputOperatorNodePushable() {
@Override
Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryMetadataProvider.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryMetadataProvider.java?rev=1483074&r1=1483073&r2=1483074&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryMetadataProvider.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryMetadataProvider.java Wed May 15 20:45:45 2013
@@ -57,7 +57,7 @@ public class VXQueryMetadataProvider imp
VXQueryCollectionDataSource ds = (VXQueryCollectionDataSource) dataSource;
RecordDescriptor rDesc = new RecordDescriptor(new ISerializerDeserializer[opSchema.getSize()]);
IOperatorDescriptor scanner = new VXQueryCollectionOperatorDescriptor(jobSpec, ds.getId(),
- ds.getDataSourceId(), rDesc);
+ ds.getDataSourceId(), ds.getTotalDataSources(), rDesc);
// TODO review if locations needs to be updated for parallel processing.
String[] locations = new String[1];
Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/xmlparser/TreeNodeIdProvider.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/xmlparser/TreeNodeIdProvider.java?rev=1483074&r1=1483073&r2=1483074&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/xmlparser/TreeNodeIdProvider.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/xmlparser/TreeNodeIdProvider.java Wed May 15 20:45:45 2013
@@ -17,28 +17,38 @@
package org.apache.vxquery.xmlparser;
public class TreeNodeIdProvider implements ITreeNodeIdProvider {
-
+
private final short partitionDataSource;
private final short dataSouceScanId;
+ private final byte dataSourceBits;
private short currentId;
-
- public TreeNodeIdProvider(short partitionDataSource, short dataSouceScanId) {
+
+ public TreeNodeIdProvider(short partitionDataSource, short dataSouceScanId, short totalDataSources) {
this.partitionDataSource = partitionDataSource;
this.dataSouceScanId = dataSouceScanId;
+ this.dataSourceBits = getBitsNeeded(totalDataSources);
currentId = 0;
}
-
- // TODO Remove this operator once all calls have been migrated to dataSourceScanId.
+
public TreeNodeIdProvider(short partition) {
this.partitionDataSource = partition;
dataSouceScanId = 0;
+ dataSourceBits = 0;
currentId = 0;
}
-
+
public int getId() {
int p = partitionDataSource;
int dssi = dataSouceScanId;
- // TODO the first 2 bytes from a combination of data source scan id and currentId.
- return (p << 16) | currentId++;
+ return (p << 16) | (dssi << (16 - dataSourceBits)) | currentId++;
+ }
+
+ private byte getBitsNeeded(int number) {
+ byte count = 0;
+ while (number > 0) {
+ count++;
+ number = number >> 1;
+ }
+ return count;
}
}
\ No newline at end of file