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/03/07 20:39:47 UTC
svn commit: r1454043 -
/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/step/DescendantOrSelfPathStepScalarEvaluator.java
Author: prestonc
Date: Thu Mar 7 19:39:47 2013
New Revision: 1454043
URL: http://svn.apache.org/r1454043
Log:
Updated the Descendant Or Self Path Step to allow argument to be a node tree or a sequence of node trees.
Modified:
incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/step/DescendantOrSelfPathStepScalarEvaluator.java
Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/step/DescendantOrSelfPathStepScalarEvaluator.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/step/DescendantOrSelfPathStepScalarEvaluator.java?rev=1454043&r1=1454042&r2=1454043&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/step/DescendantOrSelfPathStepScalarEvaluator.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/step/DescendantOrSelfPathStepScalarEvaluator.java Thu Mar 7 19:39:47 2013
@@ -18,6 +18,7 @@ package org.apache.vxquery.runtime.funct
import java.io.IOException;
+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.exceptions.ErrorCode;
@@ -30,12 +31,15 @@ import org.apache.vxquery.types.Sequence
import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluator;
import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
import edu.uci.ics.hyracks.data.std.api.IPointable;
+import edu.uci.ics.hyracks.data.std.primitive.VoidPointable;
import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
public class DescendantOrSelfPathStepScalarEvaluator extends AbstractDescendantPathStepScalarEvaluator {
private final TaggedValuePointable rootTVP;
-
private final ArrayBackedValueStorage seqAbvs;
+ private final SequencePointable seqp = (SequencePointable) SequencePointable.FACTORY.createPointable();
+ private final VoidPointable p = (VoidPointable) VoidPointable.FACTORY.createPointable();
+ private final TaggedValuePointable tvp = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
public DescendantOrSelfPathStepScalarEvaluator(IScalarEvaluator[] args, IHyracksTaskContext ctx) {
super(args, ctx);
@@ -46,35 +50,34 @@ public class DescendantOrSelfPathStepSca
@Override
protected final void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
try {
- if (args[0].getTag() != ValueTag.NODE_TREE_TAG) {
- throw new SystemException(ErrorCode.SYSE0001);
- }
- args[0].getValue(ntp);
-
- // Set up the result sequence and get the root node.
+ // Set up the result sequence.
seqAbvs.reset();
seqb.reset(seqAbvs);
- ntp.getRootNode(rootTVP);
- // Solve for self.
- switch (rootTVP.getTag()) {
- case ValueTag.DOCUMENT_NODE_TAG:
- setNodeTest(SequenceType.create(DocumentType.ANYDOCUMENT, Quantifier.QUANT_ONE));
- break;
- case ValueTag.ELEMENT_NODE_TAG:
- setNodeTest(SequenceType.create(ElementType.ANYELEMENT, Quantifier.QUANT_ONE));
- break;
- default:
- throw new SystemException(ErrorCode.SYSE0001);
- }
- itemTvp.set(rootTVP);
- if (matches()) {
- appendNodeToResult();
- }
+ int tag = args[0].getTag();
+ System.err.println("tag = " + tag);
- // Solve for descendants.
- setNodeTest(SequenceType.create(ElementType.ANYELEMENT, Quantifier.QUANT_ONE));
- searchSubtree(rootTVP);
+ // Check the argument passed in as sequence or node tree.
+ if (args[0].getTag() == ValueTag.SEQUENCE_TAG) {
+ args[0].getValue(seqp);
+ for (int j = 0; j < seqp.getEntryCount(); ++j) {
+ seqp.getEntry(j, p);
+ tvp.set(p.getByteArray(), p.getStartOffset(), p.getLength());
+ if (tvp.getTag() != ValueTag.NODE_TREE_TAG) {
+ throw new SystemException(ErrorCode.SYSE0001);
+ }
+ tvp.getValue(ntp);
+ processNodeTree(rootTVP);
+
+ int tag2 = tvp.getTag();
+ System.err.println("tag2 = " + tag2);
+ }
+ } else if (args[0].getTag() == ValueTag.NODE_TREE_TAG) {
+ args[0].getValue(ntp);
+ processNodeTree(rootTVP);
+ } else {
+ throw new SystemException(ErrorCode.SYSE0001);
+ }
seqb.finish();
result.set(seqAbvs);
@@ -83,4 +86,32 @@ public class DescendantOrSelfPathStepSca
}
}
+ private void processNodeTree(TaggedValuePointable rootTVP) throws SystemException {
+ ntp.getRootNode(rootTVP);
+
+ // Solve for self.
+ switch (rootTVP.getTag()) {
+ case ValueTag.DOCUMENT_NODE_TAG:
+ setNodeTest(SequenceType.create(DocumentType.ANYDOCUMENT, Quantifier.QUANT_ONE));
+ break;
+ case ValueTag.ELEMENT_NODE_TAG:
+ setNodeTest(SequenceType.create(ElementType.ANYELEMENT, Quantifier.QUANT_ONE));
+ break;
+ default:
+ throw new SystemException(ErrorCode.SYSE0001);
+ }
+ itemTvp.set(rootTVP);
+ if (matches()) {
+ try {
+ appendNodeToResult();
+ } catch (IOException e) {
+ throw new SystemException(ErrorCode.SYSE0001, e);
+ }
+ }
+
+ // Solve for descendants.
+ setNodeTest(SequenceType.create(ElementType.ANYELEMENT, Quantifier.QUANT_ONE));
+ searchSubtree(rootTVP);
+ }
+
}
\ No newline at end of file