You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vxquery.apache.org by vi...@apache.org on 2012/07/10 14:13:13 UTC

svn commit: r1359630 - in /incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery: datamodel/accessors/ datamodel/accessors/atomic/ runtime/functions/type/ serializer/ types/ xmlquery/translator/

Author: vinayakb
Date: Tue Jul 10 12:13:12 2012
New Revision: 1359630

URL: http://svn.apache.org/viewvc?rev=1359630&view=rev
Log:
Enabled xs:decimal. Added 'treat as' functionality

Modified:
    incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/PointablePoolFactory.java
    incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDecimalPointable.java
    incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/type/AbstractTypeScalarEvaluatorFactory.java
    incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/type/TreatScalarEvaluatorFactory.java
    incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/serializer/XMLSerializer.java
    incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/types/BuiltinTypeRegistry.java
    incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/types/NameTest.java
    incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/types/NodeKind.java
    incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/types/ProcessingInstructionType.java
    incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java

Modified: incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/PointablePoolFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/PointablePoolFactory.java?rev=1359630&r1=1359629&r2=1359630&view=diff
==============================================================================
--- incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/PointablePoolFactory.java (original)
+++ incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/PointablePoolFactory.java Tue Jul 10 12:13:12 2012
@@ -1,6 +1,7 @@
 package org.apache.vxquery.datamodel.accessors;
 
 import org.apache.vxquery.datamodel.accessors.atomic.CodedQNamePointable;
+import org.apache.vxquery.datamodel.accessors.atomic.XSDecimalPointable;
 import org.apache.vxquery.datamodel.accessors.nodes.AttributeNodePointable;
 import org.apache.vxquery.datamodel.accessors.nodes.DocumentNodePointable;
 import org.apache.vxquery.datamodel.accessors.nodes.ElementNodePointable;
