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/29 19:49:13 UTC

svn commit: r1518726 - in /incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery: datamodel/builders/nodes/ runtime/functions/step/

Author: prestonc
Date: Thu Aug 29 17:49:13 2013
New Revision: 1518726

URL: http://svn.apache.org/r1518726
Log:
Created two new classes to share the code between scalar and unnesting evaluators.

Added:
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/nodes/NodeSubTreeBuilder.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/step/NodeTestFilter.java   (with props)
Modified:
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/step/AbstractPathStepScalarEvaluator.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/step/ChildPathStepUnnestingEvaluatorFactory.java

Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/nodes/NodeSubTreeBuilder.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/nodes/NodeSubTreeBuilder.java?rev=1518726&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/nodes/NodeSubTreeBuilder.java (added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/nodes/NodeSubTreeBuilder.java Thu Aug 29 17:49:13 2013
@@ -0,0 +1,70 @@
+/*
+ * 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.datamodel.builders.nodes;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
+import org.apache.vxquery.datamodel.accessors.nodes.NodeTreePointable;
+import org.apache.vxquery.datamodel.values.ValueTag;
+
+import edu.uci.ics.hyracks.data.std.api.IMutableValueStorage;
+
+public class NodeSubTreeBuilder extends AbstractNodeBuilder {
+    private DataOutput mainOut;
+
+    @Override
+    public void reset(IMutableValueStorage mvs) throws IOException {
+        mainOut = mvs.getDataOutput();
+        mainOut.write(ValueTag.NODE_TREE_TAG);
+    }
+
+    @Override
+    public void finish() throws IOException {
+    }
+
+    public void setChildNode(NodeTreePointable ntp, TaggedValuePointable itemTvp) throws IOException {
+        boolean hasDictionary = ntp.dictionaryExists() && hasDictionary(itemTvp.getTag());
+        byte header = (byte) (hasDictionary ? NodeTreePointable.HEADER_DICTIONARY_EXISTS_MASK : 0);
+        // TODO add all header flags to this setting.
+        boolean hasNodeIds = ntp.nodeIdExists();
+        if (hasNodeIds) {
+            header |= NodeTreePointable.HEADER_NODEID_EXISTS_MASK;
+        }
+        mainOut.write(header);
+        if (hasNodeIds) {
+            mainOut.writeInt(ntp.getRootNodeId());
+        }
+        if (hasDictionary) {
+            mainOut.write(ntp.getByteArray(), ntp.getDictionaryOffset(), ntp.getDictionarySize());
+        }
+        mainOut.write(itemTvp.getByteArray(), itemTvp.getStartOffset(), itemTvp.getLength());
+    }
+
+    private boolean hasDictionary(byte tag) {
+        switch (tag) {
+            case ValueTag.ATTRIBUTE_NODE_TAG:
+            case ValueTag.DOCUMENT_NODE_TAG:
+            case ValueTag.ELEMENT_NODE_TAG:
+                return true;
+        }
+        return false;
+    }
+
+
+}
\ No newline at end of file

Propchange: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/nodes/NodeSubTreeBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/step/AbstractPathStepScalarEvaluator.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/step/AbstractPathStepScalarEvaluator.java?rev=1518726&r1=1518725&r2=1518726&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/step/AbstractPathStepScalarEvaluator.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/step/AbstractPathStepScalarEvaluator.java Thu Aug 29 17:49:13 2013
@@ -20,25 +20,18 @@ import java.io.DataOutput;
 import java.io.IOException;
 
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
-import org.apache.vxquery.datamodel.accessors.atomic.CodedQNamePointable;
-import org.apache.vxquery.datamodel.accessors.nodes.AttributeNodePointable;
-import org.apache.vxquery.datamodel.accessors.nodes.ElementNodePointable;
 import org.apache.vxquery.datamodel.accessors.nodes.NodeTreePointable;
+import org.apache.vxquery.datamodel.builders.nodes.NodeSubTreeBuilder;
 import org.apache.vxquery.datamodel.builders.sequence.SequenceBuilder;
 import org.apache.vxquery.datamodel.values.ValueTag;
 import org.apache.vxquery.exceptions.SystemException;
 import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
-import org.apache.vxquery.types.AttributeType;
-import org.apache.vxquery.types.ElementType;
-import org.apache.vxquery.types.NameTest;
-import org.apache.vxquery.types.NodeType;
+import org.apache.vxquery.runtime.functions.step.NodeTestFilter.INodeFilter;
 import org.apache.vxquery.types.SequenceType;
 
 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.UTF8StringPointable;
-import edu.uci.ics.hyracks.data.std.primitive.VoidPointable;
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 
 public abstract class AbstractPathStepScalarEvaluator extends AbstractTaggedValueArgumentScalarEvaluator {
@@ -61,142 +54,7 @@ public abstract class AbstractPathStepSc
     }
 
     protected void setNodeTest(SequenceType sType) {
-        final NodeType nodeType = (NodeType) sType.getItemType();
-        switch (nodeType.getNodeKind()) {
-            case ANY:
-                filter = new INodeFilter() {
-                    @Override
-                    public boolean accept(NodeTreePointable ntp, TaggedValuePointable tvp) {
-                        return true;
-                    }
-                };
-                break;
-
-            case ATTRIBUTE: {
-                AttributeType aType = (AttributeType) nodeType;
-                NameTest nameTest = aType.getNameTest();
-                byte[] uri = nameTest.getUri();
-                byte[] localName = nameTest.getLocalName();
-                final UTF8StringPointable urip = (UTF8StringPointable) (uri == null ? null
-                        : UTF8StringPointable.FACTORY.createPointable());
-                final UTF8StringPointable localp = (UTF8StringPointable) (localName == null ? null
-                        : UTF8StringPointable.FACTORY.createPointable());
-                if (uri != null) {
-                    urip.set(uri, 0, uri.length);
-                }
-                if (localName != null) {
-                    localp.set(localName, 0, localName.length);
-                }
-                final IPointable temp = VoidPointable.FACTORY.createPointable();
-                final AttributeNodePointable anp = (AttributeNodePointable) AttributeNodePointable.FACTORY
-                        .createPointable();
-                final CodedQNamePointable cqp = (CodedQNamePointable) CodedQNamePointable.FACTORY.createPointable();
-                filter = new INodeFilter() {
-                    @Override
-                    public boolean accept(NodeTreePointable ntp, TaggedValuePointable tvp) {
-                        if (tvp.getTag() != ValueTag.ATTRIBUTE_NODE_TAG) {
-                            return false;
-                        }
-                        tvp.getValue(anp);
-                        anp.getName(cqp);
-                        if (urip != null) {
-                            ntp.getString(cqp.getNamespaceCode(), temp);
-                            if (urip.compareTo(temp) != 0) {
-                                return false;
-                            }
-                        }
-                        if (localp != null) {
-                            ntp.getString(cqp.getLocalCode(), temp);
-                            if (localp.compareTo(temp) != 0) {
-                                return false;
-                            }
-                        }
-                        return true;
-                    }
-                };
-                break;
-            }
-
-            case COMMENT:
-                filter = new INodeFilter() {
-                    @Override
-                    public boolean accept(NodeTreePointable ntp, TaggedValuePointable tvp) {
-                        return tvp.getTag() == ValueTag.COMMENT_NODE_TAG;
-                    }
-                };
-                break;
-
-            case DOCUMENT:
-                filter = new INodeFilter() {
-                    @Override
-                    public boolean accept(NodeTreePointable ntp, TaggedValuePointable tvp) {
-                        return tvp.getTag() == ValueTag.DOCUMENT_NODE_TAG;
-                    }
-                };
-                break;
-
-            case ELEMENT: {
-                ElementType eType = (ElementType) nodeType;
-                NameTest nameTest = eType.getNameTest();
-                byte[] uri = nameTest.getUri();
-                byte[] localName = nameTest.getLocalName();
-                final UTF8StringPointable urip = (UTF8StringPointable) (uri == null ? null
-                        : UTF8StringPointable.FACTORY.createPointable());
-                final UTF8StringPointable localp = (UTF8StringPointable) (localName == null ? null
-                        : UTF8StringPointable.FACTORY.createPointable());
-                if (uri != null) {
-                    urip.set(uri, 0, uri.length);
-                }
-                if (localName != null) {
-                    localp.set(localName, 0, localName.length);
-                }
-                final IPointable temp = VoidPointable.FACTORY.createPointable();
-                final ElementNodePointable enp = (ElementNodePointable) ElementNodePointable.FACTORY.createPointable();
-                final CodedQNamePointable cqp = (CodedQNamePointable) CodedQNamePointable.FACTORY.createPointable();
-                filter = new INodeFilter() {
-                    @Override
-                    public boolean accept(NodeTreePointable ntp, TaggedValuePointable tvp) {
-                        if (tvp.getTag() != ValueTag.ELEMENT_NODE_TAG) {
-                            return false;
-                        }
-                        tvp.getValue(enp);
-                        enp.getName(cqp);
-                        if (urip != null) {
-                            ntp.getString(cqp.getNamespaceCode(), temp);
-                            if (urip.compareTo(temp) != 0) {
-                                return false;
-                            }
-                        }
-                        if (localp != null) {
-                            ntp.getString(cqp.getLocalCode(), temp);
-                            if (localp.compareTo(temp) != 0) {
-                                return false;
-                            }
-                        }
-                        return true;
-                    }
-                };
-                break;
-            }
-
-            case PI:
-                filter = new INodeFilter() {
-                    @Override
-                    public boolean accept(NodeTreePointable ntp, TaggedValuePointable tvp) {
-                        return tvp.getTag() == ValueTag.PI_NODE_TAG;
-                    }
-                };
-                break;
-
-            case TEXT:
-                filter = new INodeFilter() {
-                    @Override
-                    public boolean accept(NodeTreePointable ntp, TaggedValuePointable tvp) {
-                        return tvp.getTag() == ValueTag.TEXT_NODE_TAG;
-                    }
-                };
-                break;
-        }
+        filter = NodeTestFilter.getNodeTestFilter(sType);
     }
 
     @Override
@@ -206,39 +64,18 @@ public abstract class AbstractPathStepSc
         return filter.accept(ntp, itemTvp);
     }
 
-    protected void appendNodeToResult() throws IOException {
+    protected void setNodeToResult(IPointable result) throws IOException {
         nodeAbvs.reset();
-        DataOutput mainOut = nodeAbvs.getDataOutput();
-        mainOut.write(ValueTag.NODE_TREE_TAG);
-        boolean hasDictionary = ntp.dictionaryExists() && hasDictionary(itemTvp.getTag());
-        byte header = (byte) (hasDictionary ? NodeTreePointable.HEADER_DICTIONARY_EXISTS_MASK : 0);
-		// TODO add all header flags to this setting.
-        boolean hasNodeIds = ntp.nodeIdExists();
-        if (hasNodeIds) {
-            header |= NodeTreePointable.HEADER_NODEID_EXISTS_MASK;
-        }
-        mainOut.write(header);
-        if (hasNodeIds) {
-            mainOut.writeInt(ntp.getRootNodeId());
-        }
-        if (hasDictionary) {
-            mainOut.write(ntp.getByteArray(), ntp.getDictionaryOffset(), ntp.getDictionarySize());
-        }
-        mainOut.write(itemTvp.getByteArray(), itemTvp.getStartOffset(), itemTvp.getLength());
-        seqb.addItem(nodeAbvs);
-    }
-
-    private boolean hasDictionary(byte tag) {
-        switch (tag) {
-            case ValueTag.ATTRIBUTE_NODE_TAG:
-            case ValueTag.DOCUMENT_NODE_TAG:
-            case ValueTag.ELEMENT_NODE_TAG:
-                return true;
-        }
-        return false;
+        NodeSubTreeBuilder nstb = new NodeSubTreeBuilder();
+        nstb.reset(nodeAbvs);
+        nstb.setChildNode(ntp, itemTvp);
+        nstb.finish();
+        result.set(nodeAbvs.getByteArray(), nodeAbvs.getStartOffset(), nodeAbvs.getLength());
     }
 
-    private interface INodeFilter {
-        public boolean accept(NodeTreePointable ntp, TaggedValuePointable tvp);
+    protected void appendNodeToResult() throws IOException {
+        TaggedValuePointable node = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
+        setNodeToResult(node);
+        seqb.addItem(node);
     }
 }
\ No newline at end of file

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/step/ChildPathStepUnnestingEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/step/ChildPathStepUnnestingEvaluatorFactory.java?rev=1518726&r1=1518725&r2=1518726&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/step/ChildPathStepUnnestingEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/step/ChildPathStepUnnestingEvaluatorFactory.java Thu Aug 29 17:49:13 2013
@@ -16,26 +16,21 @@
  */
 package org.apache.vxquery.runtime.functions.step;
 
-import java.io.DataOutput;
 import java.io.IOException;
 
 import org.apache.vxquery.datamodel.accessors.SequencePointable;
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
-import org.apache.vxquery.datamodel.accessors.atomic.CodedQNamePointable;
-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.builders.nodes.NodeSubTreeBuilder;
 import org.apache.vxquery.datamodel.values.ValueTag;
 import org.apache.vxquery.datamodel.values.XDMConstants;
 import org.apache.vxquery.exceptions.ErrorCode;
 import org.apache.vxquery.exceptions.SystemException;
 import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentUnnestingEvaluator;
 import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentUnnestingEvaluatorFactory;
-import org.apache.vxquery.types.AttributeType;
-import org.apache.vxquery.types.ElementType;
-import org.apache.vxquery.types.NameTest;
-import org.apache.vxquery.types.NodeType;
+import org.apache.vxquery.runtime.functions.step.NodeTestFilter.INodeFilter;
 import org.apache.vxquery.types.SequenceType;
 
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
@@ -44,8 +39,6 @@ import edu.uci.ics.hyracks.algebricks.ru
 import edu.uci.ics.hyracks.algebricks.runtime.base.IUnnestingEvaluator;
 import edu.uci.ics.hyracks.data.std.api.IPointable;
 import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
-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;
 
 public class ChildPathStepUnnestingEvaluatorFactory extends AbstractTaggedValueArgumentUnnestingEvaluatorFactory {
@@ -108,7 +101,7 @@ public class ChildPathStepUnnestingEvalu
                     args[1].getValue(ip);
                     int typeCode = ip.getInteger();
                     SequenceType sType = dCtx.getStaticContext().lookupSequenceType(typeCode);
-                    setNodeTest(sType);
+                    filter = NodeTestFilter.getNodeTestFilter(sType);
                     first = false;
                 }
                 if (args[0].getTag() != ValueTag.NODE_TREE_TAG) {
@@ -119,184 +112,19 @@ public class ChildPathStepUnnestingEvalu
                 seqLength = seqp.getEntryCount();
             }
 
-            protected void setNodeTest(SequenceType sType) {
-                final NodeType nodeType = (NodeType) sType.getItemType();
-                switch (nodeType.getNodeKind()) {
-                    case ANY:
-                        filter = new INodeFilter() {
-                            @Override
-                            public boolean accept(NodeTreePointable ntp, TaggedValuePointable tvp) {
-                                return true;
-                            }
-                        };
-                        break;
-
-                    case ATTRIBUTE: {
-                        AttributeType aType = (AttributeType) nodeType;
-                        NameTest nameTest = aType.getNameTest();
-                        byte[] uri = nameTest.getUri();
-                        byte[] localName = nameTest.getLocalName();
-                        final UTF8StringPointable urip = (UTF8StringPointable) (uri == null ? null
-                                : UTF8StringPointable.FACTORY.createPointable());
-                        final UTF8StringPointable localp = (UTF8StringPointable) (localName == null ? null
-                                : UTF8StringPointable.FACTORY.createPointable());
-                        if (uri != null) {
-                            urip.set(uri, 0, uri.length);
-                        }
-                        if (localName != null) {
-                            localp.set(localName, 0, localName.length);
-                        }
-                        final IPointable temp = VoidPointable.FACTORY.createPointable();
-                        final AttributeNodePointable anp = (AttributeNodePointable) AttributeNodePointable.FACTORY
-                                .createPointable();
-                        final CodedQNamePointable cqp = (CodedQNamePointable) CodedQNamePointable.FACTORY
-                                .createPointable();
-                        filter = new INodeFilter() {
-                            @Override
-                            public boolean accept(NodeTreePointable ntp, TaggedValuePointable tvp) {
-                                if (tvp.getTag() != ValueTag.ATTRIBUTE_NODE_TAG) {
-                                    return false;
-                                }
-                                tvp.getValue(anp);
-                                anp.getName(cqp);
-                                if (urip != null) {
-                                    ntp.getString(cqp.getNamespaceCode(), temp);
-                                    if (urip.compareTo(temp) != 0) {
-                                        return false;
-                                    }
-                                }
-                                if (localp != null) {
-                                    ntp.getString(cqp.getLocalCode(), temp);
-                                    if (localp.compareTo(temp) != 0) {
-                                        return false;
-                                    }
-                                }
-                                return true;
-                            }
-                        };
-                        break;
-                    }
-
-                    case COMMENT:
-                        filter = new INodeFilter() {
-                            @Override
-                            public boolean accept(NodeTreePointable ntp, TaggedValuePointable tvp) {
-                                return tvp.getTag() == ValueTag.COMMENT_NODE_TAG;
-                            }
-                        };
-                        break;
-
-                    case DOCUMENT:
-                        filter = new INodeFilter() {
-                            @Override
-                            public boolean accept(NodeTreePointable ntp, TaggedValuePointable tvp) {
-                                return tvp.getTag() == ValueTag.DOCUMENT_NODE_TAG;
-                            }
-                        };
-                        break;
-
-                    case ELEMENT: {
-                        ElementType eType = (ElementType) nodeType;
-                        NameTest nameTest = eType.getNameTest();
-                        byte[] uri = nameTest.getUri();
-                        byte[] localName = nameTest.getLocalName();
-                        final UTF8StringPointable urip = (UTF8StringPointable) (uri == null ? null
-                                : UTF8StringPointable.FACTORY.createPointable());
-                        final UTF8StringPointable localp = (UTF8StringPointable) (localName == null ? null
-                                : UTF8StringPointable.FACTORY.createPointable());
-                        if (uri != null) {
-                            urip.set(uri, 0, uri.length);
-                        }
-                        if (localName != null) {
-                            localp.set(localName, 0, localName.length);
-                        }
-                        final IPointable temp = VoidPointable.FACTORY.createPointable();
-                        final ElementNodePointable enp = (ElementNodePointable) ElementNodePointable.FACTORY
-                                .createPointable();
-                        final CodedQNamePointable cqp = (CodedQNamePointable) CodedQNamePointable.FACTORY
-                                .createPointable();
-                        filter = new INodeFilter() {
-                            @Override
-                            public boolean accept(NodeTreePointable ntp, TaggedValuePointable tvp) {
-                                if (tvp.getTag() != ValueTag.ELEMENT_NODE_TAG) {
-                                    return false;
-                                }
-                                tvp.getValue(enp);
-                                enp.getName(cqp);
-                                if (urip != null) {
-                                    ntp.getString(cqp.getNamespaceCode(), temp);
-                                    if (urip.compareTo(temp) != 0) {
-                                        return false;
-                                    }
-                                }
-                                if (localp != null) {
-                                    ntp.getString(cqp.getLocalCode(), temp);
-                                    if (localp.compareTo(temp) != 0) {
-                                        return false;
-                                    }
-                                }
-                                return true;
-                            }
-                        };
-                        break;
-                    }
-
-                    case PI:
-                        filter = new INodeFilter() {
-                            @Override
-                            public boolean accept(NodeTreePointable ntp, TaggedValuePointable tvp) {
-                                return tvp.getTag() == ValueTag.PI_NODE_TAG;
-                            }
-                        };
-                        break;
-
-                    case TEXT:
-                        filter = new INodeFilter() {
-                            @Override
-                            public boolean accept(NodeTreePointable ntp, TaggedValuePointable tvp) {
-                                return tvp.getTag() == ValueTag.TEXT_NODE_TAG;
-                            }
-                        };
-                        break;
-                }
-            }
-
             protected boolean matches() {
                 return filter.accept(ntp, itemTvp);
             }
 
             protected void setNodeToResult(IPointable result) throws IOException {
                 nodeAbvs.reset();
-                DataOutput mainOut = nodeAbvs.getDataOutput();
-                mainOut.write(ValueTag.NODE_TREE_TAG);
-                boolean hasDictionary = ntp.dictionaryExists() && hasDictionary(itemTvp.getTag());
-                byte header = (byte) (hasDictionary ? NodeTreePointable.HEADER_DICTIONARY_EXISTS_MASK : 0);
-                // TODO add all header flags to this setting.
-                boolean hasNodeIds = ntp.nodeIdExists();
-                if (hasNodeIds) {
-                    header |= NodeTreePointable.HEADER_NODEID_EXISTS_MASK;
-                }
-                mainOut.write(header);
-                if (hasNodeIds) {
-                    mainOut.writeInt(ntp.getRootNodeId());
-                }
-                if (hasDictionary) {
-                    mainOut.write(ntp.getByteArray(), ntp.getDictionaryOffset(), ntp.getDictionarySize());
-                }
-                mainOut.write(itemTvp.getByteArray(), itemTvp.getStartOffset(), itemTvp.getLength());
+                NodeSubTreeBuilder nstb = new NodeSubTreeBuilder();
+                nstb.reset(nodeAbvs);
+                nstb.setChildNode(ntp, itemTvp);
+                nstb.finish();
                 result.set(nodeAbvs.getByteArray(), nodeAbvs.getStartOffset(), nodeAbvs.getLength());
             }
 
-            private boolean hasDictionary(byte tag) {
-                switch (tag) {
-                    case ValueTag.ATTRIBUTE_NODE_TAG:
-                    case ValueTag.DOCUMENT_NODE_TAG:
-                    case ValueTag.ELEMENT_NODE_TAG:
-                        return true;
-                }
-                return false;
-            }
-
             protected void getSequence(NodeTreePointable ntp, SequencePointable seqp) throws SystemException {
                 ntp.getRootNode(rootTVP);
                 switch (rootTVP.getTag()) {
@@ -317,9 +145,4 @@ public class ChildPathStepUnnestingEvalu
 
         };
     }
-
-    private interface INodeFilter {
-        public boolean accept(NodeTreePointable ntp, TaggedValuePointable tvp);
-    }
-
 }
