asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jianf...@apache.org
Subject [05/15] incubator-asterixdb git commit: ASTERIXDB-1102: VarSize Encoding to store length of String and ByteArray
Date Thu, 29 Oct 2015 04:44:56 GMT
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/common/EditDistanceEvaluator.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/common/EditDistanceEvaluator.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/common/EditDistanceEvaluator.java
index 881e01a..2f588c7 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/common/EditDistanceEvaluator.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/common/EditDistanceEvaluator.java
@@ -79,14 +79,6 @@ public class EditDistanceEvaluator implements ICopyEvaluator {
         if (!checkArgTypes(firstTypeTag, secondTypeTag))
             return;
 
-        itemTypeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut.getByteArray()[firstStart + 1]);
-        if (itemTypeTag == ATypeTag.ANY)
-            throw new AlgebricksException("\n Edit Distance can only be called on homogenous lists");
-
-        itemTypeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut.getByteArray()[secondStart + 1]);
-        if (itemTypeTag == ATypeTag.ANY)
-            throw new AlgebricksException("\n Edit Distance can only be called on homogenous lists");
-
         try {
             editDistance = computeResult(argOut.getByteArray(), firstStart, secondStart, firstTypeTag);
         } catch (HyracksDataException e1) {
@@ -155,6 +147,22 @@ public class EditDistanceEvaluator implements ICopyEvaluator {
                     + typeTag2);
         }
 
+        // Since they are equal, check one tag is enough.
+        if (typeTag1 != ATypeTag.STRING && typeTag1 != ATypeTag.ORDEREDLIST) { // could be an list
+            throw new AlgebricksException(
+                    "Only String or OrderedList type are allowed in edit distance, but given : " + typeTag1);
+        }
+
+        if (typeTag1 == ATypeTag.ORDEREDLIST) {
+            itemTypeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut.getByteArray()[firstStart + 1]);
+            if (itemTypeTag == ATypeTag.ANY)
+                throw new AlgebricksException("\n Edit Distance can only be called on homogenous lists");
+
+            itemTypeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut.getByteArray()[secondStart + 1]);
+            if (itemTypeTag == ATypeTag.ANY)
+                throw new AlgebricksException("\n Edit Distance can only be called on homogenous lists");
+        }
+
         return true;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/common/SimilarityFiltersCache.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/common/SimilarityFiltersCache.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/common/SimilarityFiltersCache.java
index 663bca9..7180df0 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/common/SimilarityFiltersCache.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/common/SimilarityFiltersCache.java
@@ -30,6 +30,7 @@ import org.apache.hyracks.dataflow.common.comm.util.ByteBufferInputStream;
 import org.apache.hyracks.dataflow.common.data.marshalling.UTF8StringSerializerDeserializer;
 
 public class SimilarityFiltersCache {
+    private final UTF8StringSerializerDeserializer utf8SerDer = new UTF8StringSerializerDeserializer();
 
     private final ByteBufferInputStream bbis = new ByteBufferInputStream();
     private final DataInputStream dis = new DataInputStream(bbis);
@@ -44,7 +45,7 @@ public class SimilarityFiltersCache {
             bbis.setByteBuffer(ByteBuffer.wrap(similarityNameBytes), 1);
             String similarityName;
             try {
-                similarityName = UTF8StringSerializerDeserializer.INSTANCE.deserialize(dis);
+                similarityName = utf8SerDer.deserialize(dis);
             } catch (HyracksDataException e) {
                 throw new AlgebricksException(e);
             }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ABinaryHexStringConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ABinaryHexStringConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ABinaryHexStringConstructorDescriptor.java
index 4304e97..ef54caf 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ABinaryHexStringConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ABinaryHexStringConstructorDescriptor.java
@@ -19,6 +19,9 @@
 
 package org.apache.asterix.runtime.evaluators.constructors;
 
+import java.io.DataOutput;
+import java.io.IOException;
+
 import org.apache.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import org.apache.asterix.om.base.ANull;
 import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
@@ -33,15 +36,13 @@ import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 import org.apache.hyracks.dataflow.common.data.parsers.ByteArrayHexParserFactory;
 import org.apache.hyracks.dataflow.common.data.parsers.IValueParser;
 import org.apache.hyracks.dataflow.common.data.parsers.IValueParserFactory;
 
-import java.io.DataOutput;
-import java.io.IOException;
-
 public class ABinaryHexStringConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
     private static final long serialVersionUID = 1L;
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
@@ -50,17 +51,20 @@ public class ABinaryHexStringConstructorDescriptor extends AbstractScalarFunctio
         }
     };
 
-    @Override public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args)
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args)
             throws AlgebricksException {
         return new ICopyEvaluatorFactory() {
-            @Override public ICopyEvaluator createEvaluator(final IDataOutputProvider output)
+            @Override
+            public ICopyEvaluator createEvaluator(final IDataOutputProvider output)
                     throws AlgebricksException {
                 return new ABinaryConstructorEvaluator(output, args[0], ByteArrayHexParserFactory.INSTANCE);
             }
         };
     }
 
-    @Override public FunctionIdentifier getIdentifier() {
+    @Override
+    public FunctionIdentifier getIdentifier() {
         return AsterixBuiltinFunctions.BINARY_HEX_CONSTRUCTOR;
     }
 
@@ -69,6 +73,7 @@ public class ABinaryHexStringConstructorDescriptor extends AbstractScalarFunctio
         private ArrayBackedValueStorage outInput;
         private ICopyEvaluator eval;
         private IValueParser byteArrayParser;
+        private UTF8StringPointable utf8Ptr = new UTF8StringPointable();
 
         @SuppressWarnings("unchecked")
         private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
@@ -83,7 +88,8 @@ public class ABinaryHexStringConstructorDescriptor extends AbstractScalarFunctio
             byteArrayParser = valueParserFactory.createValueParser();
         }
 