@@ -39,6 +40,7 @@ public class PointablePoolFactory {
         pp.register(SequencePointable.class, SequencePointable.FACTORY);
         pp.register(VoidPointable.class, VoidPointable.FACTORY);
         pp.register(CodedQNamePointable.class, CodedQNamePointable.FACTORY);
+        pp.register(XSDecimalPointable.class, XSDecimalPointable.FACTORY);
 
         pp.register(NodeTreePointable.class, NodeTreePointable.FACTORY);
         pp.register(DocumentNodePointable.class, DocumentNodePointable.FACTORY);

Modified: incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDecimalPointable.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDecimalPointable.java?rev=1359630&r1=1359629&r2=1359630&view=diff
==============================================================================
--- incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDecimalPointable.java (original)
+++ incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/atomic/XSDecimalPointable.java Tue Jul 10 12:13:12 2012
@@ -76,7 +76,7 @@ public class XSDecimalPointable extends 
     public void setDecimal(double doubleValue) {
         setDecimal(doubleValue, bytes, start);
     }
-    
+
     public static void setDecimal(double doubleValue, byte[] bytes, int start) {
         byte decimalPlace = 0;
         long value = 0;
@@ -85,7 +85,7 @@ public class XSDecimalPointable extends 
         int c;
         Double doubleObject = new Double(doubleValue);
         String strTest = doubleObject.toString();
-        
+
         for (int i = 0; i < strTest.length() && count < PRECISION; ++i) {
             c = strTest.charAt(i);
             if (Character.isDigit(c)) {
@@ -94,8 +94,7 @@ public class XSDecimalPointable extends 
                     decimalPlace++;
                 }
                 count++;
-            }
-            else {
+            } else {
                 pastDecimal = true;
             }
         }

Modified: incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/type/AbstractTypeScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/type/AbstractTypeScalarEvaluatorFactory.java?rev=1359630&r1=1359629&r2=1359630&view=diff
==============================================================================
--- incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/type/AbstractTypeScalarEvaluatorFactory.java (original)
+++ incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/type/AbstractTypeScalarEvaluatorFactory.java Tue Jul 10 12:13:12 2012
@@ -37,7 +37,7 @@ public abstract class AbstractTypeScalar
 
         protected abstract void setSequenceType(SequenceType sType);
 
-        protected abstract void evaluate(TaggedValuePointable tvp, IPointable result);
+        protected abstract void evaluate(TaggedValuePointable tvp, IPointable result) throws SystemException;
 
         @Override
         protected final void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {

Modified: incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/type/TreatScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/type/TreatScalarEvaluatorFactory.java?rev=1359630&r1=1359629&r2=1359630&view=diff
==============================================================================
--- incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/type/TreatScalarEvaluatorFactory.java (original)
+++ incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/type/TreatScalarEvaluatorFactory.java Tue Jul 10 12:13:12 2012
@@ -1,6 +1,24 @@
 package org.apache.vxquery.runtime.functions.type;
 
+import org.apache.vxquery.datamodel.accessors.SequencePointable;
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
+import org.apache.vxquery.datamodel.accessors.nodes.NodeTreePointable;
+import org.apache.vxquery.datamodel.accessors.nodes.PINodePointable;
+import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.exceptions.ErrorCode;
+import org.apache.vxquery.exceptions.SystemException;
+import org.apache.vxquery.types.AnyItemType;
+import org.apache.vxquery.types.AtomicType;
+import org.apache.vxquery.types.AttributeType;
+import org.apache.vxquery.types.BuiltinTypeRegistry;
+import org.apache.vxquery.types.DocumentType;
+import org.apache.vxquery.types.ElementType;
+import org.apache.vxquery.types.ItemType;
+import org.apache.vxquery.types.NodeKind;
+import org.apache.vxquery.types.NodeType;
+import org.apache.vxquery.types.ProcessingInstructionType;
+import org.apache.vxquery.types.Quantifier;
+import org.apache.vxquery.types.SchemaType;
 import org.apache.vxquery.types.SequenceType;
 
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
@@ -8,6 +26,7 @@ import edu.uci.ics.hyracks.algebricks.ru
 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.UTF8StringPointable;
 
 public class TreatScalarEvaluatorFactory extends AbstractTypeScalarEvaluatorFactory {
     private static final long serialVersionUID = 1L;
@@ -20,14 +39,147 @@ public class TreatScalarEvaluatorFactory
     protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
             throws AlgebricksException {
         return new AbstractTypeScalarEvaluator(args, ctx) {
+            private final NodeTreePointable ntp = (NodeTreePointable) NodeTreePointable.FACTORY.createPointable();
+            private final TaggedValuePointable tempTVP1 = (TaggedValuePointable) TaggedValuePointable.FACTORY
+                    .createPointable();
+            private final PINodePointable pinp = (PINodePointable) PINodePointable.FACTORY.createPointable();
+            private final UTF8StringPointable utf8sp = (UTF8StringPointable) UTF8StringPointable.FACTORY
+                    .createPointable();
+            private final SequencePointable seqp = (SequencePointable) SequencePointable.FACTORY.createPointable();
+            private final TaggedValuePointable tempTVP2 = (TaggedValuePointable) TaggedValuePointable.FACTORY
+                    .createPointable();
+
+            private SequenceType sequenceType;
+
             @Override
-            protected void evaluate(TaggedValuePointable tvp, IPointable result) {
+            protected void evaluate(TaggedValuePointable tvp, IPointable result) throws SystemException {
+                boolean success = sequenceTypeMatch(tvp);
+                if (!success) {
+                    throw new SystemException(ErrorCode.XPDY0050);
+                }
                 result.set(tvp);
             }
 
+            private boolean sequenceTypeMatch(TaggedValuePointable tvp) {
+                byte tag = tvp.getTag();
+                Quantifier stq = sequenceType.getQuantifier();
+                ItemType it = sequenceType.getItemType();
+                if (tag == ValueTag.SEQUENCE_TAG) {
+                    tvp.getValue(seqp);
+                    Quantifier vq = getSequenceQuantifier(seqp);
+                    if (stq.isSubQuantifier(vq)) {
+                        if (it instanceof AnyItemType) {
+                            return true;
+                        } else {
+                            int n = seqp.getEntryCount();
+                            for (int i = 0; i < n; ++i) {
+                                seqp.getEntry(i, tempTVP2);
+                                if (!itemSequenceTypeMatch(tempTVP2, it)) {
+                                    return false;
+                                }
+                            }
+                            return true;
+                        }
+                    }
+                } else {
+                    if (stq.isSubQuantifier(Quantifier.QUANT_ONE)) {
+                        return itemSequenceTypeMatch(tvp, it);
+                    }
+                }
+                return false;
+            }
+
+            private boolean itemSequenceTypeMatch(TaggedValuePointable tvp, ItemType it) {
+                byte tag = tvp.getTag();
+                if (it instanceof AnyItemType) {
+                    return true;
+                } else if (it.isAtomicType()) {
+                    AtomicType ait = (AtomicType) it;
+                    if (BuiltinTypeRegistry.INSTANCE.isBuiltinTypeId(tag)) {
+                        SchemaType vType = BuiltinTypeRegistry.INSTANCE.getSchemaTypeById(tag);
+                        while (vType != null && vType.getTypeId() != ait.getTypeId()) {
+                            vType = vType.getBaseType();
+                        }
+                        return vType != null;
+                    }
+                } else if (it instanceof NodeType && tag == ValueTag.NODE_TREE_TAG) {
+                    NodeType nt = (NodeType) it;
+                    NodeKind kind = nt.getNodeKind();
+                    if (kind == NodeKind.ANY) {
+                        return true;
+                    } else {
+                        tvp.getValue(ntp);
+                        ntp.getRootNode(tempTVP1);
+                        switch (tempTVP1.getTag()) {
+                            case ValueTag.ATTRIBUTE_NODE_TAG:
+                                if (kind == NodeKind.ATTRIBUTE) {
+                                    if (nt.equals(AttributeType.ANYATTRIBUTE)) {
+                                        return true;
+                                    } else {
+
+                                    }
+                                }
+                                break;
+
+                            case ValueTag.COMMENT_NODE_TAG:
+                                return kind == NodeKind.ATTRIBUTE;
+
+                            case ValueTag.DOCUMENT_NODE_TAG:
+                                if (kind == NodeKind.DOCUMENT) {
+                                    if (nt.equals(DocumentType.ANYDOCUMENT)) {
+                                        return true;
+                                    } else {
+
+                                    }
+                                }
+                                break;
+
+                            case ValueTag.ELEMENT_NODE_TAG:
+                                if (kind == NodeKind.ELEMENT) {
+                                    if (nt.equals(ElementType.ANYELEMENT)) {
+                                        return true;
+                                    } else {
+
+                                    }
+                                }
+                                break;
+
+                            case ValueTag.PI_NODE_TAG:
+                                if (kind == NodeKind.PI) {
+                                    if (nt.equals(ProcessingInstructionType.ANYPI)) {
+                                        return true;
+                                    } else {
+                                        ProcessingInstructionType pit = (ProcessingInstructionType) nt;
+                                        tempTVP1.getValue(pinp);
+                                        pinp.getTarget(ntp, utf8sp);
+                                        byte[] target = pit.getTarget();
+                                        return utf8sp.compareTo(target, 0, target.length) == 0;
+                                    }
+                                }
+                                break;
+
+                            case ValueTag.TEXT_NODE_TAG:
+                                return kind == NodeKind.TEXT;
+                        }
+                    }
+                }
+                return false;
+            }
+
+            private Quantifier getSequenceQuantifier(SequencePointable seqp) {
+                switch (seqp.getEntryCount()) {
+                    case 0:
+                        return Quantifier.QUANT_ZERO;
+
+                    case 1:
+                        return Quantifier.QUANT_ONE;
+                }
+                return Quantifier.QUANT_PLUS;
+            }
+
             @Override
             protected void setSequenceType(SequenceType sType) {
-
+                this.sequenceType = sType;
             }
         };
     }

Modified: incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/serializer/XMLSerializer.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/serializer/XMLSerializer.java?rev=1359630&r1=1359629&r2=1359630&view=diff
==============================================================================
--- incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/serializer/XMLSerializer.java (original)
+++ incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/serializer/XMLSerializer.java Tue Jul 10 12:13:12 2012
@@ -7,6 +7,7 @@ import org.apache.vxquery.datamodel.acce
 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.atomic.XSDecimalPointable;
 import org.apache.vxquery.datamodel.accessors.nodes.AttributeNodePointable;
 import org.apache.vxquery.datamodel.accessors.nodes.DocumentNodePointable;
 import org.apache.vxquery.datamodel.accessors.nodes.ElementNodePointable;
@@ -62,6 +63,10 @@ public class XMLSerializer implements IP
                 printDouble(ps, tvp);
                 break;
 
+            case ValueTag.XS_DECIMAL_TAG:
+                printDecimal(ps, tvp);
+                break;
+
             case ValueTag.XS_BOOLEAN_TAG:
                 printBoolean(ps, tvp);
                 break;
@@ -103,6 +108,36 @@ public class XMLSerializer implements IP
         }
     }
 
+    private void printDecimal(PrintStream ps, TaggedValuePointable tvp) {
+        XSDecimalPointable dp = pp.takeOne(XSDecimalPointable.class);
+        try {
+            tvp.getValue(dp);
+            byte decimalPlace = dp.getDecimalPlace();
+            long value = dp.getDecimalValue();
+            int nDigits = (int) Math.log10(value) + 1;
+            long pow10 = (long) Math.pow(10, nDigits - 1);
+            int start = Math.max(decimalPlace, nDigits - 1);
+            int end = Math.min(0, decimalPlace);
+            if (start > nDigits) {
+                ps.append("0.");
+            }
+            for (int i = start; i >= end; --i) {
+                if (i >= nDigits || i < 0) {
+                    ps.append('0');
+                } else {
+                    ps.append((char) ('0' + (value / pow10)));
+                    value %= pow10;
+                    pow10 /= 10;
+                }
+                if (i == decimalPlace) {
+                    ps.append('.');
+                }
+            }
+        } finally {
+            pp.giveBack(dp);
+        }
+    }
+
     private void printNodeTree(PrintStream ps, TaggedValuePointable tvp) {
         ntp = pp.takeOne(NodeTreePointable.class);
         TaggedValuePointable rootTVP = pp.takeOne(TaggedValuePointable.class);

Modified: incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/types/BuiltinTypeRegistry.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/types/BuiltinTypeRegistry.java?rev=1359630&r1=1359629&r2=1359630&view=diff
==============================================================================
--- incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/types/BuiltinTypeRegistry.java (original)
+++ incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/types/BuiltinTypeRegistry.java Tue Jul 10 12:13:12 2012
@@ -271,8 +271,12 @@ public final class BuiltinTypeRegistry {
         return types[id];
     }
 
+    public boolean isBuiltinTypeId(int id) {
+        return id < BuiltinTypeConstants.BUILTIN_TYPE_COUNT;
+    }
+
     public boolean isBuiltinType(SchemaType type) {
-        return type.getTypeId() < BuiltinTypeConstants.BUILTIN_TYPE_COUNT;
+        return isBuiltinTypeId(type.getTypeId());
     }
 
     public SchemaType getBuiltinBaseType(SchemaType type) {

Modified: incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/types/NameTest.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/types/NameTest.java?rev=1359630&r1=1359629&r2=1359630&view=diff
==============================================================================
--- incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/types/NameTest.java (original)
+++ incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/types/NameTest.java Tue Jul 10 12:13:12 2012
@@ -16,47 +16,55 @@
  */
 package org.apache.vxquery.types;
 
-import javax.xml.namespace.QName;
+import java.util.Arrays;
+
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
 
 public final class NameTest {
     public static final String WILDCARD = null;
 
     public static final NameTest STAR_NAMETEST = new NameTest(null, null);
 
-    private String uri;
-    private String localName;
+    private byte[] uri;
+    private byte[] localName;
 
-    public NameTest(String uri, String localName) {
+    public NameTest(byte[] uri, byte[] localName) {
         this.uri = uri;
         this.localName = localName;
     }
 
-    public String getUri() {
+    public byte[] getUri() {
         return uri;
     }
 
-    public String getLocalName() {
+    public byte[] getLocalName() {
         return localName;
     }
 
-    public QName asQName() {
-        if (uri == null || localName == null) {
-            throw new UnsupportedOperationException();
-        }
-        return new QName(uri, localName);
-    }
-
     @Override
     public String toString() {
-        return "NameTest(" + asQName() + ")";
+        StringBuilder buffer = new StringBuilder();
+        buffer.append("NameTest({");
+        if (uri != null) {
+            UTF8StringPointable.toString(buffer, uri, 0);
+        } else {
+            buffer.append('*');
+        }
+        buffer.append('}');
+        if (localName != null) {
+            UTF8StringPointable.toString(buffer, localName, 0);
+        } else {
+            buffer.append('*');
+        }
+        return buffer.toString();
     }
 
     @Override
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result + ((localName == null) ? 0 : localName.hashCode());
-        result = prime * result + ((uri == null) ? 0 : uri.hashCode());
+        result = prime * result + ((localName == null) ? 0 : Arrays.hashCode(localName));
+        result = prime * result + ((uri == null) ? 0 : Arrays.hashCode(uri));
         return result;
     }
 
@@ -72,12 +80,12 @@ public final class NameTest {
         if (localName == null) {
             if (other.localName != null)
                 return false;
-        } else if (!localName.equals(other.localName))
+        } else if (!Arrays.equals(localName, other.localName))
             return false;
         if (uri == null) {
             if (other.uri != null)
                 return false;
-        } else if (!uri.equals(other.uri))
+        } else if (!Arrays.equals(uri, other.uri))
             return false;
         return true;
     }

Modified: incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/types/NodeKind.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/types/NodeKind.java?rev=1359630&r1=1359629&r2=1359630&view=diff
==============================================================================
--- incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/types/NodeKind.java (original)
+++ incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/types/NodeKind.java Tue Jul 10 12:13:12 2012
@@ -17,5 +17,11 @@
 package org.apache.vxquery.types;
 
 public enum NodeKind {
-    ANY, ATTRIBUTE, COMMENT, DOCUMENT, ELEMENT, PI, TEXT,
+    ANY,
+    ATTRIBUTE,
+    COMMENT,
+    DOCUMENT,
+    ELEMENT,
+    PI,
+    TEXT,
 }
\ No newline at end of file

Modified: incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/types/ProcessingInstructionType.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/types/ProcessingInstructionType.java?rev=1359630&r1=1359629&r2=1359630&view=diff
==============================================================================
--- incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/types/ProcessingInstructionType.java (original)
+++ incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/types/ProcessingInstructionType.java Tue Jul 10 12:13:12 2012
@@ -16,12 +16,14 @@
  */
 package org.apache.vxquery.types;
 
+import java.util.Arrays;
+
 public final class ProcessingInstructionType extends AbstractNodeType {
     public static final ProcessingInstructionType ANYPI = new ProcessingInstructionType(null);
 
-    private String target;
+    private byte[] target;
 
-    public ProcessingInstructionType(String target) {
+    public ProcessingInstructionType(byte[] target) {
         this.target = target;
     }
 
@@ -30,7 +32,7 @@ public final class ProcessingInstruction
         return NodeKind.PI;
     }
 
-    public String getTarget() {
+    public byte[] getTarget() {
         return target;
     }
 
@@ -38,7 +40,7 @@ public final class ProcessingInstruction
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result + ((target == null) ? 0 : target.hashCode());
+        result = prime * result + ((target == null) ? 0 : Arrays.hashCode(target));
         return result;
     }
 
@@ -54,7 +56,7 @@ public final class ProcessingInstruction
         if (target == null) {
             if (other.target != null)
                 return false;
-        } else if (!target.equals(other.target))
+        } else if (!Arrays.equals(target, other.target))
             return false;
         return true;
     }

Modified: incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java?rev=1359630&r1=1359629&r2=1359630&view=diff
==============================================================================
--- incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java (original)
+++ incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java Tue Jul 10 12:13:12 2012
@@ -161,6 +161,7 @@ import edu.uci.ics.hyracks.algebricks.co
 import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.WriteOperator;
 import edu.uci.ics.hyracks.algebricks.core.algebra.plan.ALogicalPlanImpl;
 import edu.uci.ics.hyracks.dataflow.common.comm.io.ByteArrayAccessibleOutputStream;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
 
 public class XMLQueryTranslator {
     private static final Pattern UNQUOTER = Pattern
@@ -539,7 +540,7 @@ public class XMLQueryTranslator {
                 if (pit.getTarget() == null) {
                     return ProcessingInstructionType.ANYPI;
                 }
-                return new ProcessingInstructionType(pit.getTarget());
+                return new ProcessingInstructionType(createUTF8String(pit.getTarget()));
             }
 
             case ATTRIBUTE_TEST: {
@@ -563,7 +564,8 @@ public class XMLQueryTranslator {
                     } else {
                         uri = "";
                     }
-                    nt = new NameTest(uri, ntNode.getLocalName());
+
+                    nt = new NameTest(createUTF8String(uri), createUTF8String(ntNode.getLocalName()));
                 }
                 SchemaType cType = BuiltinTypeRegistry.XS_ANY_ATOMIC;
                 if (at.getTypeName() != null) {
@@ -600,7 +602,7 @@ public class XMLQueryTranslator {
                     } else {
                         uri = "";
                     }
-                    nt = new NameTest(uri, ntNode.getLocalName());
+                    nt = new NameTest(createUTF8String(uri), createUTF8String(ntNode.getLocalName()));
                 }
                 SchemaType cType = AnyType.INSTANCE;
                 if (et.getTypeName() != null) {
@@ -621,6 +623,17 @@ public class XMLQueryTranslator {
         }
     }
 
+    private byte[] createUTF8String(String str) {
+        ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
+        StringValueBuilder svb = new StringValueBuilder();
+        try {
+            svb.write(str, abvs.getDataOutput());
+        } catch (IOException e) {
+            throw new IllegalStateException(e);
+        }
+        return Arrays.copyOf(abvs.getByteArray(), abvs.getLength());
+    }
+
     private ILogicalPlan translateMainModule(MainModuleNode moduleNode) throws SystemException {
         QueryBodyNode qbn = moduleNode.getQueryBody();
         ASTNode queryBody = qbn.getExpression();
@@ -1552,7 +1565,7 @@ public class XMLQueryTranslator {
                             uri = "";
                         }
                     }
-                    NameTest nameTest = new NameTest(uri, ntn.getLocalName());
+                    NameTest nameTest = new NameTest(createUTF8String(uri), createUTF8String(ntn.getLocalName()));
                     if (axis == AxisStepNode.Axis.ATTRIBUTE || axis == AxisStepNode.Axis.ABBREV_ATTRIBUTE) {
                         nt = new AttributeType(nameTest, BuiltinTypeRegistry.XS_ANY_ATOMIC);
                     } else {