\ No newline at end of file

Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/step/NodeTestFilter.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/step/NodeTestFilter.java?rev=1518726&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/step/NodeTestFilter.java (added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/step/NodeTestFilter.java Thu Aug 29 17:49:13 2013
@@ -0,0 +1,182 @@
+/*
+ * 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.runtime.functions.step;
+
+import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
+import org.apache.vxquery.datamodel.accessors.atomic.CodedQNamePointable;
+import org.apache.vxquery.datamodel.accessors.nodes.AttributeNodePointable;
+import org.apache.vxquery.datamodel.accessors.nodes.ElementNodePointable;
+import org.apache.vxquery.datamodel.accessors.nodes.NodeTreePointable;
+import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.types.AttributeType;
+import org.apache.vxquery.types.ElementType;
+import org.apache.vxquery.types.NameTest;
+import org.apache.vxquery.types.NodeType;
+import org.apache.vxquery.types.SequenceType;
+
+import edu.uci.ics.hyracks.data.std.api.IPointable;
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+import edu.uci.ics.hyracks.data.std.primitive.VoidPointable;
+
+public class NodeTestFilter {
+
+    public static INodeFilter getNodeTestFilter(SequenceType sType) {
+        INodeFilter filter;
+        final NodeType nodeType = (NodeType) sType.getItemType();
+        switch (nodeType.getNodeKind()) {
+            case ATTRIBUTE: {
+                AttributeType aType = (AttributeType) nodeType;
+                NameTest nameTest = aType.getNameTest();
+                byte[] uri = nameTest.getUri();
+                byte[] localName = nameTest.getLocalName();
+                final UTF8StringPointable urip = (UTF8StringPointable) (uri == null ? null
+                        : UTF8StringPointable.FACTORY.createPointable());
+                final UTF8StringPointable localp = (UTF8StringPointable) (localName == null ? null
+                        : UTF8StringPointable.FACTORY.createPointable());
+                if (uri != null) {
+                    urip.set(uri, 0, uri.length);
+                }
+                if (localName != null) {
+                    localp.set(localName, 0, localName.length);
+                }
+                final IPointable temp = VoidPointable.FACTORY.createPointable();
+                final AttributeNodePointable anp = (AttributeNodePointable) AttributeNodePointable.FACTORY
+                        .createPointable();
+                final CodedQNamePointable cqp = (CodedQNamePointable) CodedQNamePointable.FACTORY.createPointable();
+                filter = new INodeFilter() {
+                    @Override
+                    public boolean accept(NodeTreePointable ntp, TaggedValuePointable tvp) {
+                        if (tvp.getTag() != ValueTag.ATTRIBUTE_NODE_TAG) {
+                            return false;
+                        }
+                        tvp.getValue(anp);
+                        anp.getName(cqp);
+                        if (urip != null) {
+                            ntp.getString(cqp.getNamespaceCode(), temp);
+                            if (urip.compareTo(temp) != 0) {
+                                return false;
+                            }
+                        }
+                        if (localp != null) {
+                            ntp.getString(cqp.getLocalCode(), temp);
+                            if (localp.compareTo(temp) != 0) {
+                                return false;
+                            }
+                        }
+                        return true;
+                    }
+                };
+                break;
+            }
+
+            case COMMENT:
+                filter = new INodeFilter() {
+                    @Override
+                    public boolean accept(NodeTreePointable ntp, TaggedValuePointable tvp) {
+                        return tvp.getTag() == ValueTag.COMMENT_NODE_TAG;
+                    }
+                };
+                break;
+
+            case DOCUMENT:
+                filter = new INodeFilter() {
+                    @Override
+                    public boolean accept(NodeTreePointable ntp, TaggedValuePointable tvp) {
+                        return tvp.getTag() == ValueTag.DOCUMENT_NODE_TAG;
+                    }
+                };
+                break;
+
+            case ELEMENT: {
+                ElementType eType = (ElementType) nodeType;
+                NameTest nameTest = eType.getNameTest();
+                byte[] uri = nameTest.getUri();
+                byte[] localName = nameTest.getLocalName();
+                final UTF8StringPointable urip = (UTF8StringPointable) (uri == null ? null
+                        : UTF8StringPointable.FACTORY.createPointable());
+                final UTF8StringPointable localp = (UTF8StringPointable) (localName == null ? null
+                        : UTF8StringPointable.FACTORY.createPointable());
+                if (uri != null) {
+                    urip.set(uri, 0, uri.length);
+                }
+                if (localName != null) {
+                    localp.set(localName, 0, localName.length);
+                }
+                final IPointable temp = VoidPointable.FACTORY.createPointable();
+                final ElementNodePointable enp = (ElementNodePointable) ElementNodePointable.FACTORY.createPointable();
+                final CodedQNamePointable cqp = (CodedQNamePointable) CodedQNamePointable.FACTORY.createPointable();
+                filter = new INodeFilter() {
+                    @Override
+                    public boolean accept(NodeTreePointable ntp, TaggedValuePointable tvp) {
+                        if (tvp.getTag() != ValueTag.ELEMENT_NODE_TAG) {
+                            return false;
+                        }
+                        tvp.getValue(enp);
+                        enp.getName(cqp);
+                        if (urip != null) {
+                            ntp.getString(cqp.getNamespaceCode(), temp);
+                            if (urip.compareTo(temp) != 0) {
+                                return false;
+                            }
+                        }
+                        if (localp != null) {
+                            ntp.getString(cqp.getLocalCode(), temp);
+                            if (localp.compareTo(temp) != 0) {
+                                return false;
+                            }
+                        }
+                        return true;
+                    }
+                };
+                break;
+            }
+
+            case PI:
+                filter = new INodeFilter() {
+                    @Override
+                    public boolean accept(NodeTreePointable ntp, TaggedValuePointable tvp) {
+                        return tvp.getTag() == ValueTag.PI_NODE_TAG;
+                    }
+                };
+                break;
+
+            case TEXT:
+                filter = new INodeFilter() {
+                    @Override
+                    public boolean accept(NodeTreePointable ntp, TaggedValuePointable tvp) {
+                        return tvp.getTag() == ValueTag.TEXT_NODE_TAG;
+                    }
+                };
+                break;
+                
+            case ANY:
+            default:
+                filter = new INodeFilter() {
+                    @Override
+                    public boolean accept(NodeTreePointable ntp, TaggedValuePointable tvp) {
+                        return true;
+                    }
+                };
+                break;
+        }
+        return filter;
+    }
+
+    public interface INodeFilter {
+        public boolean accept(NodeTreePointable ntp, TaggedValuePointable tvp);
+    }
+}
\ No newline at end of file

Propchange: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/step/NodeTestFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native