-        @Override public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+        @Override
+        public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
 
             try {
                 outInput.reset();
@@ -96,9 +102,9 @@ public class ABinaryHexStringConstructorDescriptor extends AbstractScalarFunctio
                 } else if (tt == ATypeTag.BINARY) {
                     out.write(outInput.getByteArray(), outInput.getStartOffset(), outInput.getLength());
                 } else if (tt == ATypeTag.STRING) {
-                    String string = new String(outInput.getByteArray(), 3, outInput.getLength() - 3,
-                            "UTF-8");
-                    char[] buffer = string.toCharArray();
+                    utf8Ptr.set(outInput.getByteArray(), 1, outInput.getLength() - 1);
+
+                    char[] buffer = utf8Ptr.toString().toCharArray();
                     out.write(ATypeTag.BINARY.serialize());
                     byteArrayParser.parse(buffer, 0, buffer.length, out);
                 } else {

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ABooleanConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ABooleanConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ABooleanConstructorDescriptor.java
index 8ea464d..d865e3e 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ABooleanConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ABooleanConstructorDescriptor.java
@@ -40,6 +40,7 @@ import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+import org.apache.hyracks.util.string.UTF8StringUtil;
 
 public class ABooleanConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
@@ -65,8 +66,8 @@ public class ABooleanConstructorDescriptor extends AbstractScalarFunctionDynamic
                     private ArrayBackedValueStorage outInput = new ArrayBackedValueStorage();
                     private ICopyEvaluator eval = args[0].createEvaluator(outInput);
                     private String errorMessage = "This can not be an instance of boolean";
-                    private final byte[] TRUE = { 0, 4, 't', 'r', 'u', 'e' };
-                    private final byte[] FALSE = { 0, 5, 'f', 'a', 'l', 's', 'e' };
+                    private final byte[] TRUE = UTF8StringUtil.writeStringToBytes("true");
+                    private final byte[] FALSE = UTF8StringUtil.writeStringToBytes("false");
                     IBinaryComparator utf8BinaryComparator = AqlBinaryComparatorFactoryProvider.UTF8STRING_POINTABLE_INSTANCE
                             .createBinaryComparator();
                     @SuppressWarnings("unchecked")
@@ -84,11 +85,12 @@ public class ABooleanConstructorDescriptor extends AbstractScalarFunctionDynamic
                             eval.evaluate(tuple);
                             byte[] serString = outInput.getByteArray();
                             if (serString[0] == SER_STRING_TYPE_TAG) {
-                                if (utf8BinaryComparator.compare(serString, 1, outInput.getLength(), TRUE, 0, 6) == 0) {
+                                if (utf8BinaryComparator
+                                        .compare(serString, 1, outInput.getLength(), TRUE, 0, TRUE.length) == 0) {
                                     booleanSerde.serialize(ABoolean.TRUE, out);
                                     return;
                                 } else if (utf8BinaryComparator
-                                        .compare(serString, 1, outInput.getLength(), FALSE, 0, 7) == 0) {
+                                        .compare(serString, 1, outInput.getLength(), FALSE, 0, FALSE.length) == 0) {
                                     booleanSerde.serialize(ABoolean.FALSE, out);
                                     return;
                                 } else

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ACircleConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ACircleConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ACircleConstructorDescriptor.java
index ff4c792..e4a33f5 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ACircleConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ACircleConstructorDescriptor.java
@@ -38,6 +38,7 @@ import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -75,6 +76,8 @@ public class ACircleConstructorDescriptor extends AbstractScalarFunctionDynamicD
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
 
+                    private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
+
                     @Override
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
 
@@ -83,7 +86,8 @@ public class ACircleConstructorDescriptor extends AbstractScalarFunctionDynamicD
                             eval.evaluate(tuple);
                             byte[] serString = outInput.getByteArray();
                             if (serString[0] == SER_STRING_TYPE_TAG) {
-                                String s = new String(serString, 3, outInput.getLength() - 3, "UTF-8");
+                                utf8Ptr.set(serString, 1, outInput.getLength()-1);
+                                String s = utf8Ptr.toString();
                                 int commaIndex = s.indexOf(',');
                                 int spaceIndex = s.indexOf(' ', commaIndex + 1);
                                 aPoint.setValue(Double.parseDouble(s.substring(0, commaIndex)),

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADateConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADateConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADateConstructorDescriptor.java
index 41fa315..a73dec6 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADateConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADateConstructorDescriptor.java
@@ -39,6 +39,7 @@ import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -76,6 +77,8 @@ public class ADateConstructorDescriptor extends AbstractScalarFunctionDynamicDes
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
 
+                    private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
+
                     @Override
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
 
@@ -85,7 +88,8 @@ public class ADateConstructorDescriptor extends AbstractScalarFunctionDynamicDes
                             byte[] serString = outInput.getByteArray();
                             if (serString[0] == SER_STRING_TYPE_TAG) {
 
-                                int stringLength = (serString[1] & 0xff << 8) + (serString[2] & 0xff << 0);
+                                utf8Ptr.set(serString, 1, outInput.getLength()-1);
+                                int stringLength = utf8Ptr.getUTF8Length();
 
                                 // the string to be parsed should be at least 8 characters: YYYYMMDD
                                 if (stringLength < 8) {
@@ -94,11 +98,11 @@ public class ADateConstructorDescriptor extends AbstractScalarFunctionDynamicDes
                                             + stringLength);
                                 }
 
-                                int startOffset = 3;
+                                int startOffset = utf8Ptr.getCharStartOffset();
                                 while (serString[startOffset] == ' ') {
                                     startOffset++;
                                 }
-                                int endOffset = stringLength - 1 + 3;
+                                int endOffset = startOffset + stringLength - 1 ;
                                 while (serString[endOffset] == ' ') {
                                     endOffset--;
                                 }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADateTimeConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADateTimeConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADateTimeConstructorDescriptor.java
index fc01831..0775e80 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADateTimeConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADateTimeConstructorDescriptor.java
@@ -39,6 +39,7 @@ import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -75,6 +76,7 @@ public class ADateTimeConstructorDescriptor extends AbstractScalarFunctionDynami
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
+                    private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
 
                     @Override
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
@@ -85,7 +87,9 @@ public class ADateTimeConstructorDescriptor extends AbstractScalarFunctionDynami
                             byte[] serString = outInput.getByteArray();
                             if (serString[0] == SER_STRING_TYPE_TAG) {
 
-                                int stringLength = (serString[1] & 0xff << 8) + (serString[2] & 0xff << 0);
+                                utf8Ptr.set(serString, 1, outInput.getLength() - 1);
+                                int stringLength = utf8Ptr.getUTF8Length();
+                                int startOffset = utf8Ptr.getCharStartOffset();
                                 // the string to be parsed should be at least 14 characters: YYYYMMDDhhmmss
                                 if (stringLength < 14) {
                                     throw new AlgebricksException(errorMessage
@@ -93,21 +97,23 @@ public class ADateTimeConstructorDescriptor extends AbstractScalarFunctionDynami
                                             + stringLength);
                                 }
                                 // +1 if it is negative (-)
-                                short timeOffset = (short) ((serString[3] == '-') ? 1 : 0);
+                                short timeOffset = (short) ((serString[startOffset] == '-') ? 1 : 0);
 
                                 timeOffset += 8;
 
-                                if (serString[3 + timeOffset] != 'T') {
+                                if (serString[startOffset + timeOffset] != 'T') {
                                     timeOffset += 2;
-                                    if (serString[3 + timeOffset] != 'T') {
+                                    if (serString[startOffset + timeOffset] != 'T') {
                                         throw new AlgebricksException(errorMessage + ": missing T");
                                     }
                                 }
 
-                                long chrononTimeInMs = ADateParserFactory.parseDatePart(serString, 3, timeOffset);
+                                long chrononTimeInMs = ADateParserFactory
+                                        .parseDatePart(serString, startOffset, timeOffset);
 
-                                chrononTimeInMs += ATimeParserFactory.parseTimePart(serString, 3 + timeOffset + 1,
-                                        stringLength - timeOffset - 1);
+                                chrononTimeInMs += ATimeParserFactory
+                                        .parseTimePart(serString, startOffset + timeOffset + 1,
+                                                stringLength - timeOffset - 1);
 
                                 aDateTime.setValue(chrononTimeInMs);
                                 datetimeSerde.serialize(aDateTime, out);

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADayTimeDurationConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADayTimeDurationConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADayTimeDurationConstructorDescriptor.java
index 916c5f3..67cd3d5 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADayTimeDurationConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADayTimeDurationConstructorDescriptor.java
@@ -38,6 +38,7 @@ import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -76,6 +77,7 @@ public class ADayTimeDurationConstructorDescriptor extends AbstractScalarFunctio
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
+                    private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
 
                     @Override
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
@@ -86,9 +88,11 @@ public class ADayTimeDurationConstructorDescriptor extends AbstractScalarFunctio
 
                             if (serString[0] == SER_STRING_TYPE_TAG) {
 
-                                int stringLength = (serString[1] & 0xff << 8) + (serString[2] & 0xff << 0);
+                                utf8Ptr.set(serString, 1, outInput.getLength() -1);
+                                int stringLength = utf8Ptr.getUTF8Length();
+                                int startOffset = utf8Ptr.getCharStartOffset();
 
-                                ADurationParserFactory.parseDuration(serString, 3, stringLength, aDayTimeDuration,
+                                ADurationParserFactory.parseDuration(serString, startOffset, stringLength, aDayTimeDuration,
                                         ADurationParseOption.DAY_TIME);
 
                                 dayTimeDurationSerde.serialize(aDayTimeDuration, out);

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADoubleConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADoubleConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADoubleConstructorDescriptor.java
index 39b7a16..2ad883a 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADoubleConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADoubleConstructorDescriptor.java
@@ -39,8 +39,10 @@ import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import org.apache.hyracks.api.dataflow.value.IBinaryComparator;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+import org.apache.hyracks.util.string.UTF8StringUtil;
 
 public class ADoubleConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
@@ -67,9 +69,9 @@ public class ADoubleConstructorDescriptor extends AbstractScalarFunctionDynamicD
                     private ArrayBackedValueStorage outInput = new ArrayBackedValueStorage();
                     private ICopyEvaluator eval = args[0].createEvaluator(outInput);
                     private String errorMessage = "This can not be an instance of double";
-                    private final byte[] POSITIVE_INF = { 0, 3, 'I', 'N', 'F' };
-                    private final byte[] NEGATIVE_INF = { 0, 4, '-', 'I', 'N', 'F' };
-                    private final byte[] NAN = { 0, 3, 'N', 'a', 'N' };
+                    private final byte[] POSITIVE_INF = UTF8StringUtil.writeStringToBytes("INF");
+                    private final byte[] NEGATIVE_INF = UTF8StringUtil.writeStringToBytes("-INF");
+                    private final byte[] NAN = UTF8StringUtil.writeStringToBytes("NaN");
                     // private int offset = 3, value = 0, integerPart = 0,
                     // fractionPart = 0, exponentPart = 0,
                     // pointIndex = 0, eIndex = 1;
@@ -87,6 +89,8 @@ public class ADoubleConstructorDescriptor extends AbstractScalarFunctionDynamicD
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
 
+                    private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
+
                     @Override
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
 
@@ -102,12 +106,14 @@ public class ADoubleConstructorDescriptor extends AbstractScalarFunctionDynamicD
                                 } else if (utf8BinaryComparator.compare(serString, 1, outInput.getLength(),
                                         NEGATIVE_INF, 0, 6) == 0) {
                                     aDouble.setValue(Double.NEGATIVE_INFINITY);
-                                } else if (utf8BinaryComparator.compare(serString, 1, outInput.getLength(), NAN, 0, 5) == 0) {
+                                } else if (utf8BinaryComparator.compare(serString, 1, outInput.getLength(), NAN, 0, 5)
+                                        == 0) {
                                     aDouble.setValue(Double.NaN);
-                                } else
+                                } else {
                                     // out.writeDouble(parseDouble(serString));
-                                    aDouble.setValue(Double.parseDouble(new String(serString, 3,
-                                            outInput.getLength() - 3, "UTF-8")));
+                                    utf8Ptr.set(serString, 1, outInput.getLength() - 1);
+                                    aDouble.setValue(Double.parseDouble(utf8Ptr.toString()));
+                                }
                                 doubleSerde.serialize(aDouble, out);
                             } else if (serString[0] == SER_NULL_TYPE_TAG)
                                 nullSerde.serialize(ANull.NULL, out);

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADurationConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADurationConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADurationConstructorDescriptor.java
index 3d8c4e9..c51c5f2 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADurationConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADurationConstructorDescriptor.java
@@ -38,6 +38,7 @@ import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -74,6 +75,7 @@ public class ADurationConstructorDescriptor extends AbstractScalarFunctionDynami
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
+                    private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
 
                     @Override
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
@@ -85,10 +87,12 @@ public class ADurationConstructorDescriptor extends AbstractScalarFunctionDynami
 
                             if (serString[0] == SER_STRING_TYPE_TAG) {
 
-                                int stringLength = (serString[1] & 0xff << 8) + (serString[2] & 0xff << 0);
+                                utf8Ptr.set(serString, 1, outInput.getLength() - 1);
+                                int stringLength = utf8Ptr.getUTF8Length();
 
-                                ADurationParserFactory.parseDuration(serString, 3, stringLength, aDuration,
-                                        ADurationParseOption.All);
+                                ADurationParserFactory
+                                        .parseDuration(serString, utf8Ptr.getCharStartOffset(), stringLength, aDuration,
+                                                ADurationParseOption.All);
 
                                 durationSerde.serialize(aDuration, out);
                             } else if (serString[0] == SER_NULL_TYPE_TAG) {

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AFloatConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AFloatConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AFloatConstructorDescriptor.java
index b274419..3de5265 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AFloatConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AFloatConstructorDescriptor.java
@@ -39,8 +39,10 @@ import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import org.apache.hyracks.api.dataflow.value.IBinaryComparator;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+import org.apache.hyracks.util.string.UTF8StringUtil;
 
 public class AFloatConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
@@ -66,9 +68,10 @@ public class AFloatConstructorDescriptor extends AbstractScalarFunctionDynamicDe
                     private ArrayBackedValueStorage outInput = new ArrayBackedValueStorage();
                     private ICopyEvaluator eval = args[0].createEvaluator(outInput);
                     private String errorMessage = "This can not be an instance of float";
-                    private final byte[] POSITIVE_INF = { 0, 3, 'I', 'N', 'F' };
-                    private final byte[] NEGATIVE_INF = { 0, 4, '-', 'I', 'N', 'F' };
-                    private final byte[] NAN = { 0, 3, 'N', 'a', 'N' };
+                    private final byte[] POSITIVE_INF = UTF8StringUtil.writeStringToBytes("INF");
+                    private final byte[] NEGATIVE_INF = UTF8StringUtil.writeStringToBytes("-INF");
+                    private final byte[] NAN = UTF8StringUtil.writeStringToBytes("NaN");
+
                     // private int offset = 3, value = 0, pointIndex = 0, eIndex
                     // = 1;
                     // private int integerPart = 0, fractionPart = 0,
@@ -86,6 +89,7 @@ public class AFloatConstructorDescriptor extends AbstractScalarFunctionDynamicDe
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
+                    private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
 
                     @Override
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
@@ -101,11 +105,13 @@ public class AFloatConstructorDescriptor extends AbstractScalarFunctionDynamicDe
                                 } else if (utf8BinaryComparator.compare(serString, 1, outInput.getLength(),
                                         NEGATIVE_INF, 0, 6) == 0) {
                                     aFloat.setValue(Float.NEGATIVE_INFINITY);
-                                } else if (utf8BinaryComparator.compare(serString, 1, outInput.getLength(), NAN, 0, 5) == 0) {
+                                } else if (utf8BinaryComparator.compare(serString, 1, outInput.getLength(), NAN, 0, 5)
+                                        == 0) {
                                     aFloat.setValue(Float.NaN);
-                                } else
-                                    aFloat.setValue(Float.parseFloat(new String(serString, 3, outInput.getLength() - 3,
-                                            "UTF-8")));
+                                } else {
+                                    utf8Ptr.set(serString, 1, outInput.getLength() -1);
+                                    aFloat.setValue(Float.parseFloat(utf8Ptr.toString()));
+                                }
                                 floatSerde.serialize(aFloat, out);
 
                             } else if (serString[0] == SER_NULL_TYPE_TAG)

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt16ConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt16ConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt16ConstructorDescriptor.java
index 838e3c0..c498217 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt16ConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt16ConstructorDescriptor.java
@@ -37,6 +37,7 @@ import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -75,6 +76,7 @@ public class AInt16ConstructorDescriptor extends AbstractScalarFunctionDynamicDe
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
+                    private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
 
                     @Override
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
@@ -84,7 +86,8 @@ public class AInt16ConstructorDescriptor extends AbstractScalarFunctionDynamicDe
                             eval.evaluate(tuple);
                             byte[] serString = outInput.getByteArray();
                             if (serString[0] == SER_STRING_TYPE_TAG) {
-                                offset = 3;
+                                utf8Ptr.set(serString, 1, outInput.getLength()-1);
+                                offset = utf8Ptr.getCharStartOffset();
                                 value = 0;
                                 positive = true;
                                 if (serString[offset] == '+')

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt32ConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt32ConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt32ConstructorDescriptor.java
index ddc78c8..f08972f 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt32ConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt32ConstructorDescriptor.java
@@ -37,6 +37,7 @@ import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -74,6 +75,7 @@ public class AInt32ConstructorDescriptor extends AbstractScalarFunctionDynamicDe
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
+                    private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
 
                     @Override
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
@@ -83,7 +85,8 @@ public class AInt32ConstructorDescriptor extends AbstractScalarFunctionDynamicDe
                             eval.evaluate(tuple);
                             byte[] serString = outInput.getByteArray();
                             if (serString[0] == SER_STRING_TYPE_TAG) {
-                                offset = 3;
+                                utf8Ptr.set(serString, 1, outInput.getLength()-1);
+                                offset = utf8Ptr.getCharStartOffset();
                                 value = 0;
                                 positive = true;
                                 if (serString[offset] == '+')

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt64ConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt64ConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt64ConstructorDescriptor.java
index f766c82..eb43c5d 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt64ConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt64ConstructorDescriptor.java
@@ -37,6 +37,7 @@ import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -75,6 +76,7 @@ public class AInt64ConstructorDescriptor extends AbstractScalarFunctionDynamicDe
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
+                    private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
 
                     @Override
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
@@ -84,7 +86,8 @@ public class AInt64ConstructorDescriptor extends AbstractScalarFunctionDynamicDe
                             eval.evaluate(tuple);
                             byte[] serString = outInput.getByteArray();
                             if (serString[0] == SER_STRING_TYPE_TAG) {
-                                offset = 3;
+                                utf8Ptr.set(serString, 1, outInput.getLength()-1);
+                                offset = utf8Ptr.getCharStartOffset();
                                 value = 0;
                                 positive = true;
                                 if (serString[offset] == '+')

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt8ConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt8ConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt8ConstructorDescriptor.java
index d77c424..2c8010b 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt8ConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AInt8ConstructorDescriptor.java
@@ -37,6 +37,7 @@ import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -75,6 +76,7 @@ public class AInt8ConstructorDescriptor extends AbstractScalarFunctionDynamicDes
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
+                    private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
 
                     @Override
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
@@ -84,7 +86,8 @@ public class AInt8ConstructorDescriptor extends AbstractScalarFunctionDynamicDes
                             eval.evaluate(tuple);
                             byte[] serString = outInput.getByteArray();
                             if (serString[0] == SER_STRING_TYPE_TAG) {
-                                offset = 3;
+                                utf8Ptr.set(serString, 1, outInput.getLength()-1);
+                                offset = utf8Ptr.getCharStartOffset();
                                 value = 0;
                                 positive = true;
                                 if (serString[offset] == '+')

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalFromDateConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalFromDateConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalFromDateConstructorDescriptor.java
index 0684018..d238938 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalFromDateConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalFromDateConstructorDescriptor.java
@@ -41,6 +41,7 @@ import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -82,6 +83,7 @@ public class AIntervalFromDateConstructorDescriptor extends AbstractScalarFuncti
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
+                    private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
 
                     @Override
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
@@ -104,10 +106,11 @@ public class AIntervalFromDateConstructorDescriptor extends AbstractScalarFuncti
                             if (argOut0.getByteArray()[0] == SER_DATE_TYPE_TAG) {
                                 intervalStart = ADateSerializerDeserializer.getChronon(argOut0.getByteArray(), 1);
                             } else if (argOut0.getByteArray()[0] == SER_STRING_TYPE_TAG) {
-                                int stringLength = (argOut0.getByteArray()[1] & 0xff << 8)
-                                        + (argOut0.getByteArray()[2] & 0xff << 0);
-                                intervalStart = ADateParserFactory.parseDatePart(argOut0.getByteArray(), 3,
-                                        stringLength) / GregorianCalendarSystem.CHRONON_OF_DAY;
+                                utf8Ptr.set(argOut0.getByteArray(), 1, argOut0.getLength() - 1);
+                                int stringLength = utf8Ptr.getUTF8Length();
+                                intervalStart = ADateParserFactory
+                                        .parseDatePart(utf8Ptr.getByteArray(), utf8Ptr.getCharStartOffset(),
+                                                stringLength) / GregorianCalendarSystem.CHRONON_OF_DAY;
                             } else {
                                 throw new AlgebricksException(FID.getName()
                                         + ": expects NULL/STRING/DATE for the first argument, but got "
@@ -117,10 +120,11 @@ public class AIntervalFromDateConstructorDescriptor extends AbstractScalarFuncti
                             if (argOut1.getByteArray()[0] == SER_DATE_TYPE_TAG) {
                                 intervalEnd = ADateSerializerDeserializer.getChronon(argOut1.getByteArray(), 1);
                             } else if (argOut1.getByteArray()[0] == SER_STRING_TYPE_TAG) {
-                                int stringLength = (argOut1.getByteArray()[1] & 0xff << 8)
-                                        + (argOut1.getByteArray()[2] & 0xff << 0);
-                                intervalEnd = ADateParserFactory.parseDatePart(argOut1.getByteArray(), 3, stringLength)
-                                        / GregorianCalendarSystem.CHRONON_OF_DAY;
+                                utf8Ptr.set(argOut1.getByteArray(), 1, argOut1.getLength() - 1);
+                                int stringLength = utf8Ptr.getUTF8Length();
+                                intervalEnd = ADateParserFactory
+                                        .parseDatePart(utf8Ptr.getByteArray(), utf8Ptr.getCharStartOffset(),
+                                                stringLength) / GregorianCalendarSystem.CHRONON_OF_DAY;
                             } else {
                                 throw new AlgebricksException(FID.getName()
                                         + ": expects NULL/STRING/DATE for the second argument, but got "

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalFromDateTimeConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalFromDateTimeConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalFromDateTimeConstructorDescriptor.java
index 7f731d4..939485e 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalFromDateTimeConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalFromDateTimeConstructorDescriptor.java
@@ -21,7 +21,6 @@ package org.apache.asterix.runtime.evaluators.constructors;
 import java.io.DataOutput;
 import java.io.IOException;
 
-import org.apache.asterix.common.functions.FunctionConstants;
 import org.apache.asterix.dataflow.data.nontagged.serde.ADateTimeSerializerDeserializer;
 import org.apache.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import org.apache.asterix.om.base.AInterval;
@@ -42,6 +41,7 @@ import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -83,6 +83,7 @@ public class AIntervalFromDateTimeConstructorDescriptor extends AbstractScalarFu
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
+                    private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
 
                     @Override
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
@@ -106,20 +107,24 @@ public class AIntervalFromDateTimeConstructorDescriptor extends AbstractScalarFu
                                 intervalStart = ADateTimeSerializerDeserializer.getChronon(argOut0.getByteArray(), 1);
                             } else if (argOut0.getByteArray()[0] == SER_STRING_TYPE_TAG) {
                                 // start datetime
-                                int stringLength = (argOut0.getByteArray()[1] & 0xff << 8)
-                                        + (argOut0.getByteArray()[2] & 0xff << 0);
+                                utf8Ptr.set(argOut0.getByteArray(), 1, argOut0.getLength() - 1);
+
+                                int stringLength = utf8Ptr.getUTF8Length();
                                 // get offset for time part: +1 if it is negative (-)
-                                short timeOffset = (short) ((argOut0.getByteArray()[3] == '-') ? 1 : 0);
+                                int startOffset = utf8Ptr.getCharStartOffset();
+                                short timeOffset = (short) ((argOut0.getByteArray()[startOffset] == '-') ? 1 : 0);
                                 timeOffset += 8;
-                                if (argOut0.getByteArray()[3 + timeOffset] != 'T') {
+                                if (argOut0.getByteArray()[startOffset + timeOffset] != 'T') {
                                     timeOffset += 2;
-                                    if (argOut0.getByteArray()[3 + timeOffset] != 'T') {
+                                    if (argOut0.getByteArray()[startOffset + timeOffset] != 'T') {
                                         throw new AlgebricksException(errorMessage + ": missing T");
                                     }
                                 }
-                                intervalStart = ADateParserFactory.parseDatePart(argOut0.getByteArray(), 3, timeOffset);
-                                intervalStart += ATimeParserFactory.parseTimePart(argOut0.getByteArray(),
-                                        3 + timeOffset + 1, stringLength - timeOffset - 1);
+                                intervalStart = ADateParserFactory
+                                        .parseDatePart(argOut0.getByteArray(), startOffset, timeOffset);
+                                intervalStart += ATimeParserFactory
+                                        .parseTimePart(argOut0.getByteArray(), startOffset + timeOffset + 1,
+                                                stringLength - timeOffset - 1);
                             } else {
                                 throw new AlgebricksException(FID.getName()
                                         + ": expects NULL/STRING/DATETIME for the first argument, but got "
@@ -130,20 +135,22 @@ public class AIntervalFromDateTimeConstructorDescriptor extends AbstractScalarFu
                                 intervalEnd = ADateTimeSerializerDeserializer.getChronon(argOut1.getByteArray(), 1);
                             } else if (argOut1.getByteArray()[0] == SER_STRING_TYPE_TAG) {
                                 // start datetime
-                                int stringLength = (argOut1.getByteArray()[1] & 0xff << 8)
-                                        + (argOut1.getByteArray()[2] & 0xff << 0);
+                                utf8Ptr.set(argOut1.getByteArray(), 1, argOut1.getLength() - 1);
+                                int stringLength = utf8Ptr.getUTF8Length();
                                 // get offset for time part: +1 if it is negative (-)
-                                short timeOffset = (short) ((argOut1.getByteArray()[3] == '-') ? 1 : 0);
+                                int startOffset = utf8Ptr.getCharStartOffset();
+                                short timeOffset = (short) ((argOut1.getByteArray()[startOffset] == '-') ? 1 : 0);
                                 timeOffset += 8;
-                                if (argOut1.getByteArray()[3 + timeOffset] != 'T') {
+                                if (argOut1.getByteArray()[startOffset + timeOffset] != 'T') {
                                     timeOffset += 2;
-                                    if (argOut1.getByteArray()[3 + timeOffset] != 'T') {
+                                    if (argOut1.getByteArray()[startOffset + timeOffset] != 'T') {
                                         throw new AlgebricksException(errorMessage + ": missing T");
                                     }
                                 }
-                                intervalEnd = ADateParserFactory.parseDatePart(argOut1.getByteArray(), 3, timeOffset);
+                                intervalEnd = ADateParserFactory
+                                        .parseDatePart(argOut1.getByteArray(), startOffset, timeOffset);
                                 intervalEnd += ATimeParserFactory.parseTimePart(argOut1.getByteArray(),
-                                        3 + timeOffset + 1, stringLength - timeOffset - 1);
+                                        startOffset + timeOffset + 1, stringLength - timeOffset - 1);
                             } else {
                                 throw new AlgebricksException(FID.getName()
                                         + ": expects NULL/STRING/DATETIME for the second argument, but got "

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalFromTimeConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalFromTimeConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalFromTimeConstructorDescriptor.java
index 3075ab9..dbb05e5 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalFromTimeConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalFromTimeConstructorDescriptor.java
@@ -21,7 +21,6 @@ package org.apache.asterix.runtime.evaluators.constructors;
 import java.io.DataOutput;
 import java.io.IOException;
 
-import org.apache.asterix.common.functions.FunctionConstants;
 import org.apache.asterix.dataflow.data.nontagged.serde.ATimeSerializerDeserializer;
 import org.apache.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import org.apache.asterix.om.base.AInterval;
@@ -42,6 +41,7 @@ import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -83,6 +83,7 @@ public class AIntervalFromTimeConstructorDescriptor extends AbstractScalarFuncti
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
+                    private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
 
                     @Override
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
@@ -105,12 +106,13 @@ public class AIntervalFromTimeConstructorDescriptor extends AbstractScalarFuncti
                             if (argOut0.getByteArray()[0] == SER_TIME_TYPE_TAG) {
                                 intervalStart = ATimeSerializerDeserializer.getChronon(argOut0.getByteArray(), 1);
                             } else if (argOut0.getByteArray()[0] == SER_STRING_TYPE_TAG) {
+                                utf8Ptr.set(argOut0.getByteArray(), 1, argOut0.getLength() - 1);
                                 // start date
-                                int stringLength = (argOut0.getByteArray()[1] & 0xff << 8)
-                                        + (argOut0.getByteArray()[2] & 0xff << 0);
+                                int stringLength = utf8Ptr.getUTF8Length();
 
-                                intervalStart = ATimeParserFactory.parseTimePart(argOut0.getByteArray(), 3,
-                                        stringLength);
+                                intervalStart = ATimeParserFactory
+                                        .parseTimePart(utf8Ptr.getByteArray(), utf8Ptr.getCharStartOffset(),
+                                                stringLength);
                             } else {
                                 throw new AlgebricksException(FID.getName()
                                         + ": expects NULL/STRING/TIME for the first argument, but got "
@@ -124,11 +126,13 @@ public class AIntervalFromTimeConstructorDescriptor extends AbstractScalarFuncti
                             if (argOut1.getByteArray()[0] == SER_TIME_TYPE_TAG) {
                                 intervalEnd = ATimeSerializerDeserializer.getChronon(argOut1.getByteArray(), 1);
                             } else if (argOut1.getByteArray()[0] == SER_STRING_TYPE_TAG) {
+                                utf8Ptr.set(argOut1.getByteArray(), 1, argOut1.getLength() - 1);
                                 // start date
-                                int stringLength = (argOut1.getByteArray()[1] & 0xff << 8)
-                                        + (argOut1.getByteArray()[2] & 0xff << 0);
+                                int stringLength = utf8Ptr.getUTF8Length();
 
-                                intervalEnd = ATimeParserFactory.parseTimePart(argOut1.getByteArray(), 3, stringLength);
+                                intervalEnd = ATimeParserFactory
+                                        .parseTimePart(argOut1.getByteArray(), utf8Ptr.getCharStartOffset(),
+                                                stringLength);
 
                             } else {
                                 throw new AlgebricksException(FID.getName()

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalStartFromDateConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalStartFromDateConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalStartFromDateConstructorDescriptor.java
index 4462b8e..b82dcac 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalStartFromDateConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalStartFromDateConstructorDescriptor.java
@@ -48,6 +48,7 @@ import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -93,6 +94,7 @@ public class AIntervalStartFromDateConstructorDescriptor extends AbstractScalarF
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
+                    private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
 
                     @Override
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
@@ -116,10 +118,11 @@ public class AIntervalStartFromDateConstructorDescriptor extends AbstractScalarF
                                 intervalStart = ADateSerializerDeserializer.getChronon(argOut0.getByteArray(), 1)
                                         * GregorianCalendarSystem.CHRONON_OF_DAY;
                             } else if (argOut0.getByteArray()[0] == SER_STRING_TYPE_TAG) {
+                                utf8Ptr.set(argOut0.getByteArray(), 1, argOut0.getLength() - 1);
                                 // start date
-                                int stringLength = (argOut0.getByteArray()[1] & 0xff << 8)
-                                        + (argOut0.getByteArray()[2] & 0xff << 0);
-                                intervalStart = ADateParserFactory.parseDatePart(argOut0.getByteArray(), 3,
+                                int stringLength = utf8Ptr.getUTF8Length();
+                                int startOffset = utf8Ptr.getCharStartOffset();
+                                intervalStart = ADateParserFactory.parseDatePart(argOut0.getByteArray(), startOffset,
                                         stringLength);
                             } else {
                                 throw new AlgebricksException(FID.getName()
@@ -134,18 +137,21 @@ public class AIntervalStartFromDateConstructorDescriptor extends AbstractScalarF
                             } else if (argOut1.getByteArray()[0] == SER_DAY_TIME_DURATION_TYPE_TAG) {
                                 intervalEnd = DurationArithmeticOperations.addDuration(intervalStart,
                                         0,
-                                        ADayTimeDurationSerializerDeserializer.getDayTime(argOut1.getByteArray(), 1), false);
+                                        ADayTimeDurationSerializerDeserializer.getDayTime(argOut1.getByteArray(), 1),
+                                        false);
                             } else if (argOut1.getByteArray()[0] == SER_YEAR_MONTH_DURATION_TYPE_TAG) {
                                 intervalEnd = DurationArithmeticOperations.addDuration(intervalStart,
-                                        AYearMonthDurationSerializerDeserializer.getYearMonth(argOut1.getByteArray(), 1),
+                                        AYearMonthDurationSerializerDeserializer
+                                                .getYearMonth(argOut1.getByteArray(), 1),
                                         0, false);
                             } else if (argOut1.getByteArray()[0] == SER_STRING_TYPE_TAG) {
                                 // duration
-                                int stringLength = (argOut1.getByteArray()[1] & 0xff << 8)
-                                        + (argOut1.getByteArray()[2] & 0xff << 0);
+                                utf8Ptr.set(argOut1.getByteArray(), 1, argOut1.getLength() - 1);
+                                int stringLength = utf8Ptr.getUTF8Length();
 
-                                ADurationParserFactory.parseDuration(argOut1.getByteArray(), 3, stringLength,
-                                        aDuration, ADurationParseOption.All);
+                                ADurationParserFactory
+                                        .parseDuration(argOut1.getByteArray(), utf8Ptr.getCharStartOffset(),
+                                                stringLength, aDuration, ADurationParseOption.All);
                                 intervalEnd = DurationArithmeticOperations.addDuration(intervalStart,
                                         aDuration.getMonths(), aDuration.getMilliseconds(), false);
                             } else {

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalStartFromDateTimeConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalStartFromDateTimeConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalStartFromDateTimeConstructorDescriptor.java
index 826e3f8..3ad1cc3 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalStartFromDateTimeConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalStartFromDateTimeConstructorDescriptor.java
@@ -32,10 +32,10 @@ import org.apache.asterix.om.base.AMutableInterval;
 import org.apache.asterix.om.base.ANull;
 import org.apache.asterix.om.base.temporal.ADateParserFactory;
 import org.apache.asterix.om.base.temporal.ADurationParserFactory;
+import org.apache.asterix.om.base.temporal.ADurationParserFactory.ADurationParseOption;
 import org.apache.asterix.om.base.temporal.ATimeParserFactory;
 import org.apache.asterix.om.base.temporal.DurationArithmeticOperations;
 import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
-import org.apache.asterix.om.base.temporal.ADurationParserFactory.ADurationParseOption;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
 import org.apache.asterix.om.types.ATypeTag;
@@ -48,6 +48,7 @@ import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -93,6 +94,7 @@ public class AIntervalStartFromDateTimeConstructorDescriptor extends AbstractSca
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
+                    private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
 
                     @Override
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
@@ -115,24 +117,27 @@ public class AIntervalStartFromDateTimeConstructorDescriptor extends AbstractSca
                             if (argOut0.getByteArray()[0] == SER_DATETIME_TYPE_TAG) {
                                 intervalStart = ADateTimeSerializerDeserializer.getChronon(argOut0.getByteArray(), 1);
                             } else if (argOut0.getByteArray()[0] == SER_STRING_TYPE_TAG) {
-                                int stringLength = (argOut0.getByteArray()[1] & 0xff << 8)
-                                        + (argOut0.getByteArray()[2] & 0xff << 0);
+                                utf8Ptr.set(argOut0.getByteArray(), 1, argOut0.getLength() - 1);
+
+                                int stringLength = utf8Ptr.getUTF8Length();
+                                int startOffset = utf8Ptr.getCharStartOffset();
 
                                 // get offset for time part: +1 if it is negative (-)
-                                short timeOffset = (short) ((argOut0.getByteArray()[3] == '-') ? 1 : 0);
+                                short timeOffset = (short) ((argOut0.getByteArray()[startOffset] == '-') ? 1 : 0);
 
                                 timeOffset += 8;
 
-                                if (argOut0.getByteArray()[3 + timeOffset] != 'T') {
+                                if (argOut0.getByteArray()[startOffset + timeOffset] != 'T') {
                                     timeOffset += 2;
-                                    if (argOut0.getByteArray()[3 + timeOffset] != 'T') {
+                                    if (argOut0.getByteArray()[startOffset + timeOffset] != 'T') {
                                         throw new AlgebricksException(errorMessage + ": missing T");
                                     }
                                 }
 
-                                intervalStart = ADateParserFactory.parseDatePart(argOut0.getByteArray(), 3, timeOffset);
+                                intervalStart = ADateParserFactory
+                                        .parseDatePart(argOut0.getByteArray(), startOffset, timeOffset);
                                 intervalStart += ATimeParserFactory.parseTimePart(argOut0.getByteArray(),
-                                        3 + timeOffset + 1, stringLength - timeOffset - 1);
+                                        startOffset + timeOffset + 1, stringLength - timeOffset - 1);
                             } else {
                                 throw new AlgebricksException(FID.getName()
                                         + ": expects NULL/STRING/DATETIME for the first argument but got "
@@ -156,11 +161,12 @@ public class AIntervalStartFromDateTimeConstructorDescriptor extends AbstractSca
                             } else if (argOut1.getByteArray()[0] == SER_STRING_TYPE_TAG) {
 
                                 // duration
-                                int stringLength = (argOut1.getByteArray()[1] & 0xff << 8)
-                                        + (argOut1.getByteArray()[2] & 0xff << 0);
+                                utf8Ptr.set(argOut1.getByteArray(), 1, argOut1.getLength() - 1);
+                                int stringLength = utf8Ptr.getUTF8Length();
 
-                                ADurationParserFactory.parseDuration(argOut1.getByteArray(), 3, stringLength,
-                                        aDuration, ADurationParseOption.All);
+                                ADurationParserFactory
+                                        .parseDuration(argOut1.getByteArray(), utf8Ptr.getCharStartOffset(),
+                                                stringLength, aDuration, ADurationParseOption.All);
 
                                 intervalEnd = DurationArithmeticOperations.addDuration(intervalStart,
                                         aDuration.getMonths(), aDuration.getMilliseconds(), false);

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalStartFromTimeConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalStartFromTimeConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalStartFromTimeConstructorDescriptor.java
index 9ecc8bd..3474ed6 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalStartFromTimeConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalStartFromTimeConstructorDescriptor.java
@@ -30,11 +30,11 @@ import org.apache.asterix.om.base.AMutableDuration;
 import org.apache.asterix.om.base.AMutableInterval;
 import org.apache.asterix.om.base.ANull;
 import org.apache.asterix.om.base.temporal.ADurationParserFactory;
+import org.apache.asterix.om.base.temporal.ADurationParserFactory.ADurationParseOption;
 import org.apache.asterix.om.base.temporal.ATimeParserFactory;
 import org.apache.asterix.om.base.temporal.DurationArithmeticOperations;
 import org.apache.asterix.om.base.temporal.GregorianCalendarSystem;
 import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
-import org.apache.asterix.om.base.temporal.ADurationParserFactory.ADurationParseOption;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
 import org.apache.asterix.om.types.ATypeTag;
@@ -47,6 +47,7 @@ import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -91,6 +92,7 @@ public class AIntervalStartFromTimeConstructorDescriptor extends AbstractScalarF
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
+                    private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
 
                     @Override
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
@@ -113,11 +115,13 @@ public class AIntervalStartFromTimeConstructorDescriptor extends AbstractScalarF
                             if (argOut0.getByteArray()[0] == SER_TIME_TYPE_TAG) {
                                 intervalStart = ATimeSerializerDeserializer.getChronon(argOut0.getByteArray(), 1);
                             } else if (argOut0.getByteArray()[0] == SER_STRING_TYPE_TAG) {
-                                int stringLength = (argOut0.getByteArray()[1] & 0xff << 8)
-                                        + (argOut0.getByteArray()[2] & 0xff << 0);
+                                utf8Ptr.set(argOut0.getByteArray(), 1, argOut0.getLength() - 1);
+
+                                int stringLength = utf8Ptr.getUTF8Length();
 
-                                intervalStart = ATimeParserFactory.parseTimePart(argOut0.getByteArray(), 3,
-                                        stringLength);
+                                intervalStart = ATimeParserFactory
+                                        .parseTimePart(argOut0.getByteArray(), utf8Ptr.getCharStartOffset(),
+                                                stringLength);
                             } else {
                                 throw new AlgebricksException(FID.getName()
                                         + ": expects NULL/STRING/TIME for the first argument, but got "
@@ -147,11 +151,12 @@ public class AIntervalStartFromTimeConstructorDescriptor extends AbstractScalarF
                             } else if (argOut1.getByteArray()[0] == SER_STRING_TYPE_TAG) {
                                 // duration
 
-                                int stringLength = (argOut1.getByteArray()[1] & 0xff << 8)
-                                        + (argOut1.getByteArray()[2] & 0xff << 0);
+                                utf8Ptr.set(argOut1.getByteArray(), 1, argOut1.getLength() - 1);
+                                int stringLength = utf8Ptr.getUTF8Length();
 
-                                ADurationParserFactory.parseDuration(argOut1.getByteArray(), 3, stringLength,
-                                        aDuration, ADurationParseOption.All);
+                                ADurationParserFactory
+                                        .parseDuration(argOut1.getByteArray(), utf8Ptr.getCharStartOffset(),
+                                                stringLength, aDuration, ADurationParseOption.All);
 
                                 if (aDuration.getMonths() != 0) {
                                     throw new AlgebricksException(FID.getName()

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ALineConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ALineConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ALineConstructorDescriptor.java
index afb1e1a..bafb778 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ALineConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ALineConstructorDescriptor.java
@@ -38,6 +38,7 @@ import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -74,6 +75,7 @@ public class ALineConstructorDescriptor extends AbstractScalarFunctionDynamicDes
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
+                    private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
 
                     @Override
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
@@ -83,7 +85,8 @@ public class ALineConstructorDescriptor extends AbstractScalarFunctionDynamicDes
                             eval.evaluate(tuple);
                             byte[] serString = outInput.getByteArray();
                             if (serString[0] == SER_STRING_TYPE_TAG) {
-                                String s = new String(serString, 3, outInput.getLength() - 3, "UTF-8");
+                                utf8Ptr.set(serString, 1, outInput.getLength()-1);
+                                String s = utf8Ptr.toString();
                                 int commaIndex = s.indexOf(',');
                                 int spaceIndex = s.indexOf(' ', commaIndex + 1);
                                 aPoint[0].setValue(Double.parseDouble(s.substring(0, commaIndex)),

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/742aba85/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ANullConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ANullConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ANullConstructorDescriptor.java
index 26c9a40..4b204f4 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ANullConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ANullConstructorDescriptor.java
@@ -39,6 +39,7 @@ import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.data.std.api.IDataOutputProvider;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+import org.apache.hyracks.util.string.UTF8StringUtil;
 
 public class ANullConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
@@ -63,7 +64,7 @@ public class ANullConstructorDescriptor extends AbstractScalarFunctionDynamicDes
                     private ArrayBackedValueStorage outInput = new ArrayBackedValueStorage();
                     private ICopyEvaluator eval = args[0].createEvaluator(outInput);
                     private String errorMessage = "This can not be an instance of null";
-                    private final byte[] NULL = { 0, 4, 'n', 'u', 'l', 'l' };
+                    private final byte[] NULL = UTF8StringUtil.writeStringToBytes("null");
                     IBinaryComparator utf8BinaryComparator = AqlBinaryComparatorFactoryProvider.UTF8STRING_POINTABLE_INSTANCE
                             .createBinaryComparator();
                     @SuppressWarnings("unchecked")
@@ -78,7 +79,7 @@ public class ANullConstructorDescriptor extends AbstractScalarFunctionDynamicDes
                             eval.evaluate(tuple);
                             byte[] serString = outInput.getByteArray();
                             if (serString[0] == SER_STRING_TYPE_TAG) {
-                                if (utf8BinaryComparator.compare(serString, 1, outInput.getLength(), NULL, 0, 6) == 0) {
+                                if (utf8BinaryComparator.compare(serString, 1, outInput.getLength(), NULL, 0, NULL.length) == 0) {
                                     nullSerde.serialize(ANull.NULL, out);
                                     return;
                                 } else


Mime
View raw message