incubator-vxquery-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prest...@apache.org
Subject svn commit: r1386877 - /incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/
Date Mon, 17 Sep 2012 22:22:05 GMT
Author: prestonc
Date: Mon Sep 17 22:22:04 2012
New Revision: 1386877

URL: http://svn.apache.org/viewvc?rev=1386877&view=rev
Log:
Added empty sequence support as a argument and support for derived string types for string function.

Modified:
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnCodepointEqualEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnCompareEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnConcatEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnContainsEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnEndsWithEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnLowerCaseEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnStartsWithEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnStringJoinEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnStringLengthEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnStringScalarEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnSubstringAfterEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnSubstringBeforeEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnSubstringEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnUpperCaseEvaluatorFactory.java

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnCodepointEqualEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnCodepointEqualEvaluatorFactory.java?rev=1386877&r1=1386876&r2=1386877&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnCodepointEqualEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnCodepointEqualEvaluatorFactory.java Mon Sep 17 22:22:04 2012
@@ -16,12 +16,15 @@
  */
 package org.apache.vxquery.runtime.functions.strings;
 
+import org.apache.vxquery.datamodel.accessors.SequencePointable;
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
 import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.datamodel.values.XDMConstants;
 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;
@@ -42,6 +45,7 @@ public class FnCodepointEqualEvaluatorFa
             throws AlgebricksException {
         final UTF8StringPointable stringp1 = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
         final UTF8StringPointable stringp2 = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
+        final SequencePointable seqp = (SequencePointable) SequencePointable.FACTORY.createPointable();
 
         return new AbstractTaggedValueArgumentScalarEvaluator(args) {
             @Override
@@ -54,15 +58,35 @@ public class FnCodepointEqualEvaluatorFa
                 TaggedValuePointable tvp1 = args[0];
                 TaggedValuePointable tvp2 = args[1];
 
-                // Only accept strings as input.
-                if (tvp1.getTag() != ValueTag.XS_STRING_TAG && tvp1.getTag() != ValueTag.XS_ANY_URI_TAG) {
-                    throw new SystemException(ErrorCode.XPTY0004);
+                // Only accept strings or empty sequence as input.
+                if (tvp1.getTag() == ValueTag.SEQUENCE_TAG) {
+                    tvp1.getValue(seqp);
+                    if (seqp.getEntryCount() == 0) {
+                        XDMConstants.setEmptySequence(result);
+                        return;
+                    } else {
+                        throw new SystemException(ErrorCode.XPTY0004);
+                    }
+                } else {
+                    if (!FunctionHelper.isDerivedFromString(tvp1.getTag())) {
+                        throw new SystemException(ErrorCode.XPTY0004);
+                    }
+                    tvp1.getValue(stringp1);
                 }
-                if (tvp2.getTag() != ValueTag.XS_STRING_TAG && tvp2.getTag() != ValueTag.XS_ANY_URI_TAG) {
-                    throw new SystemException(ErrorCode.XPTY0004);
+                if (tvp2.getTag() == ValueTag.SEQUENCE_TAG) {
+                    tvp2.getValue(seqp);
+                    if (seqp.getEntryCount() == 0) {
+                        XDMConstants.setEmptySequence(result);
+                        return;
+                    } else {
+                        throw new SystemException(ErrorCode.XPTY0004);
+                    }
+                } else {
+                    if (!FunctionHelper.isDerivedFromString(tvp2.getTag())) {
+                        throw new SystemException(ErrorCode.XPTY0004);
+                    }
+                    tvp2.getValue(stringp2);
                 }
-                tvp1.getValue(stringp1);
-                tvp2.getValue(stringp2);
 
                 if (stringp1.compareTo(stringp2) == 0) {
                     booleanResult[1] = 1;

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnCompareEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnCompareEvaluatorFactory.java?rev=1386877&r1=1386876&r2=1386877&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnCompareEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnCompareEvaluatorFactory.java Mon Sep 17 22:22:04 2012
@@ -16,12 +16,15 @@
  */
 package org.apache.vxquery.runtime.functions.strings;
 
+import org.apache.vxquery.datamodel.accessors.SequencePointable;
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
 import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.datamodel.values.XDMConstants;
 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;
@@ -45,6 +48,7 @@ public class FnCompareEvaluatorFactory e
         final UTF8StringPointable stringp2 = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
         final UTF8StringPointable stringp3 = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
         final byte[] integerResult = new byte[LongPointable.TYPE_TRAITS.getFixedLength() + 1];
+        final SequencePointable seqp = (SequencePointable) SequencePointable.FACTORY.createPointable();
 
         return new AbstractTaggedValueArgumentScalarEvaluator(args) {
             @Override
@@ -52,15 +56,35 @@ public class FnCompareEvaluatorFactory e
                 TaggedValuePointable tvp1 = args[0];
                 TaggedValuePointable tvp2 = args[1];
 
-                // Only accept strings as input.
-                if (tvp1.getTag() != ValueTag.XS_STRING_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
+                // Only accept strings or empty sequence as input.
+                if (tvp1.getTag() == ValueTag.SEQUENCE_TAG) {
+                    tvp1.getValue(seqp);
+                    if (seqp.getEntryCount() == 0) {
+                        XDMConstants.setEmptySequence(result);
+                        return;
+                    } else {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                } else {
+                    if (!FunctionHelper.isDerivedFromString(tvp1.getTag())) {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                    tvp1.getValue(stringp1);
                 }
-                if (tvp2.getTag() != ValueTag.XS_STRING_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
+                if (tvp2.getTag() == ValueTag.SEQUENCE_TAG) {
+                    tvp2.getValue(seqp);
+                    if (seqp.getEntryCount() == 0) {
+                        XDMConstants.setEmptySequence(result);
+                        return;
+                    } else {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                } else {
+                    if (!FunctionHelper.isDerivedFromString(tvp2.getTag())) {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                    tvp2.getValue(stringp2);
                 }
-                tvp1.getValue(stringp1);
-                tvp2.getValue(stringp2);
 
                 // Third parameter is optional.
                 if (args.length > 2) {

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnConcatEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnConcatEvaluatorFactory.java?rev=1386877&r1=1386876&r2=1386877&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnConcatEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnConcatEvaluatorFactory.java Mon Sep 17 22:22:04 2012
@@ -20,32 +20,19 @@ import java.io.DataOutput;
 import java.io.IOException;
 
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
-import org.apache.vxquery.datamodel.accessors.atomic.XSBinaryPointable;
-import org.apache.vxquery.datamodel.accessors.atomic.XSDatePointable;
-import org.apache.vxquery.datamodel.accessors.atomic.XSDateTimePointable;
-import org.apache.vxquery.datamodel.accessors.atomic.XSDecimalPointable;
-import org.apache.vxquery.datamodel.accessors.atomic.XSDurationPointable;
-import org.apache.vxquery.datamodel.accessors.atomic.XSQNamePointable;
-import org.apache.vxquery.datamodel.accessors.atomic.XSTimePointable;
 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.cast.CastToStringOperation;
+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.BooleanPointable;
-import edu.uci.ics.hyracks.data.std.primitive.BytePointable;
-import edu.uci.ics.hyracks.data.std.primitive.DoublePointable;
-import edu.uci.ics.hyracks.data.std.primitive.FloatPointable;
-import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
-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.util.ArrayBackedValueStorage;
 
@@ -64,7 +51,7 @@ public class FnConcatEvaluatorFactory ex
         final ArrayBackedValueStorage abvsInner = new ArrayBackedValueStorage();
         final DataOutput dOutInner = abvsInner.getDataOutput();
         final CastToStringOperation castToString = new CastToStringOperation();
-        final TypedPointables tp = new TypedPointables();
+        final FunctionHelper.TypedPointables tp = new FunctionHelper.TypedPointables();
 
         return new AbstractTaggedValueArgumentScalarEvaluator(args) {
             @Override
@@ -84,7 +71,7 @@ public class FnConcatEvaluatorFactory ex
                         TaggedValuePointable tvp = args[i];
 
                         // TODO Update function to support cast to a string from any atomic value.
-                        if (tvp.getTag() != ValueTag.XS_STRING_TAG) {
+                        if (!FunctionHelper.isDerivedFromString(tvp.getTag())) {
 
                             try {
                                 abvsInner.reset();
@@ -93,10 +80,6 @@ public class FnConcatEvaluatorFactory ex
                                         tvp.getValue(tp.utf8sp);
                                         castToString.convertAnyURI(tp.utf8sp, dOutInner);
                                         break;
-                                    case ValueTag.XS_STRING_TAG:
-                                        tvp.getValue(tp.utf8sp);
-                                        castToString.convertString(tp.utf8sp, dOutInner);
-                                        break;
                                     case ValueTag.XS_UNTYPED_ATOMIC_TAG:
                                         tvp.getValue(tp.utf8sp);
                                         castToString.convertUntypedAtomic(tp.utf8sp, dOutInner);
@@ -198,8 +181,18 @@ public class FnConcatEvaluatorFactory ex
                                         tvp.getValue(tp.bytep);
                                         castToString.convertByte(tp.bytep, dOutInner);
                                         break;
+                                    case ValueTag.SEQUENCE_TAG:
+                                        tvp.getValue(tp.seqp);
+                                        if (tp.seqp.getEntryCount() == 0) {
+                                            // Byte Format: Type (1 byte) + String Length (2 bytes) + String.
+                                            dOutInner.write(ValueTag.XS_STRING_TAG);
+                                            dOutInner.write(0);
+                                            dOutInner.write(0);
+                                            break;
+                                        }
+                                        // Pass through if not empty sequence.
                                     default:
-                                        throw new SystemException(ErrorCode.XPDY0002);
+                                        throw new SystemException(ErrorCode.XPTY0004);
                                 }
 
                                 stringp.set(abvsInner.getByteArray(), abvsInner.getStartOffset() + 1,
@@ -211,15 +204,17 @@ public class FnConcatEvaluatorFactory ex
                             tvp.getValue(stringp);
                         }
 
-                        out.write(stringp.getByteArray(), stringp.getStartOffset() + 2, stringp.getUTFLength());
+                        // If its an empty string do nothing.
+                        if (stringp.getUTFLength() > 0) {
+                            out.write(stringp.getByteArray(), stringp.getStartOffset() + 2, stringp.getUTFLength());
+                        }
                     }
 
                     // Update the full length string in the byte array.
-                    byte[] stringResult = abvs.getByteArray();
-                    stringResult[1] = (byte) (((abvs.getLength() - 3) >>> 8) & 0xFF);
-                    stringResult[2] = (byte) (((abvs.getLength() - 3) >>> 0) & 0xFF);
+                    abvs.getByteArray()[1] = (byte) (((abvs.getLength() - 3) >>> 8) & 0xFF);
+                    abvs.getByteArray()[2] = (byte) (((abvs.getLength() - 3) >>> 0) & 0xFF);
 
-                    result.set(stringResult, 0, abvs.getLength());
+                    result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                 } catch (IOException e) {
                     throw new SystemException(ErrorCode.SYSE0001, e);
                 }
@@ -227,22 +222,4 @@ public class FnConcatEvaluatorFactory ex
         };
     }
 
-    private static class TypedPointables {
-        BooleanPointable boolp = (BooleanPointable) BooleanPointable.FACTORY.createPointable();
-        BytePointable bytep = (BytePointable) BytePointable.FACTORY.createPointable();
-        DoublePointable doublep = (DoublePointable) DoublePointable.FACTORY.createPointable();
-        FloatPointable floatp = (FloatPointable) FloatPointable.FACTORY.createPointable();
-        IntegerPointable intp = (IntegerPointable) IntegerPointable.FACTORY.createPointable();
-        LongPointable longp = (LongPointable) LongPointable.FACTORY.createPointable();
-        ShortPointable shortp = (ShortPointable) ShortPointable.FACTORY.createPointable();
-        UTF8StringPointable utf8sp = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
-        XSBinaryPointable binaryp = (XSBinaryPointable) XSBinaryPointable.FACTORY.createPointable();
-        XSDatePointable datep = (XSDatePointable) XSDatePointable.FACTORY.createPointable();
-        XSDateTimePointable datetimep = (XSDateTimePointable) XSDateTimePointable.FACTORY.createPointable();
-        XSDecimalPointable decp = (XSDecimalPointable) XSDecimalPointable.FACTORY.createPointable();
-        XSDurationPointable durationp = (XSDurationPointable) XSDurationPointable.FACTORY.createPointable();
-        XSTimePointable timep = (XSTimePointable) XSTimePointable.FACTORY.createPointable();
-        XSQNamePointable qnamep = (XSQNamePointable) XSQNamePointable.FACTORY.createPointable();
-    }
-
 }

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnContainsEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnContainsEvaluatorFactory.java?rev=1386877&r1=1386876&r2=1386877&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnContainsEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnContainsEvaluatorFactory.java Mon Sep 17 22:22:04 2012
@@ -16,12 +16,15 @@
  */
 package org.apache.vxquery.runtime.functions.strings;
 
+import org.apache.vxquery.datamodel.accessors.SequencePointable;
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
 import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.datamodel.values.XDMConstants;
 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;
@@ -45,6 +48,7 @@ public class FnContainsEvaluatorFactory 
         final UTF8StringPointable stringp3 = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
         final UTF8StringCharacterIterator charIterator1 = new UTF8StringCharacterIterator(stringp1);
         final UTF8StringCharacterIterator charIterator2 = new UTF8StringCharacterIterator(stringp2);
+        final SequencePointable seqp = (SequencePointable) SequencePointable.FACTORY.createPointable();
 
         return new AbstractTaggedValueArgumentScalarEvaluator(args) {
             @Override
@@ -58,21 +62,39 @@ public class FnContainsEvaluatorFactory 
                 TaggedValuePointable tvp2 = args[1];
 
                 // Only accept strings as input.
-                if (tvp1.getTag() != ValueTag.XS_STRING_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
+                if (tvp1.getTag() == ValueTag.SEQUENCE_TAG) {
+                    tvp1.getValue(seqp);
+                    if (seqp.getEntryCount() == 0) {
+                        XDMConstants.setEmptyString(stringp1);
+                    } else {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                } else {
+                    if (!FunctionHelper.isDerivedFromString(tvp1.getTag())) {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                    tvp1.getValue(stringp1);
                 }
-                if (tvp2.getTag() != ValueTag.XS_STRING_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
+                if (tvp2.getTag() == ValueTag.SEQUENCE_TAG) {
+                    tvp2.getValue(seqp);
+                    if (seqp.getEntryCount() == 0) {
+                        XDMConstants.setEmptyString(stringp2);
+                    } else {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                } else {
+                    if (!FunctionHelper.isDerivedFromString(tvp2.getTag())) {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                    tvp2.getValue(stringp2);
                 }
-                tvp1.getValue(stringp1);
-                tvp2.getValue(stringp2);
                 charIterator1.reset();
                 charIterator2.reset();
 
                 // Third parameter is optional.
                 if (args.length > 2) {
                     TaggedValuePointable tvp3 = args[2];
-                    if (tvp3.getTag() != ValueTag.XS_STRING_TAG) {
+                    if (!FunctionHelper.isDerivedFromString(tvp3.getTag())) {
                         throw new SystemException(ErrorCode.FORG0006);
                     }
                     tvp3.getValue(stringp3);

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnEndsWithEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnEndsWithEvaluatorFactory.java?rev=1386877&r1=1386876&r2=1386877&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnEndsWithEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnEndsWithEvaluatorFactory.java Mon Sep 17 22:22:04 2012
@@ -16,12 +16,15 @@
  */
 package org.apache.vxquery.runtime.functions.strings;
 
+import org.apache.vxquery.datamodel.accessors.SequencePointable;
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
 import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.datamodel.values.XDMConstants;
 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;
@@ -45,6 +48,8 @@ public class FnEndsWithEvaluatorFactory 
         final UTF8StringPointable stringp3 = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
         final ICharacterIterator charIterator1 = new UTF8StringCharacterIterator(stringp1);
         final ICharacterIterator charIterator2 = new UTF8StringCharacterIterator(stringp2);
+        final SequencePointable seqp = (SequencePointable) SequencePointable.FACTORY.createPointable();
+        final TaggedValuePointable tvp = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
 
         return new AbstractTaggedValueArgumentScalarEvaluator(args) {
             @Override
@@ -58,14 +63,34 @@ public class FnEndsWithEvaluatorFactory 
                 TaggedValuePointable tvp2 = args[1];
 
                 // Only accept strings as input.
-                if (tvp1.getTag() != ValueTag.XS_STRING_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
+                if (tvp1.getTag() == ValueTag.SEQUENCE_TAG) {
+                    tvp1.getValue(seqp);
+                    if (seqp.getEntryCount() == 0) {
+                        XDMConstants.setEmptyString(tvp);
+                        tvp.getValue(stringp1);
+                    } else {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                } else {
+                    if (!FunctionHelper.isDerivedFromString(tvp1.getTag())) {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                    tvp1.getValue(stringp1);
                 }
-                if (tvp2.getTag() != ValueTag.XS_STRING_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
+                if (tvp2.getTag() == ValueTag.SEQUENCE_TAG) {
+                    tvp2.getValue(seqp);
+                    if (seqp.getEntryCount() == 0) {
+                        XDMConstants.setEmptyString(tvp);
+                        tvp.getValue(stringp2);
+                    } else {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                } else {
+                    if (!FunctionHelper.isDerivedFromString(tvp2.getTag())) {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                    tvp2.getValue(stringp2);
                 }
-                tvp1.getValue(stringp1);
-                tvp2.getValue(stringp2);
                 int stringLength1 = stringp1.getStringLength();
                 int stringLength2 = stringp2.getStringLength();
                 charIterator1.reset();
@@ -74,7 +99,7 @@ public class FnEndsWithEvaluatorFactory 
                 // Third parameter is optional.
                 if (args.length > 2) {
                     TaggedValuePointable tvp3 = args[2];
-                    if (tvp3.getTag() != ValueTag.XS_STRING_TAG) {
+                    if (!FunctionHelper.isDerivedFromString(tvp3.getTag())) {
                         throw new SystemException(ErrorCode.FORG0006);
                     }
                     tvp3.getValue(stringp3);

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnLowerCaseEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnLowerCaseEvaluatorFactory.java?rev=1386877&r1=1386876&r2=1386877&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnLowerCaseEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnLowerCaseEvaluatorFactory.java Mon Sep 17 22:22:04 2012
@@ -16,10 +16,13 @@
  */
 package org.apache.vxquery.runtime.functions.strings;
 
+import org.apache.vxquery.datamodel.accessors.SequencePointable;
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
 import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.datamodel.values.XDMConstants;
 import org.apache.vxquery.exceptions.ErrorCode;
 import org.apache.vxquery.exceptions.SystemException;
+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;
@@ -39,18 +42,29 @@ public class FnLowerCaseEvaluatorFactory
             throws AlgebricksException {
         final UTF8StringPointable stringp = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
         final ICharacterIterator charIterator = new LowerCaseCharacterIterator(new UTF8StringCharacterIterator(stringp));
-        return new AbstractCharacterIteratorCopyingEvaluator(args, charIterator) {
+        final SequencePointable seqp = (SequencePointable) SequencePointable.FACTORY.createPointable();
+        final TaggedValuePointable tvp = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
 
+        return new AbstractCharacterIteratorCopyingEvaluator(args, charIterator) {
             @Override
             protected void preEvaluate(TaggedValuePointable[] args) throws SystemException {
                 TaggedValuePointable tvp1 = args[0];
 
                 // Only accept strings as input.
-                if (tvp1.getTag() != ValueTag.XS_STRING_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
+                if (tvp1.getTag() == ValueTag.SEQUENCE_TAG) {
+                    tvp1.getValue(seqp);
+                    if (seqp.getEntryCount() == 0) {
+                        XDMConstants.setEmptyString(tvp);
+                        tvp.getValue(stringp);
+                    } else {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                } else {
+                    if (!FunctionHelper.isDerivedFromString(tvp1.getTag())) {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                    tvp1.getValue(stringp);
                 }
-
-                tvp1.getValue(stringp);
             }
         };
     }

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnStartsWithEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnStartsWithEvaluatorFactory.java?rev=1386877&r1=1386876&r2=1386877&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnStartsWithEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnStartsWithEvaluatorFactory.java Mon Sep 17 22:22:04 2012
@@ -16,12 +16,15 @@
  */
 package org.apache.vxquery.runtime.functions.strings;
 
+import org.apache.vxquery.datamodel.accessors.SequencePointable;
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
 import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.datamodel.values.XDMConstants;
 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;
@@ -45,6 +48,8 @@ public class FnStartsWithEvaluatorFactor
         final UTF8StringPointable stringp3 = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
         final ICharacterIterator charIterator1 = new UTF8StringCharacterIterator(stringp1);
         final ICharacterIterator charIterator2 = new UTF8StringCharacterIterator(stringp2);
+        final SequencePointable seqp = (SequencePointable) SequencePointable.FACTORY.createPointable();
+        final TaggedValuePointable tvp = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
 
         return new AbstractTaggedValueArgumentScalarEvaluator(args) {
             @Override
@@ -58,21 +63,41 @@ public class FnStartsWithEvaluatorFactor
                 TaggedValuePointable tvp2 = args[1];
 
                 // Only accept strings as input.
-                if (tvp1.getTag() != ValueTag.XS_STRING_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
+                if (tvp1.getTag() == ValueTag.SEQUENCE_TAG) {
+                    tvp1.getValue(seqp);
+                    if (seqp.getEntryCount() == 0) {
+                        XDMConstants.setEmptyString(tvp);
+                        tvp.getValue(stringp1);
+                    } else {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                } else {
+                    if (!FunctionHelper.isDerivedFromString(tvp1.getTag())) {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                    tvp1.getValue(stringp1);
                 }
-                if (tvp2.getTag() != ValueTag.XS_STRING_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
+                if (tvp2.getTag() == ValueTag.SEQUENCE_TAG) {
+                    tvp2.getValue(seqp);
+                    if (seqp.getEntryCount() == 0) {
+                        XDMConstants.setEmptyString(tvp);
+                        tvp.getValue(stringp2);
+                    } else {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                } else {
+                    if (!FunctionHelper.isDerivedFromString(tvp2.getTag())) {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                    tvp2.getValue(stringp2);
                 }
-                tvp1.getValue(stringp1);
-                tvp2.getValue(stringp2);
                 charIterator1.reset();
                 charIterator2.reset();
 
                 // Third parameter is optional.
                 if (args.length > 2) {
                     TaggedValuePointable tvp3 = args[2];
-                    if (tvp3.getTag() != ValueTag.XS_STRING_TAG) {
+                    if (!FunctionHelper.isDerivedFromString(tvp3.getTag())) {
                         throw new SystemException(ErrorCode.FORG0006);
                     }
                     tvp3.getValue(stringp3);

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnStringJoinEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnStringJoinEvaluatorFactory.java?rev=1386877&r1=1386876&r2=1386877&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnStringJoinEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnStringJoinEvaluatorFactory.java Mon Sep 17 22:22:04 2012
@@ -26,6 +26,7 @@ import org.apache.vxquery.exceptions.Err
 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;
@@ -60,13 +61,26 @@ public class FnStringJoinEvaluatorFactor
                 TaggedValuePointable tvp2 = args[1];
 
                 // Only accept a sequence of strings and a string.
-                if (tvp1.getTag() != ValueTag.SEQUENCE_TAG) {
+                if (!FunctionHelper.isDerivedFromString(tvp2.getTag())) {
                     throw new SystemException(ErrorCode.FORG0006);
                 }
-                if (tvp2.getTag() != ValueTag.XS_STRING_TAG) {
+                if (FunctionHelper.isDerivedFromString(tvp1.getTag())) {
+                    try {
+                        // Return first parameter as a string.
+                        DataOutput out = abvs.getDataOutput();
+                        tvp1.getValue(stringp1);
+                        out.write(ValueTag.XS_STRING_TAG);
+                        out.write(stringp1.getByteArray(), stringp1.getStartOffset(), stringp1.getLength());
+                        result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
+                    } catch (IOException e) {
+                        throw new SystemException(ErrorCode.SYSE0001, e);
+                    }
+                    return;
+                } else if (tvp1.getTag() != ValueTag.SEQUENCE_TAG) {
                     throw new SystemException(ErrorCode.FORG0006);
                 }
 
+                // Operate on a sequence.
                 tvp1.getValue(seq);
                 tvp2.getValue(stringp2);
 
@@ -76,30 +90,32 @@ public class FnStringJoinEvaluatorFactor
                     out.write(ValueTag.XS_STRING_TAG);
 
                     // Default values for the length and update later
-                    out.write(0xFF);
-                    out.write(0xFF);
+                    out.write(0);
+                    out.write(0);
 
                     int seqLen = seq.getEntryCount();
-                    for (int j = 0; j < seqLen; ++j) {
-                        // Add separator if more than one value.
-                        if (j > 0) {
-                            out.write(stringp2.getByteArray(), stringp2.getStartOffset() + 2, stringp2.getUTFLength());
-                        }
-                        // Get string from sequence.
-                        seq.getEntry(j, tvp);
-                        if (tvp.getTag() != ValueTag.XS_STRING_TAG) {
-                            throw new SystemException(ErrorCode.FORG0006);
+                    if (seqLen != 0) {
+                        for (int j = 0; j < seqLen; ++j) {
+                            // Add separator if more than one value.
+                            if (j > 0) {
+                                out.write(stringp2.getByteArray(), stringp2.getStartOffset() + 2,
+                                        stringp2.getUTFLength());
+                            }
+                            // Get string from sequence.
+                            seq.getEntry(j, tvp);
+                            if (!FunctionHelper.isDerivedFromString(tvp.getTag())) {
+                                throw new SystemException(ErrorCode.FORG0006);
+                            }
+                            tvp.getValue(stringp1);
+                            out.write(stringp1.getByteArray(), stringp1.getStartOffset() + 2, stringp1.getUTFLength());
                         }
-                        tvp.getValue(stringp1);
-                        out.write(stringp1.getByteArray(), stringp1.getStartOffset() + 2, stringp1.getUTFLength());
-                    }
 
-                    // Update the full length string in the byte array.
-                    byte[] stringResult = abvs.getByteArray();
-                    stringResult[1] = (byte) (((abvs.getLength() - 3) >>> 8) & 0xFF);
-                    stringResult[2] = (byte) (((abvs.getLength() - 3) >>> 0) & 0xFF);
+                        // Update the full length string in the byte array.
+                        abvs.getByteArray()[1] = (byte) (((abvs.getLength() - 3) >>> 8) & 0xFF);
+                        abvs.getByteArray()[2] = (byte) (((abvs.getLength() - 3) >>> 0) & 0xFF);
+                    }
 
-                    result.set(stringResult, 0, abvs.getLength());
+                    result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
                 } catch (IOException e) {
                     throw new SystemException(ErrorCode.SYSE0001, e);
                 }

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnStringLengthEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnStringLengthEvaluatorFactory.java?rev=1386877&r1=1386876&r2=1386877&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnStringLengthEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnStringLengthEvaluatorFactory.java Mon Sep 17 22:22:04 2012
@@ -18,12 +18,15 @@ package org.apache.vxquery.runtime.funct
 
 import java.io.DataOutput;
 
+import org.apache.vxquery.datamodel.accessors.SequencePointable;
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
 import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.datamodel.values.XDMConstants;
 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;
@@ -46,6 +49,8 @@ public class FnStringLengthEvaluatorFact
         final UTF8StringPointable stringp = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
         final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
         final DataOutput dOut = abvs.getDataOutput();
+        final SequencePointable seqp = (SequencePointable) SequencePointable.FACTORY.createPointable();
+        final TaggedValuePointable tvp = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
 
         return new AbstractTaggedValueArgumentScalarEvaluator(args) {
             @Override
@@ -53,12 +58,22 @@ public class FnStringLengthEvaluatorFact
                 TaggedValuePointable tvp1 = args[0];
 
                 // Only accept strings as input.
-                if (tvp1.getTag() != ValueTag.XS_STRING_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
+                if (tvp1.getTag() == ValueTag.SEQUENCE_TAG) {
+                    tvp1.getValue(seqp);
+                    if (seqp.getEntryCount() == 0) {
+                        XDMConstants.setEmptyString(tvp);
+                        tvp.getValue(stringp);
+                    } else {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                } else {
+                    if (!FunctionHelper.isDerivedFromString(tvp1.getTag())) {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                    tvp1.getValue(stringp);
                 }
 
                 // Return the string length of the UTF8 String.
-                tvp1.getValue(stringp);
                 try {
                     abvs.reset();
                     dOut.write(ValueTag.XS_INTEGER_TAG);

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnStringScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnStringScalarEvaluatorFactory.java?rev=1386877&r1=1386876&r2=1386877&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnStringScalarEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnStringScalarEvaluatorFactory.java Mon Sep 17 22:22:04 2012
@@ -20,33 +20,20 @@ import java.io.DataOutput;
 import java.io.IOException;
 
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
-import org.apache.vxquery.datamodel.accessors.atomic.XSBinaryPointable;
-import org.apache.vxquery.datamodel.accessors.atomic.XSDatePointable;
-import org.apache.vxquery.datamodel.accessors.atomic.XSDateTimePointable;
-import org.apache.vxquery.datamodel.accessors.atomic.XSDecimalPointable;
-import org.apache.vxquery.datamodel.accessors.atomic.XSDurationPointable;
-import org.apache.vxquery.datamodel.accessors.atomic.XSQNamePointable;
-import org.apache.vxquery.datamodel.accessors.atomic.XSTimePointable;
 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.AbstractTaggedValueArgumentScalarEvaluator;
 import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
 import org.apache.vxquery.runtime.functions.cast.CastToStringOperation;
+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.BooleanPointable;
-import edu.uci.ics.hyracks.data.std.primitive.BytePointable;
-import edu.uci.ics.hyracks.data.std.primitive.DoublePointable;
-import edu.uci.ics.hyracks.data.std.primitive.FloatPointable;
-import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
-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.util.ArrayBackedValueStorage;
 
 public class FnStringScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
@@ -62,7 +49,7 @@ public class FnStringScalarEvaluatorFact
         final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
         final DataOutput dOut = abvs.getDataOutput();
         final CastToStringOperation castToString = new CastToStringOperation();
-        final TypedPointables tp = new TypedPointables();
+        final FunctionHelper.TypedPointables tp = new FunctionHelper.TypedPointables();
 
         return new AbstractTaggedValueArgumentScalarEvaluator(args) {
             @Override
@@ -76,6 +63,15 @@ public class FnStringScalarEvaluatorFact
                             castToString.convertAnyURI(tp.utf8sp, dOut);
                             break;
                         case ValueTag.XS_STRING_TAG:
+                        case ValueTag.XS_NORMALIZED_STRING_TAG:
+                        case ValueTag.XS_TOKEN_TAG:
+                        case ValueTag.XS_LANGUAGE_TAG:
+                        case ValueTag.XS_NMTOKEN_TAG:
+                        case ValueTag.XS_NAME_TAG:
+                        case ValueTag.XS_NCNAME_TAG:
+                        case ValueTag.XS_ID_TAG:
+                        case ValueTag.XS_IDREF_TAG:
+                        case ValueTag.XS_ENTITY_TAG:
                             tvp1.getValue(tp.utf8sp);
                             castToString.convertString(tp.utf8sp, dOut);
                             break;
@@ -180,6 +176,13 @@ public class FnStringScalarEvaluatorFact
                             tvp1.getValue(tp.bytep);
                             castToString.convertByte(tp.bytep, dOut);
                             break;
+                        case ValueTag.SEQUENCE_TAG:
+                            tvp1.getValue(tp.seqp);
+                            if (tp.seqp.getEntryCount() == 0) {
+                                XDMConstants.setEmptyString(result);
+                                return;
+                            }
+                            // Pass through if not empty sequence.
                         default:
                             throw new SystemException(ErrorCode.XPDY0002);
                     }
@@ -192,22 +195,4 @@ public class FnStringScalarEvaluatorFact
 
         };
     }
-
-    private static class TypedPointables {
-        BooleanPointable boolp = (BooleanPointable) BooleanPointable.FACTORY.createPointable();
-        BytePointable bytep = (BytePointable) BytePointable.FACTORY.createPointable();
-        DoublePointable doublep = (DoublePointable) DoublePointable.FACTORY.createPointable();
-        FloatPointable floatp = (FloatPointable) FloatPointable.FACTORY.createPointable();
-        IntegerPointable intp = (IntegerPointable) IntegerPointable.FACTORY.createPointable();
-        LongPointable longp = (LongPointable) LongPointable.FACTORY.createPointable();
-        ShortPointable shortp = (ShortPointable) ShortPointable.FACTORY.createPointable();
-        UTF8StringPointable utf8sp = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
-        XSBinaryPointable binaryp = (XSBinaryPointable) XSBinaryPointable.FACTORY.createPointable();
-        XSDatePointable datep = (XSDatePointable) XSDatePointable.FACTORY.createPointable();
-        XSDateTimePointable datetimep = (XSDateTimePointable) XSDateTimePointable.FACTORY.createPointable();
-        XSDecimalPointable decp = (XSDecimalPointable) XSDecimalPointable.FACTORY.createPointable();
-        XSDurationPointable durationp = (XSDurationPointable) XSDurationPointable.FACTORY.createPointable();
-        XSTimePointable timep = (XSTimePointable) XSTimePointable.FACTORY.createPointable();
-        XSQNamePointable qnamep = (XSQNamePointable) XSQNamePointable.FACTORY.createPointable();
-    }
 }

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnSubstringAfterEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnSubstringAfterEvaluatorFactory.java?rev=1386877&r1=1386876&r2=1386877&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnSubstringAfterEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnSubstringAfterEvaluatorFactory.java Mon Sep 17 22:22:04 2012
@@ -16,10 +16,13 @@
  */
 package org.apache.vxquery.runtime.functions.strings;
 
+import org.apache.vxquery.datamodel.accessors.SequencePointable;
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
 import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.datamodel.values.XDMConstants;
 import org.apache.vxquery.exceptions.ErrorCode;
 import org.apache.vxquery.exceptions.SystemException;
+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;
@@ -43,6 +46,8 @@ public class FnSubstringAfterEvaluatorFa
         final SubstringAfterCharacterIterator stringIterator = new SubstringAfterCharacterIterator(
                 new UTF8StringCharacterIterator(stringp1));
         final UTF8StringCharacterIterator searchIterator = new UTF8StringCharacterIterator(stringp2);
+        final SequencePointable seqp = (SequencePointable) SequencePointable.FACTORY.createPointable();
+        final TaggedValuePointable tvp = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
 
         return new AbstractCharacterIteratorCopyingEvaluator(args, stringIterator) {
             @Override
@@ -51,21 +56,41 @@ public class FnSubstringAfterEvaluatorFa
                 TaggedValuePointable tvp1 = args[0];
                 TaggedValuePointable tvp2 = args[1];
 
-                if (tvp1.getTag() != ValueTag.XS_STRING_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
+                if (tvp1.getTag() == ValueTag.SEQUENCE_TAG) {
+                    tvp1.getValue(seqp);
+                    if (seqp.getEntryCount() == 0) {
+                        XDMConstants.setEmptyString(tvp);
+                        tvp.getValue(stringp1);
+                    } else {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                } else {
+                    if (!FunctionHelper.isDerivedFromString(tvp1.getTag())) {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                    tvp1.getValue(stringp1);
                 }
-                if (tvp2.getTag() != ValueTag.XS_STRING_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
+                if (tvp2.getTag() == ValueTag.SEQUENCE_TAG) {
+                    tvp2.getValue(seqp);
+                    if (seqp.getEntryCount() == 0) {
+                        XDMConstants.setEmptyString(tvp);
+                        tvp.getValue(stringp2);
+                    } else {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                } else {
+                    if (!FunctionHelper.isDerivedFromString(tvp2.getTag())) {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                    tvp2.getValue(stringp2);
                 }
-                tvp1.getValue(stringp1);
-                tvp2.getValue(stringp2);
                 stringIterator.reset();
                 searchIterator.reset();
 
                 // Third parameter is optional.
                 if (args.length > 2) {
                     TaggedValuePointable tvp3 = args[2];
-                    if (tvp3.getTag() != ValueTag.XS_STRING_TAG) {
+                    if (!FunctionHelper.isDerivedFromString(tvp3.getTag())) {
                         throw new SystemException(ErrorCode.FORG0006);
                     }
                     tvp3.getValue(stringp3);

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnSubstringBeforeEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnSubstringBeforeEvaluatorFactory.java?rev=1386877&r1=1386876&r2=1386877&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnSubstringBeforeEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnSubstringBeforeEvaluatorFactory.java Mon Sep 17 22:22:04 2012
@@ -16,10 +16,13 @@
  */
 package org.apache.vxquery.runtime.functions.strings;
 
+import org.apache.vxquery.datamodel.accessors.SequencePointable;
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
 import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.datamodel.values.XDMConstants;
 import org.apache.vxquery.exceptions.ErrorCode;
 import org.apache.vxquery.exceptions.SystemException;
+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;
@@ -43,29 +46,51 @@ public class FnSubstringBeforeEvaluatorF
         final SubstringBeforeCharacterIterator stringIterator = new SubstringBeforeCharacterIterator(
                 new UTF8StringCharacterIterator(stringp1));
         final UTF8StringCharacterIterator searchIterator = new UTF8StringCharacterIterator(stringp2);
+        final SequencePointable seqp = (SequencePointable) SequencePointable.FACTORY.createPointable();
+        final TaggedValuePointable tvp = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
 
         return new AbstractCharacterIteratorCopyingEvaluator(args, stringIterator) {
             @Override
             protected void preEvaluate(TaggedValuePointable[] args) throws SystemException {
-                // Only accept strings as input.
                 TaggedValuePointable tvp1 = args[0];
                 TaggedValuePointable tvp2 = args[1];
 
-                if (tvp1.getTag() != ValueTag.XS_STRING_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
+                // Only accept strings or empty sequence as input.
+                if (tvp1.getTag() == ValueTag.SEQUENCE_TAG) {
+                    tvp1.getValue(seqp);
+                    if (seqp.getEntryCount() == 0) {
+                        XDMConstants.setEmptyString(tvp);
+                        tvp.getValue(stringp1);
+                    } else {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                } else {
+                    if (!FunctionHelper.isDerivedFromString(tvp1.getTag())) {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                    tvp1.getValue(stringp1);
                 }
-                if (tvp2.getTag() != ValueTag.XS_STRING_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
+                if (tvp2.getTag() == ValueTag.SEQUENCE_TAG) {
+                    tvp2.getValue(seqp);
+                    if (seqp.getEntryCount() == 0) {
+                        XDMConstants.setEmptyString(tvp);
+                        tvp.getValue(stringp2);
+                    } else {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                } else {
+                    if (!FunctionHelper.isDerivedFromString(tvp2.getTag())) {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                    tvp2.getValue(stringp2);
                 }
-                tvp1.getValue(stringp1);
-                tvp2.getValue(stringp2);
                 stringIterator.reset();
                 searchIterator.reset();
 
                 // Third parameter is optional.
                 if (args.length > 2) {
                     TaggedValuePointable tvp3 = args[2];
-                    if (tvp3.getTag() != ValueTag.XS_STRING_TAG) {
+                    if (!FunctionHelper.isDerivedFromString(tvp3.getTag())) {
                         throw new SystemException(ErrorCode.FORG0006);
                     }
                     tvp3.getValue(stringp3);

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnSubstringEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnSubstringEvaluatorFactory.java?rev=1386877&r1=1386876&r2=1386877&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnSubstringEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnSubstringEvaluatorFactory.java Mon Sep 17 22:22:04 2012
@@ -16,10 +16,13 @@
  */
 package org.apache.vxquery.runtime.functions.strings;
 
+import org.apache.vxquery.datamodel.accessors.SequencePointable;
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
 import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.datamodel.values.XDMConstants;
 import org.apache.vxquery.exceptions.ErrorCode;
 import org.apache.vxquery.exceptions.SystemException;
+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;
@@ -61,6 +64,8 @@ public class FnSubstringEvaluatorFactory
         final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
         final SubstringCharacterIterator charIterator = new SubstringCharacterIterator(new UTF8StringCharacterIterator(
                 stringp));
+        final SequencePointable seqp = (SequencePointable) SequencePointable.FACTORY.createPointable();
+        final TaggedValuePointable tvp = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
 
         return new AbstractCharacterIteratorCopyingEvaluator(args, charIterator) {
             @Override
@@ -72,10 +77,20 @@ public class FnSubstringEvaluatorFactory
 
                 // Only accept string, double, and optional double as input.
                 TaggedValuePointable tvp1 = args[0];
-                if (tvp1.getTag() != ValueTag.XS_STRING_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
+                if (tvp1.getTag() == ValueTag.SEQUENCE_TAG) {
+                    tvp1.getValue(seqp);
+                    if (seqp.getEntryCount() == 0) {
+                        XDMConstants.setEmptyString(tvp);
+                        tvp.getValue(stringp);
+                    } else {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                } else {
+                    if (!FunctionHelper.isDerivedFromString(tvp1.getTag())) {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                    tvp1.getValue(stringp);
                 }
-                tvp1.getValue(stringp);
 
                 // TODO Check specification to see if only double? If so change passing function.
                 startingLocation = getIntParameter(args[1], doublep, longp);

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnUpperCaseEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnUpperCaseEvaluatorFactory.java?rev=1386877&r1=1386876&r2=1386877&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnUpperCaseEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnUpperCaseEvaluatorFactory.java Mon Sep 17 22:22:04 2012
@@ -16,10 +16,13 @@
  */
 package org.apache.vxquery.runtime.functions.strings;
 
+import org.apache.vxquery.datamodel.accessors.SequencePointable;
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
 import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.datamodel.values.XDMConstants;
 import org.apache.vxquery.exceptions.ErrorCode;
 import org.apache.vxquery.exceptions.SystemException;
+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;
@@ -39,18 +42,29 @@ public class FnUpperCaseEvaluatorFactory
             throws AlgebricksException {
         final UTF8StringPointable stringp = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
         final ICharacterIterator charIterator = new UpperCaseCharacterIterator(new UTF8StringCharacterIterator(stringp));
-        return new AbstractCharacterIteratorCopyingEvaluator(args, charIterator) {
+        final SequencePointable seqp = (SequencePointable) SequencePointable.FACTORY.createPointable();
+        final TaggedValuePointable tvp = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
 
+        return new AbstractCharacterIteratorCopyingEvaluator(args, charIterator) {
             @Override
             protected void preEvaluate(TaggedValuePointable[] args) throws SystemException {
                 TaggedValuePointable tvp1 = args[0];
 
                 // Only accept strings as input.
-                if (tvp1.getTag() != ValueTag.XS_STRING_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
+                if (tvp1.getTag() == ValueTag.SEQUENCE_TAG) {
+                    tvp1.getValue(seqp);
+                    if (seqp.getEntryCount() == 0) {
+                        XDMConstants.setEmptyString(tvp);
+                        tvp.getValue(stringp);
+                    } else {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                } else {
+                    if (!FunctionHelper.isDerivedFromString(tvp1.getTag())) {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                    tvp1.getValue(stringp);
                 }
-
-                tvp1.getValue(stringp);
             }
         };
     }



Mime
View raw message