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/09/11 23:54:33 UTC

svn commit: r1522061 - in /incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions: comparison/general/ misc/ util/

Author: prestonc
Date: Wed Sep 11 21:54:33 2013
New Revision: 1522061

URL: http://svn.apache.org/r1522061
Log:
Updated the general comparison to make NodeTrees into atomic value for comparison. The atomize functions were taken from fn:data and updated to work in a shared utility class.

Modified:
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/comparison/general/AbstractGeneralComparisonScalarEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/misc/FnDataScalarEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/util/FunctionHelper.java

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/comparison/general/AbstractGeneralComparisonScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/comparison/general/AbstractGeneralComparisonScalarEvaluatorFactory.java?rev=1522061&r1=1522060&r2=1522061&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/comparison/general/AbstractGeneralComparisonScalarEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/comparison/general/AbstractGeneralComparisonScalarEvaluatorFactory.java Wed Sep 11 21:54:33 2013
@@ -184,49 +184,68 @@ public abstract class AbstractGeneralCom
                     TaggedValuePointable tvpArg1, TaggedValuePointable tvpArg2, DynamicContext dCtx)
                     throws SystemException {
                 boolean tagTransformed1 = false, tagTransformed2 = false;
-                int tid1 = FunctionHelper.getBaseTypeForGeneralComparisons(tvpArg1.getTag());
-                int tid2 = FunctionHelper.getBaseTypeForGeneralComparisons(tvpArg2.getTag());
                 abvsInner1.reset();
                 abvsInner2.reset();
+                TaggedValuePointable tvpTransform1 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
+                TaggedValuePointable tvpTransform2 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
+                tvpTransform1.set(tvpArg1);
+                tvpTransform2.set(tvpArg2);
+                int tid1 = FunctionHelper.getBaseTypeForGeneralComparisons(tvpTransform1.getTag());
+                int tid2 = FunctionHelper.getBaseTypeForGeneralComparisons(tvpTransform2.getTag());
+                
                 // Converted tags
-                TaggedValuePointable tvp1 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
-                TaggedValuePointable tvp2 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
+                TaggedValuePointable tvpCompare1 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
+                TaggedValuePointable tvpCompare2 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
                 try {
+                    // Converts node tree's into untyped atomic values that can then be compared as atomic items.
+                    if (tid1 == ValueTag.NODE_TREE_TAG && tid2 == ValueTag.NODE_TREE_TAG) {
+                        FunctionHelper.atomize(tvpArg1, tvpTransform1);
+                        FunctionHelper.atomize(tvpArg2, tvpTransform2);
+                        tid1 = FunctionHelper.getBaseTypeForGeneralComparisons(tvpTransform1.getTag());
+                        tid2 = FunctionHelper.getBaseTypeForGeneralComparisons(tvpTransform2.getTag());
+                    } else if (tid1 == ValueTag.NODE_TREE_TAG) {
+                        FunctionHelper.atomize(tvpArg1, tvpTransform1);
+                        tid1 = FunctionHelper.getBaseTypeForGeneralComparisons(tvpTransform1.getTag());
+                    } else if (tid2 == ValueTag.NODE_TREE_TAG) {
+                        FunctionHelper.atomize(tvpArg2, tvpTransform2);
+                        tid2 = FunctionHelper.getBaseTypeForGeneralComparisons(tvpTransform2.getTag());
+                    }
+
                     // Set up value comparison tagged value pointables.
                     if (tid1 == ValueTag.XS_UNTYPED_ATOMIC_TAG && tid2 == ValueTag.XS_UNTYPED_ATOMIC_TAG) {
                         // Only need to change tag since the storage is the same for untyped atomic and string.
-                        tvp1.getByteArray()[0] = ValueTag.XS_STRING_TAG;
-                        tvp2.getByteArray()[0] = ValueTag.XS_STRING_TAG;
+                        tvpCompare1.getByteArray()[0] = ValueTag.XS_STRING_TAG;
+                        tvpCompare2.getByteArray()[0] = ValueTag.XS_STRING_TAG;
                     } else if (tid1 == ValueTag.XS_UNTYPED_ATOMIC_TAG) {
                         tid1 = tid2;
                         getCastToOperator(tid2);
-                        tvpArg1.getValue(tp1.utf8sp);
+                        tvpTransform1.getValue(tp1.utf8sp);
                         aCastToOp.convertUntypedAtomic(tp1.utf8sp, dOutInner1);
-                        tvp1.set(abvsInner1.getByteArray(), abvsInner1.getStartOffset(), abvsInner1.getLength());
+                        tvpCompare1.set(abvsInner1.getByteArray(), abvsInner1.getStartOffset(), abvsInner1.getLength());
                         tagTransformed1 = true;
                     } else if (tid2 == ValueTag.XS_UNTYPED_ATOMIC_TAG) {
                         tid2 = tid1;
                         getCastToOperator(tid1);
-                        tvpArg2.getValue(tp2.utf8sp);
+                        tvpTransform2.getValue(tp2.utf8sp);
                         aCastToOp.convertUntypedAtomic(tp2.utf8sp, dOutInner2);
-                        tvp2.set(abvsInner2.getByteArray(), abvsInner2.getStartOffset(), abvsInner2.getLength());
+                        tvpCompare2.set(abvsInner2.getByteArray(), abvsInner2.getStartOffset(), abvsInner2.getLength());
                         tagTransformed2 = true;
                     }
                     // Copy over the values not changed and upgrade numeric values to double.
                     if (!tagTransformed1) {
-                        tvp1 = tvpArg1;
-                        if (FunctionHelper.isDerivedFromDouble(tvp1.getTag())) {
-                            FunctionHelper.getDoublePointable(tvpArg1, dOutInner1);
-                            tvp1.set(abvsInner1.getByteArray(), abvsInner1.getStartOffset(),
+                        tvpCompare1 = tvpTransform1;
+                        if (FunctionHelper.isDerivedFromDouble(tvpCompare1.getTag())) {
+                            FunctionHelper.getDoublePointable(tvpTransform1, dOutInner1);
+                            tvpCompare1.set(abvsInner1.getByteArray(), abvsInner1.getStartOffset(),
                                     DoublePointable.TYPE_TRAITS.getFixedLength() + 1);
                             tagTransformed1 = true;
                         }
                     }
                     if (!tagTransformed2) {
-                        tvp2 = tvpArg2;
-                        if (FunctionHelper.isDerivedFromDouble(tvp2.getTag())) {
-                            FunctionHelper.getDoublePointable(tvpArg2, dOutInner2);
-                            tvp2.set(abvsInner2.getByteArray(), abvsInner2.getStartOffset(),
+                        tvpCompare2 = tvpTransform2;
+                        if (FunctionHelper.isDerivedFromDouble(tvpCompare2.getTag())) {
+                            FunctionHelper.getDoublePointable(tvpTransform2, dOutInner2);
+                            tvpCompare2.set(abvsInner2.getByteArray(), abvsInner2.getStartOffset(),
                                     DoublePointable.TYPE_TRAITS.getFixedLength() + 1);
                             tagTransformed2 = true;
                         }
@@ -236,7 +255,7 @@ public abstract class AbstractGeneralCom
                 } catch (Exception e) {
                     throw new SystemException(ErrorCode.SYSE0001, e);
                 }
-                return FunctionHelper.compareTaggedValues(aOp, tvp1, tvp2, dCtx);
+                return FunctionHelper.compareTaggedValues(aOp, tvpCompare1, tvpCompare2, dCtx);
             }
 
             private void getCastToOperator(int tid) {

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/misc/FnDataScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/misc/FnDataScalarEvaluatorFactory.java?rev=1522061&r1=1522060&r2=1522061&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/misc/FnDataScalarEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/misc/FnDataScalarEvaluatorFactory.java Wed Sep 11 21:54:33 2013
@@ -16,32 +16,23 @@
  */
 package org.apache.vxquery.runtime.functions.misc;
 
-import java.io.DataOutput;
 import java.io.IOException;
 
-import org.apache.vxquery.datamodel.accessors.PointablePool;
-import org.apache.vxquery.datamodel.accessors.PointablePoolFactory;
 import org.apache.vxquery.datamodel.accessors.SequencePointable;
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
-import org.apache.vxquery.datamodel.accessors.nodes.AttributeNodePointable;
-import org.apache.vxquery.datamodel.accessors.nodes.DocumentNodePointable;
-import org.apache.vxquery.datamodel.accessors.nodes.ElementNodePointable;
-import org.apache.vxquery.datamodel.accessors.nodes.NodeTreePointable;
-import org.apache.vxquery.datamodel.accessors.nodes.PINodePointable;
-import org.apache.vxquery.datamodel.accessors.nodes.TextOrCommentNodePointable;
 import org.apache.vxquery.datamodel.builders.sequence.SequenceBuilder;
 import org.apache.vxquery.datamodel.values.ValueTag;
 import org.apache.vxquery.exceptions.ErrorCode;
 import org.apache.vxquery.exceptions.SystemException;
 import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
 import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
+import org.apache.vxquery.runtime.functions.util.FunctionHelper;
 
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
 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 FnDataScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
@@ -55,15 +46,10 @@ public class FnDataScalarEvaluatorFactor
     protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
             throws AlgebricksException {
         final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
-        final ArrayBackedValueStorage tempABVS = new ArrayBackedValueStorage();
         final SequenceBuilder sb = new SequenceBuilder();
         final SequencePointable seq = new SequencePointable();
         final TaggedValuePointable p = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
         final TaggedValuePointable tempTVP = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
-        final TaggedValuePointable tempTVP2 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
-        final NodeTreePointable ntp = (NodeTreePointable) NodeTreePointable.FACTORY.createPointable();
-        final VoidPointable vp = (VoidPointable) VoidPointable.FACTORY.createPointable();
-        final PointablePool pp = PointablePoolFactory.INSTANCE.createPointablePool();
         return new AbstractTaggedValueArgumentScalarEvaluator(args) {
             @Override
             protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
@@ -76,10 +62,12 @@ public class FnDataScalarEvaluatorFactor
                         int seqLen = seq.getEntryCount();
                         for (int j = 0; j < seqLen; ++j) {
                             seq.getEntry(j, p);
-                            atomize(p, sb);
+                            FunctionHelper.atomize(p, tempTVP);
+                            sb.addItem(tempTVP);
                         }
                     } else {
-                        atomize(tvp, sb);
+                        FunctionHelper.atomize(tvp, tempTVP);
+                        sb.addItem(tempTVP);
                     }
                     sb.finish();
                     result.set(abvs);
@@ -88,149 +76,7 @@ public class FnDataScalarEvaluatorFactor
                 }
             }
 
-            private void atomize(TaggedValuePointable tvp, SequenceBuilder sb) throws IOException {
-                switch (tvp.getTag()) {
-                    case ValueTag.NODE_TREE_TAG:
-                        tvp.getValue(ntp);
-                        atomizeNode(ntp, sb);
-                        break;
-
-                    default:
-                        sb.addItem(tvp);
-                }
-            }
-
-            private void atomizeNode(NodeTreePointable ntp, SequenceBuilder sb) throws IOException {
-                ntp.getRootNode(tempTVP);
-                switch (tempTVP.getTag()) {
-                    case ValueTag.ATTRIBUTE_NODE_TAG: {
-                        AttributeNodePointable anp = pp.takeOne(AttributeNodePointable.class);
-                        try {
-                            tempTVP.getValue(anp);
-                            anp.getValue(ntp, vp);
-                            sb.addItem(vp);
-                        } finally {
-                            pp.giveBack(anp);
-                        }
-                        break;
-                    }
-
-                    case ValueTag.TEXT_NODE_TAG:
-                    case ValueTag.COMMENT_NODE_TAG: {
-                        TextOrCommentNodePointable tcnp = pp.takeOne(TextOrCommentNodePointable.class);
-                        try {
-                            tempTVP.getValue(tcnp);
-                            tcnp.getValue(ntp, vp);
-                            tempABVS.reset();
-                            tempABVS.getDataOutput().write(ValueTag.XS_UNTYPED_ATOMIC_TAG);
-                            tempABVS.append(vp);
-                            sb.addItem(tempABVS);
-                        } finally {
-                            pp.giveBack(tcnp);
-                        }
-                        break;
-                    }
-
-                    case ValueTag.DOCUMENT_NODE_TAG: {
-                        DocumentNodePointable dnp = pp.takeOne(DocumentNodePointable.class);
-                        SequencePointable sp = pp.takeOne(SequencePointable.class);
-                        try {
-                            tempTVP.getValue(dnp);
-                            dnp.getContent(ntp, sp);
-                            buildStringConcatenation(sp, tempABVS, ntp);
-                            sb.addItem(tempABVS);
-                        } finally {
-                            pp.giveBack(sp);
-                            pp.giveBack(dnp);
-                        }
-                        break;
-                    }
-
-                    case ValueTag.ELEMENT_NODE_TAG: {
-                        ElementNodePointable enp = pp.takeOne(ElementNodePointable.class);
-                        SequencePointable sp = pp.takeOne(SequencePointable.class);
-                        try {
-                            tempTVP.getValue(enp);
-                            if (enp.childrenChunkExists()) {
-                                enp.getChildrenSequence(ntp, sp);
-                                buildStringConcatenation(sp, tempABVS, ntp);
-                                sb.addItem(tempABVS);
-                            }
-                        } finally {
-                            pp.giveBack(sp);
-                            pp.giveBack(enp);
-                        }
-                        break;
-                    }
-
-                    case ValueTag.PI_NODE_TAG: {
-                        PINodePointable pnp = pp.takeOne(PINodePointable.class);
-                        try {
-                            tempTVP.getValue(pnp);
-                            pnp.getContent(ntp, vp);
-                            tempABVS.reset();
-                            tempABVS.getDataOutput().write(ValueTag.XS_UNTYPED_ATOMIC_TAG);
-                            tempABVS.append(vp);
-                            sb.addItem(tempABVS);
-                        } finally {
-                            pp.giveBack(pnp);
-                        }
-                        break;
-                    }
-
-                }
-            }
-
-            private void buildStringConcatenation(SequencePointable sp, ArrayBackedValueStorage tempABVS,
-                    NodeTreePointable ntp) throws IOException {
-                tempABVS.reset();
-                DataOutput out = tempABVS.getDataOutput();
-                out.write(ValueTag.XS_UNTYPED_ATOMIC_TAG);
-                // Leave room for the utf-8 length
-                out.write(0);
-                out.write(0);
-                buildConcatenationRec(sp, out, ntp);
-                int utflen = tempABVS.getLength() - 3;
-                byte[] bytes = tempABVS.getByteArray();
-                // Patch utf-8 length at bytes 1 and 2
-                bytes[1] = (byte) ((utflen >>> 8) & 0xFF);
-                bytes[2] = (byte) ((utflen >>> 0) & 0xFF);
-            }
-
-            private void buildConcatenationRec(SequencePointable sp, DataOutput out, NodeTreePointable ntp)
-                    throws IOException {
-                int nItems = sp.getEntryCount();
-                for (int i = 0; i < nItems; ++i) {
-                    sp.getEntry(i, tempTVP2);
-                    switch (tempTVP2.getTag()) {
-                        case ValueTag.TEXT_NODE_TAG: {
-                            TextOrCommentNodePointable tcnp = pp.takeOne(TextOrCommentNodePointable.class);
-                            try {
-                                tempTVP2.getValue(tcnp);
-                                tcnp.getValue(ntp, vp);
-                                out.write(vp.getByteArray(), vp.getStartOffset() + 2, vp.getLength() - 2);
-                            } finally {
-                                pp.giveBack(tcnp);
-                            }
-                            break;
-                        }
-                        case ValueTag.ELEMENT_NODE_TAG: {
-                            ElementNodePointable enp = pp.takeOne(ElementNodePointable.class);
-                            SequencePointable sp2 = pp.takeOne(SequencePointable.class);
-                            try {
-                                tempTVP2.getValue(enp);
-                                if (enp.childrenChunkExists()) {
-                                    enp.getChildrenSequence(ntp, sp2);
-                                    buildConcatenationRec(sp2, out, ntp);
-                                }
-                            } finally {
-                                pp.giveBack(sp2);
-                                pp.giveBack(enp);
-                            }
-                        }
-                    }
-                }
-            }
-        };
+       };
     }
+
 }
\ No newline at end of file

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/util/FunctionHelper.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/util/FunctionHelper.java?rev=1522061&r1=1522060&r2=1522061&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/util/FunctionHelper.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/util/FunctionHelper.java Wed Sep 11 21:54:33 2013
@@ -27,6 +27,8 @@ import java.util.Arrays;
 import java.util.zip.GZIPInputStream;
 
 import org.apache.vxquery.context.DynamicContext;
+import org.apache.vxquery.datamodel.accessors.PointablePool;
+import org.apache.vxquery.datamodel.accessors.PointablePoolFactory;
 import org.apache.vxquery.datamodel.accessors.SequencePointable;
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
 import org.apache.vxquery.datamodel.accessors.atomic.XSBinaryPointable;
@@ -69,6 +71,7 @@ import edu.uci.ics.hyracks.data.std.prim
 import edu.uci.ics.hyracks.data.std.primitive.LongPointable;
 import edu.uci.ics.hyracks.data.std.primitive.ShortPointable;
 import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+import edu.uci.ics.hyracks.data.std.primitive.VoidPointable;
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 import edu.uci.ics.hyracks.dataflow.common.comm.util.ByteBufferInputStream;
 
@@ -510,6 +513,157 @@ public class FunctionHelper {
         throw new SystemException(ErrorCode.XPTY0004);
     }
 
+    public static void atomize(TaggedValuePointable tvp, IPointable result) throws IOException {
+        NodeTreePointable ntp = (NodeTreePointable) NodeTreePointable.FACTORY.createPointable();
+        switch (tvp.getTag()) {
+            case ValueTag.NODE_TREE_TAG:
+                tvp.getValue(ntp);
+                atomizeNode(ntp, result);
+                break;
+
+            default:
+                result.set(tvp);
+        }
+    }
+
+    public static void atomizeNode(NodeTreePointable ntp, IPointable result) throws IOException {
+        ArrayBackedValueStorage tempABVS = new ArrayBackedValueStorage();
+        TaggedValuePointable tempTVP = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
+        VoidPointable vp = (VoidPointable) VoidPointable.FACTORY.createPointable();
+        PointablePool pp = PointablePoolFactory.INSTANCE.createPointablePool();
+        ntp.getRootNode(tempTVP);
+        switch (tempTVP.getTag()) {
+            case ValueTag.ATTRIBUTE_NODE_TAG: {
+                AttributeNodePointable anp = pp.takeOne(AttributeNodePointable.class);
+                try {
+                    tempTVP.getValue(anp);
+                    anp.getValue(ntp, result);
+                } finally {
+                    pp.giveBack(anp);
+                }
+                break;
+            }
+
+            case ValueTag.TEXT_NODE_TAG:
+            case ValueTag.COMMENT_NODE_TAG: {
+                TextOrCommentNodePointable tcnp = pp.takeOne(TextOrCommentNodePointable.class);
+                try {
+                    tempTVP.getValue(tcnp);
+                    tcnp.getValue(ntp, vp);
+                    tempABVS.reset();
+                    tempABVS.getDataOutput().write(ValueTag.XS_UNTYPED_ATOMIC_TAG);
+                    tempABVS.append(vp);
+                    result.set(tempABVS.getByteArray(), tempABVS.getStartOffset(), tempABVS.getLength());
+                } finally {
+                    pp.giveBack(tcnp);
+                }
+                break;
+            }
+
+            case ValueTag.DOCUMENT_NODE_TAG: {
+                DocumentNodePointable dnp = pp.takeOne(DocumentNodePointable.class);
+                SequencePointable sp = pp.takeOne(SequencePointable.class);
+                try {
+                    tempTVP.getValue(dnp);
+                    dnp.getContent(ntp, sp);
+                    buildStringConcatenation(sp, tempABVS, ntp);
+                    result.set(tempABVS.getByteArray(), tempABVS.getStartOffset(), tempABVS.getLength());
+                } finally {
+                    pp.giveBack(sp);
+                    pp.giveBack(dnp);
+                }
+                break;
+            }
+
+            case ValueTag.ELEMENT_NODE_TAG: {
+                ElementNodePointable enp = pp.takeOne(ElementNodePointable.class);
+                SequencePointable sp = pp.takeOne(SequencePointable.class);
+                try {
+                    tempTVP.getValue(enp);
+                    if (enp.childrenChunkExists()) {
+                        enp.getChildrenSequence(ntp, sp);
+                        buildStringConcatenation(sp, tempABVS, ntp);
+                        result.set(tempABVS.getByteArray(), tempABVS.getStartOffset(), tempABVS.getLength());
+                    }
+                } finally {
+                    pp.giveBack(sp);
+                    pp.giveBack(enp);
+                }
+                break;
+            }
+
+            case ValueTag.PI_NODE_TAG: {
+                PINodePointable pnp = pp.takeOne(PINodePointable.class);
+                try {
+                    tempTVP.getValue(pnp);
+                    pnp.getContent(ntp, vp);
+                    tempABVS.reset();
+                    tempABVS.getDataOutput().write(ValueTag.XS_UNTYPED_ATOMIC_TAG);
+                    tempABVS.append(vp);
+                    result.set(tempABVS.getByteArray(), tempABVS.getStartOffset(), tempABVS.getLength());
+                } finally {
+                    pp.giveBack(pnp);
+                }
+                break;
+            }
+
+        }
+    }
+
+    public static void buildStringConcatenation(SequencePointable sp, ArrayBackedValueStorage tempABVS,
+            NodeTreePointable ntp) throws IOException {
+        tempABVS.reset();
+        DataOutput out = tempABVS.getDataOutput();
+        out.write(ValueTag.XS_UNTYPED_ATOMIC_TAG);
+        // Leave room for the utf-8 length
+        out.write(0);
+        out.write(0);
+        buildConcatenationRec(sp, out, ntp);
+        int utflen = tempABVS.getLength() - 3;
+        byte[] bytes = tempABVS.getByteArray();
+        // Patch utf-8 length at bytes 1 and 2
+        bytes[1] = (byte) ((utflen >>> 8) & 0xFF);
+        bytes[2] = (byte) ((utflen >>> 0) & 0xFF);
+    }
+
+    public static void buildConcatenationRec(SequencePointable sp, DataOutput out, NodeTreePointable ntp)
+            throws IOException {
+        TaggedValuePointable tempTVP2 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
+        VoidPointable vp = (VoidPointable) VoidPointable.FACTORY.createPointable();
+        PointablePool pp = PointablePoolFactory.INSTANCE.createPointablePool();
+        int nItems = sp.getEntryCount();
+        for (int i = 0; i < nItems; ++i) {
+            sp.getEntry(i, tempTVP2);
+            switch (tempTVP2.getTag()) {
+                case ValueTag.TEXT_NODE_TAG: {
+                    TextOrCommentNodePointable tcnp = pp.takeOne(TextOrCommentNodePointable.class);
+                    try {
+                        tempTVP2.getValue(tcnp);
+                        tcnp.getValue(ntp, vp);
+                        out.write(vp.getByteArray(), vp.getStartOffset() + 2, vp.getLength() - 2);
+                    } finally {
+                        pp.giveBack(tcnp);
+                    }
+                    break;
+                }
+                case ValueTag.ELEMENT_NODE_TAG: {
+                    ElementNodePointable enp = pp.takeOne(ElementNodePointable.class);
+                    SequencePointable sp2 = pp.takeOne(SequencePointable.class);
+                    try {
+                        tempTVP2.getValue(enp);
+                        if (enp.childrenChunkExists()) {
+                            enp.getChildrenSequence(ntp, sp2);
+                            buildConcatenationRec(sp2, out, ntp);
+                        }
+                    } finally {
+                        pp.giveBack(sp2);
+                        pp.giveBack(enp);
+                    }
+                }
+            }
+        }
+    }
+
     public static boolean compareTaggedValues(AbstractValueComparisonOperation aOp, TaggedValuePointable tvp1,
             TaggedValuePointable tvp2, DynamicContext dCtx) throws SystemException {
         final TypedPointables tp1 = new TypedPointables();
@@ -940,6 +1094,7 @@ public class FunctionHelper {
     public static int getBaseTypeForGeneralComparisons(int tid) throws SystemException {
         while (true) {
             switch (tid) {
+                case ValueTag.NODE_TREE_TAG:
                 case ValueTag.XS_ANY_URI_TAG:
                 case ValueTag.XS_BASE64_BINARY_TAG:
                 case ValueTag.XS_BOOLEAN_TAG:
@@ -1236,6 +1391,7 @@ public class FunctionHelper {
 
     /**
      * Checks the path has an acceptable file name extension to read in.
+     * 
      * @param path
      * @return
      */