asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From buyin...@apache.org
Subject [07/24] incubator-asterixdb git commit: Move to non-copy-based evaluator interfaces for all function implementations, including: - scalar functions, - aggregate functions, - running aggregate functions, - unnesting functions
Date Sat, 13 Feb 2016 02:15:36 GMT
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringEqualDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringEqualDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringEqualDescriptor.java
index 8cc3400..441c3e1 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringEqualDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringEqualDescriptor.java
@@ -18,17 +18,15 @@
  */
 package org.apache.asterix.runtime.evaluators.functions;
 
-import java.io.DataOutput;
-
 import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 
 public class StringEqualDescriptor extends AbstractScalarFunctionDynamicDescriptor {
@@ -42,17 +40,17 @@ public class StringEqualDescriptor extends AbstractScalarFunctionDynamicDescript
     };
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
+            throws AlgebricksException {
 
-        return new ICopyEvaluatorFactory() {
+        return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public ICopyEvaluator createEvaluator(IDataOutputProvider output) throws AlgebricksException {
-
-                DataOutput dout = output.getDataOutput();
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
 
-                return new AbstractBinaryStringBoolEval(dout, args[0], args[1], AsterixBuiltinFunctions.STRING_EQUAL) {
+                return new AbstractBinaryStringBoolEval(ctx, args[0], args[1],
+                        AsterixBuiltinFunctions.STRING_EQUAL) {
 
                     @Override
                     protected boolean compute(UTF8StringPointable left, UTF8StringPointable right)

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringJoinDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringJoinDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringJoinDescriptor.java
index 866d6c4..67f3fbd 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringJoinDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringJoinDescriptor.java
@@ -31,9 +31,11 @@ import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.data.std.api.IPointable;
+import org.apache.hyracks.data.std.primitive.VoidPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 import org.apache.hyracks.util.string.UTF8StringUtil;
@@ -49,57 +51,63 @@ public class StringJoinDescriptor extends AbstractScalarFunctionDynamicDescripto
     };
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
-        return new ICopyEvaluatorFactory() {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
+        return new IScalarEvaluatorFactory() {
 
             private static final long serialVersionUID = 1L;
 
             @Override
-            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
-                return new ICopyEvaluator() {
-
-                    private DataOutput out = output.getDataOutput();
-                    private ICopyEvaluatorFactory listEvalFactory = args[0];
-                    private ICopyEvaluatorFactory sepEvalFactory = args[1];
-                    private ArrayBackedValueStorage outInputList = new ArrayBackedValueStorage();
-                    private ArrayBackedValueStorage outInputSep = new ArrayBackedValueStorage();
-                    private ICopyEvaluator evalList = listEvalFactory.createEvaluator(outInputList);
-                    private ICopyEvaluator evalSep = sepEvalFactory.createEvaluator(outInputSep);
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+                return new IScalarEvaluator() {
+
+                    private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+                    private DataOutput out = resultStorage.getDataOutput();
+                    private IScalarEvaluatorFactory listEvalFactory = args[0];
+                    private IScalarEvaluatorFactory sepEvalFactory = args[1];
+                    private IPointable inputArgList = new VoidPointable();
+                    private IPointable inputArgSep = new VoidPointable();
+                    private IScalarEvaluator evalList = listEvalFactory.createScalarEvaluator(ctx);
+                    private IScalarEvaluator evalSep = sepEvalFactory.createScalarEvaluator(ctx);
                     private final byte[] tempLengthArray = new byte[5];
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
                         try {
-                            outInputList.reset();
-                            evalList.evaluate(tuple);
-                            byte[] serOrderedList = outInputList.getByteArray();
-
-                            outInputSep.reset();
-                            evalSep.evaluate(tuple);
-                            byte[] serSep = outInputSep.getByteArray();
-                            if (serOrderedList[0] != ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG
-                                    && serOrderedList[1] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
+                            resultStorage.reset();
+                            evalList.evaluate(tuple, inputArgList);
+                            byte[] serOrderedList = inputArgList.getByteArray();
+                            int serOrderedListOffset = inputArgList.getStartOffset();
+
+                            evalSep.evaluate(tuple, inputArgSep);
+                            byte[] serSep = inputArgSep.getByteArray();
+                            int serSepOffset = inputArgSep.getStartOffset();
+
+                            if (serOrderedList[serOrderedListOffset] != ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG
+                                    && serOrderedList[serOrderedListOffset
+                                            + 1] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                                 throw new AlgebricksException(AsterixBuiltinFunctions.STRING_JOIN.getName()
                                         + ": expects input type ORDEREDLIST but got "
-                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serOrderedList[0]));
+                                        + EnumDeserializer.ATYPETAGDESERIALIZER
+                                                .deserialize(serOrderedList[serOrderedListOffset]));
                             }
 
-                            if (serSep[0] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
+                            if (serSep[serSepOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                                 throw new AlgebricksException(AsterixBuiltinFunctions.STRING_JOIN.getName()
                                         + ": expects STRING type for the seperator but got "
-                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serSep[0]));
+                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serSep[serSepOffset]));
                             }
 
-                            int size = AOrderedListSerializerDeserializer.getNumberOfItems(serOrderedList);
+                            int size = AOrderedListSerializerDeserializer.getNumberOfItems(serOrderedList,
+                                    serOrderedListOffset);
                             try {
                                 // calculate length first
                                 int utf_8_len = 0;
-                                int sep_len = UTF8StringUtil.getUTFLength(serSep, 1);
+                                int sep_len = UTF8StringUtil.getUTFLength(serSep, serSepOffset + 1);
                                 int sep_meta_len = UTF8StringUtil.getNumBytesToStoreLength(sep_len);
 
                                 for (int i = 0; i < size; i++) {
                                     int itemOffset = AOrderedListSerializerDeserializer.getItemOffset(serOrderedList,
-                                            i);
+                                            serOrderedListOffset, i);
 
                                     int currentSize = UTF8StringUtil.getUTFLength(serOrderedList, itemOffset);
                                     if (i != size - 1 && currentSize != 0) {
@@ -112,19 +120,21 @@ public class StringJoinDescriptor extends AbstractScalarFunctionDynamicDescripto
                                 out.write(tempLengthArray, 0, length);
                                 for (int i = 0; i < size; i++) {
                                     int itemOffset = AOrderedListSerializerDeserializer.getItemOffset(serOrderedList,
-                                            i);
+                                            serOrderedListOffset, i);
                                     utf_8_len = UTF8StringUtil.getUTFLength(serOrderedList, itemOffset);
                                     out.write(serOrderedList,
                                             itemOffset + UTF8StringUtil.getNumBytesToStoreLength(utf_8_len), utf_8_len);
-                                    if (i == size - 1 || utf_8_len == 0)
+                                    if (i == size - 1 || utf_8_len == 0) {
                                         continue;
+                                    }
                                     for (int j = 0; j < sep_len; j++) {
-                                        out.writeByte(serSep[1 + sep_meta_len + j]);
+                                        out.writeByte(serSep[serSepOffset + 1 + sep_meta_len + j]);
                                     }
                                 }
                             } catch (AsterixException ex) {
                                 throw new AlgebricksException(ex);
                             }
+                            result.set(resultStorage);
                         } catch (IOException e1) {
                             throw new AlgebricksException(e1.getMessage());
                         }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLengthDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLengthDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLengthDescriptor.java
index 5a6c1a0..f3d9d0e 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLengthDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLengthDescriptor.java
@@ -34,10 +34,12 @@ import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
-import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.data.std.api.IPointable;
+import org.apache.hyracks.data.std.primitive.VoidPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 import org.apache.hyracks.util.string.UTF8StringUtil;
@@ -52,17 +54,18 @@ public class StringLengthDescriptor extends AbstractScalarFunctionDynamicDescrip
     };
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
-        return new ICopyEvaluatorFactory() {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
+        return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
-                return new ICopyEvaluator() {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+                return new IScalarEvaluator() {
                     private AMutableInt64 result = new AMutableInt64(0);
-                    private DataOutput out = output.getDataOutput();
-                    private ArrayBackedValueStorage outInput = new ArrayBackedValueStorage();
-                    private ICopyEvaluator eval = args[0].createEvaluator(outInput);
+                    private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+                    private DataOutput out = resultStorage.getDataOutput();
+                    private IPointable inputArg = new VoidPointable();
+                    private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
@@ -71,23 +74,26 @@ public class StringLengthDescriptor extends AbstractScalarFunctionDynamicDescrip
                             .getSerializerDeserializer(BuiltinType.AINT64);
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-
+                    public void evaluate(IFrameTupleReference tuple, IPointable resultPointable)
+                            throws AlgebricksException {
                         try {
-                            outInput.reset();
-                            eval.evaluate(tuple);
-                            byte[] serString = outInput.getByteArray();
-                            if (serString[0] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
-                                int len = UTF8StringUtil.getUTFLength(outInput.getByteArray(), 1);
+                            resultStorage.reset();
+                            eval.evaluate(tuple, inputArg);
+                            byte[] serString = inputArg.getByteArray();
+                            int offset = inputArg.getStartOffset();
+
+                            if (serString[offset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
+                                int len = UTF8StringUtil.getUTFLength(serString, offset + 1);
                                 result.setValue(len);
                                 int64Serde.serialize(result, out);
-                            } else if (serString[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG)
+                            } else if (serString[offset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
                                 nullSerde.serialize(ANull.NULL, out);
-                            else {
+                            } else {
                                 throw new AlgebricksException(AsterixBuiltinFunctions.STRING_LENGTH.getName()
                                         + ": expects input type STRING/NULL but got "
-                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serString[0]));
+                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serString[offset]));
                             }
+                            resultPointable.set(resultStorage);
                         } catch (IOException e1) {
                             throw new AlgebricksException(e1);
                         }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLikeDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLikeDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLikeDescriptor.java
index 3ccba1c..9b2a8b3 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLikeDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLikeDescriptor.java
@@ -18,7 +18,6 @@
  */
 package org.apache.asterix.runtime.evaluators.functions;
 
-import java.io.DataOutput;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -28,9 +27,9 @@ import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ByteArrayAccessibleOutputStream;
 import org.apache.hyracks.data.std.util.UTF8CharSequence;
@@ -45,6 +44,7 @@ public class StringLikeDescriptor extends AbstractScalarFunctionDynamicDescripto
     private static final long serialVersionUID = 1L;
 
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        @Override
         public IFunctionDescriptor createFunctionDescriptor() {
             return new StringLikeDescriptor();
         }
@@ -56,17 +56,16 @@ public class StringLikeDescriptor extends AbstractScalarFunctionDynamicDescripto
     }
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
+            throws AlgebricksException {
 
-        return new ICopyEvaluatorFactory() {
+        return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public ICopyEvaluator createEvaluator(IDataOutputProvider output) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
 
-                final DataOutput dout = output.getDataOutput();
-
-                return new AbstractBinaryStringBoolEval(dout, args[0], args[1],
+                return new AbstractBinaryStringBoolEval(ctx, args[0], args[1],
                         AsterixBuiltinFunctions.STRING_MATCHES) {
 
                     private Pattern pattern = null;
@@ -103,4 +102,3 @@ public class StringLikeDescriptor extends AbstractScalarFunctionDynamicDescripto
     }
 
 };
-

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLowerCaseDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLowerCaseDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLowerCaseDescriptor.java
index 7ae1e89..c025947 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLowerCaseDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringLowerCaseDescriptor.java
@@ -32,11 +32,13 @@ import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
-import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.data.std.api.IPointable;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
+import org.apache.hyracks.data.std.primitive.VoidPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.data.std.util.GrowableArray;
 import org.apache.hyracks.data.std.util.UTF8StringBuilder;
@@ -53,17 +55,18 @@ public class StringLowerCaseDescriptor extends AbstractScalarFunctionDynamicDesc
     };
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
-        return new ICopyEvaluatorFactory() {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
+        return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
-                return new ICopyEvaluator() {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+                return new IScalarEvaluator() {
 
-                    private final DataOutput out = output.getDataOutput();
-                    private final ArrayBackedValueStorage outInput = new ArrayBackedValueStorage();
-                    private final ICopyEvaluator eval = args[0].createEvaluator(outInput);
+                    private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+                    private final DataOutput out = resultStorage.getDataOutput();
+                    private final IPointable inputArg = new VoidPointable();
+                    private final IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
 
                     private final GrowableArray array = new GrowableArray();
                     private final UTF8StringBuilder builder = new UTF8StringBuilder();
@@ -74,26 +77,30 @@ public class StringLowerCaseDescriptor extends AbstractScalarFunctionDynamicDesc
                             .getSerializerDeserializer(BuiltinType.ANULL);
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
 
                         try {
-                            outInput.reset();
-                            eval.evaluate(tuple);
-                            byte[] serString = outInput.getByteArray();
+                            resultStorage.reset();
+                            eval.evaluate(tuple, inputArg);
+                            byte[] serString = inputArg.getByteArray();
+                            int offset = inputArg.getStartOffset();
+                            int len = inputArg.getLength() - 1;
 
-                            if (serString[0] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
-                                string.set(serString, 1, serString.length);
+                            if (serString[offset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
+                                string.set(serString, offset + 1, len - 1);
                                 array.reset();
                                 UTF8StringPointable.lowercase(string, builder, array);
 
                                 out.writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                                 out.write(array.getByteArray(), 0, array.getLength());
-                            } else if (serString[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG)
+                            } else if (serString[offset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
                                 nullSerde.serialize(ANull.NULL, out);
-                            else
+                            } else {
                                 throw new AlgebricksException(AsterixBuiltinFunctions.STRING_LOWERCASE.getName()
                                         + ": expects input type STRING/NULL but got "
-                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serString[0]));
+                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serString[offset]));
+                            }
+                            result.set(resultStorage);
                         } catch (IOException e1) {
                             throw new AlgebricksException(e1);
                         }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringMatchesDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringMatchesDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringMatchesDescriptor.java
index 0b8477c..5551942 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringMatchesDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringMatchesDescriptor.java
@@ -18,7 +18,6 @@
  */
 package org.apache.asterix.runtime.evaluators.functions;
 
-import java.io.DataOutput;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -28,9 +27,9 @@ import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ByteArrayAccessibleOutputStream;
 import org.apache.hyracks.data.std.util.UTF8CharSequence;
@@ -39,23 +38,23 @@ public class StringMatchesDescriptor extends AbstractScalarFunctionDynamicDescri
     private static final long serialVersionUID = 1L;
 
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        @Override
         public IFunctionDescriptor createFunctionDescriptor() {
             return new StringMatchesDescriptor();
         }
     };
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
+            throws AlgebricksException {
 
-        return new ICopyEvaluatorFactory() {
+        return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public ICopyEvaluator createEvaluator(IDataOutputProvider output) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
 
-                DataOutput dout = output.getDataOutput();
-
-                return new AbstractBinaryStringBoolEval(dout, args[0], args[1],
+                return new AbstractBinaryStringBoolEval(ctx, args[0], args[1],
                         AsterixBuiltinFunctions.STRING_MATCHES) {
 
                     private Pattern pattern = null;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringMatchesWithFlagDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringMatchesWithFlagDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringMatchesWithFlagDescriptor.java
index e4129a3..10de2e4 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringMatchesWithFlagDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringMatchesWithFlagDescriptor.java
@@ -22,7 +22,6 @@
  */
 package org.apache.asterix.runtime.evaluators.functions;
 
-import java.io.DataOutput;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -32,9 +31,9 @@ import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ByteArrayAccessibleOutputStream;
 import org.apache.hyracks.data.std.util.UTF8CharSequence;
@@ -43,24 +42,24 @@ public class StringMatchesWithFlagDescriptor extends AbstractScalarFunctionDynam
 
     private static final long serialVersionUID = 1L;
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        @Override
         public IFunctionDescriptor createFunctionDescriptor() {
             return new StringMatchesWithFlagDescriptor();
         }
     };
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
+            throws AlgebricksException {
 
-        return new ICopyEvaluatorFactory() {
+        return new IScalarEvaluatorFactory() {
 
             private static final long serialVersionUID = 1L;
 
             @Override
-            public ICopyEvaluator createEvaluator(IDataOutputProvider output) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
 
-                DataOutput dout = output.getDataOutput();
-
-                return new AbstractTripleStringBoolEval(dout, args[0], args[1], args[2],
+                return new AbstractTripleStringBoolEval(ctx, args[0], args[1], args[2],
                         AsterixBuiltinFunctions.STRING_MATCHES_WITH_FLAG) {
                     private Pattern pattern = null;
                     private Matcher matcher = null;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringReplaceDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringReplaceDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringReplaceDescriptor.java
index a43f1a4..eec9f41 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringReplaceDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringReplaceDescriptor.java
@@ -18,7 +18,6 @@
  */
 package org.apache.asterix.runtime.evaluators.functions;
 
-import java.io.DataOutput;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -28,9 +27,9 @@ import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ByteArrayAccessibleOutputStream;
 import org.apache.hyracks.data.std.util.UTF8CharSequence;
@@ -39,24 +38,24 @@ public class StringReplaceDescriptor extends AbstractScalarFunctionDynamicDescri
 
     private static final long serialVersionUID = 1L;
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        @Override
         public IFunctionDescriptor createFunctionDescriptor() {
             return new StringReplaceDescriptor();
         }
     };
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
+            throws AlgebricksException {
 
-        return new ICopyEvaluatorFactory() {
+        return new IScalarEvaluatorFactory() {
 
             private static final long serialVersionUID = 1L;
 
             @Override
-            public ICopyEvaluator createEvaluator(IDataOutputProvider output) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
 
-                DataOutput dout = output.getDataOutput();
-
-                return new AbstractTripleStringStringEval(dout, args[0], args[1], args[2],
+                return new AbstractTripleStringStringEval(ctx, args[0], args[1], args[2],
                         AsterixBuiltinFunctions.STRING_REPLACE) {
 
                     private Pattern pattern = null;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringReplaceWithFlagsDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringReplaceWithFlagsDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringReplaceWithFlagsDescriptor.java
index 1511d0d..a65b437 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringReplaceWithFlagsDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringReplaceWithFlagsDescriptor.java
@@ -18,7 +18,6 @@
  */
 package org.apache.asterix.runtime.evaluators.functions;
 
-import java.io.DataOutput;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -28,9 +27,9 @@ import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.data.std.util.ByteArrayAccessibleOutputStream;
 import org.apache.hyracks.data.std.util.UTF8CharSequence;
@@ -39,24 +38,24 @@ public class StringReplaceWithFlagsDescriptor extends AbstractScalarFunctionDyna
 
     private static final long serialVersionUID = 1L;
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        @Override
         public IFunctionDescriptor createFunctionDescriptor() {
             return new StringReplaceWithFlagsDescriptor();
         }
     };
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
+            throws AlgebricksException {
 
-        return new ICopyEvaluatorFactory() {
+        return new IScalarEvaluatorFactory() {
 
             private static final long serialVersionUID = 1L;
 
             @Override
-            public ICopyEvaluator createEvaluator(IDataOutputProvider output) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
 
-                DataOutput dout = output.getDataOutput();
-
-                return new AbstractQuadStringStringEval(dout, args[0], args[1], args[2], args[3],
+                return new AbstractQuadStringStringEval(ctx, args[0], args[1], args[2], args[3],
                         AsterixBuiltinFunctions.STRING_REPLACE_WITH_FLAG) {
                     private Pattern pattern = null;
                     private Matcher matcher = null;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringStartsWithDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringStartsWithDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringStartsWithDescriptor.java
index 8fcca3c..c3d80d4 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringStartsWithDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringStartsWithDescriptor.java
@@ -18,40 +18,38 @@
  */
 package org.apache.asterix.runtime.evaluators.functions;
 
-import java.io.DataOutput;
-
 import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 
 public class StringStartsWithDescriptor extends AbstractScalarFunctionDynamicDescriptor {
     private static final long serialVersionUID = 1L;
 
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        @Override
         public IFunctionDescriptor createFunctionDescriptor() {
             return new StringStartsWithDescriptor();
         }
     };
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
+            throws AlgebricksException {
 
-        return new ICopyEvaluatorFactory() {
+        return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public ICopyEvaluator createEvaluator(IDataOutputProvider output) throws AlgebricksException {
-
-                DataOutput dout = output.getDataOutput();
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
 
-                return new AbstractBinaryStringBoolEval(dout, args[0], args[1],
+                return new AbstractBinaryStringBoolEval(ctx, args[0], args[1],
                         AsterixBuiltinFunctions.STRING_STARTS_WITH) {
 
                     @Override

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringToCodePointDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringToCodePointDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringToCodePointDescriptor.java
index f75b8e3..f0c2330 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringToCodePointDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringToCodePointDescriptor.java
@@ -35,10 +35,12 @@ import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
-import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.data.std.api.IPointable;
+import org.apache.hyracks.data.std.primitive.VoidPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 import org.apache.hyracks.util.string.UTF8StringUtil;
@@ -55,16 +57,17 @@ public class StringToCodePointDescriptor extends AbstractScalarFunctionDynamicDe
     };
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
-        return new ICopyEvaluatorFactory() {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
+        return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
-                return new ICopyEvaluator() {
-                    protected final DataOutput out = output.getDataOutput();;
-                    protected final ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
-                    protected final ICopyEvaluator stringEval = args[0].createEvaluator(argOut);
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+                return new IScalarEvaluator() {
+                    protected final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+                    protected final DataOutput out = resultStorage.getDataOutput();
+                    protected final IPointable argPtr = new VoidPointable();
+                    protected final IScalarEvaluator stringEval = args[0].createScalarEvaluator(ctx);
                     protected final AOrderedListType intListType = new AOrderedListType(BuiltinType.AINT64, null);
 
                     private OrderedListBuilder listBuilder = new OrderedListBuilder();
@@ -76,34 +79,35 @@ public class StringToCodePointDescriptor extends AbstractScalarFunctionDynamicDe
                     private final AMutableInt64 aInt64 = new AMutableInt64(0);
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
                         try {
-                            argOut.reset();
-                            stringEval.evaluate(tuple);
-                            byte[] serString = argOut.getByteArray();
+                            resultStorage.reset();
+                            stringEval.evaluate(tuple, argPtr);
+                            byte[] serString = argPtr.getByteArray();
+                            int offset = argPtr.getStartOffset();
 
-                            if (serString[0] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
-                                byte[] bytes = argOut.getByteArray();
-                                int len = UTF8StringUtil.getUTFLength(bytes, 1);
+                            if (serString[offset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
+                                int len = UTF8StringUtil.getUTFLength(serString, offset + 1);
 
-                                int start = 1 + UTF8StringUtil.getNumBytesToStoreLength(len);
+                                int start = offset + 1 + UTF8StringUtil.getNumBytesToStoreLength(len);
                                 int pos = 0;
                                 listBuilder.reset(intListType);
                                 while (pos < len) {
-                                    int codePoint = UTF8StringUtil.UTF8ToCodePoint(bytes, start + pos);
-                                    pos += UTF8StringUtil.charSize(bytes, start + pos);
+                                    int codePoint = UTF8StringUtil.UTF8ToCodePoint(serString, start + pos);
+                                    pos += UTF8StringUtil.charSize(serString, start + pos);
 
                                     inputVal.reset();
                                     aInt64.setValue(codePoint);
                                     int64Serde.serialize(aInt64, inputVal.getDataOutput());
                                     listBuilder.addItem(inputVal);
-
                                 }
                                 listBuilder.write(out, true);
-                            } else
+                            } else {
                                 throw new AlgebricksException(AsterixBuiltinFunctions.STRING_TO_CODEPOINT.getName()
                                         + ": expects input type STRING but got "
-                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serString[0]));
+                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serString[offset]));
+                            }
+                            result.set(resultStorage);
                         } catch (IOException e1) {
                             throw new AlgebricksException(e1.getMessage());
                         }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringUpperCaseDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringUpperCaseDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringUpperCaseDescriptor.java
index 02e495f..473ee94 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringUpperCaseDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/StringUpperCaseDescriptor.java
@@ -32,11 +32,13 @@ import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
-import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.data.std.api.IPointable;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
+import org.apache.hyracks.data.std.primitive.VoidPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.data.std.util.GrowableArray;
 import org.apache.hyracks.data.std.util.UTF8StringBuilder;
@@ -53,17 +55,18 @@ public class StringUpperCaseDescriptor extends AbstractScalarFunctionDynamicDesc
     };
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
-        return new ICopyEvaluatorFactory() {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
+        return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
-                return new ICopyEvaluator() {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+                return new IScalarEvaluator() {
 
-                    private DataOutput out = output.getDataOutput();
-                    private ArrayBackedValueStorage outInput = new ArrayBackedValueStorage();
-                    private ICopyEvaluator eval = args[0].createEvaluator(outInput);
+                    private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+                    private DataOutput out = resultStorage.getDataOutput();
+                    private IPointable inputArg = new VoidPointable();
+                    private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
 
                     private final byte stt = ATypeTag.SERIALIZED_STRING_TYPE_TAG;
 
@@ -76,26 +79,28 @@ public class StringUpperCaseDescriptor extends AbstractScalarFunctionDynamicDesc
                             .getSerializerDeserializer(BuiltinType.ANULL);
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
                         try {
-                            outInput.reset();
-                            eval.evaluate(tuple);
-                            byte[] serString = outInput.getByteArray();
+                            resultStorage.reset();
+                            eval.evaluate(tuple, inputArg);
+                            byte[] serString = inputArg.getByteArray();
+                            int offset = inputArg.getStartOffset();
 
-                            if (serString[0] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
-                                string.set(serString, 1, serString.length);
+                            if (serString[offset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
+                                string.set(serString, offset + 1, serString.length);
                                 array.reset();
                                 UTF8StringPointable.uppercase(string, builder, array);
 
                                 out.writeByte(stt);
                                 out.write(array.getByteArray(), 0, array.getLength());
-                            } else if (serString[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG)
+                            } else if (serString[offset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
                                 nullSerde.serialize(ANull.NULL, out);
-                            else
+                            } else {
                                 throw new AlgebricksException(AsterixBuiltinFunctions.STRING_UPPERCASE.getName()
                                         + ": expects input type STRING/NULL but got "
-                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serString[0]));
+                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serString[offset]));
+                            }
+                            result.set(resultStorage);
                         } catch (IOException e1) {
                             throw new AlgebricksException(e1);
                         }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/Substring2Descriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/Substring2Descriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/Substring2Descriptor.java
index a3076ce..8abda5f 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/Substring2Descriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/Substring2Descriptor.java
@@ -30,11 +30,13 @@ import org.apache.asterix.om.types.hierachy.ATypeHierarchy;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
 import org.apache.hyracks.api.exceptions.HyracksDataException;
-import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.data.std.api.IPointable;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
+import org.apache.hyracks.data.std.primitive.VoidPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.data.std.util.GrowableArray;
 import org.apache.hyracks.data.std.util.UTF8StringBuilder;
@@ -50,44 +52,49 @@ public class Substring2Descriptor extends AbstractScalarFunctionDynamicDescripto
     };
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
-        return new ICopyEvaluatorFactory() {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
+            throws AlgebricksException {
+        return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
-                return new ICopyEvaluator() {
-
-                    private DataOutput out = output.getDataOutput();
-                    private ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
-                    private ICopyEvaluator evalString = args[0].createEvaluator(argOut);
-                    private ICopyEvaluator evalStart = args[1].createEvaluator(argOut);
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+                return new IScalarEvaluator() {
 
+                    private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+                    private DataOutput out = resultStorage.getDataOutput();
+                    private IPointable argPtr = new VoidPointable();
+                    private IScalarEvaluator evalString = args[0].createScalarEvaluator(ctx);
+                    private IScalarEvaluator evalStart = args[1].createScalarEvaluator(ctx);
                     private final GrowableArray array = new GrowableArray();
                     private final UTF8StringBuilder builder = new UTF8StringBuilder();
                     private final UTF8StringPointable string = new UTF8StringPointable();
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-                        argOut.reset();
-                        evalStart.evaluate(tuple);
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                        resultStorage.reset();
+                        evalStart.evaluate(tuple, argPtr);
                         int start = 0;
 
+                        byte[] bytes = argPtr.getByteArray();
+                        int offset = argPtr.getStartOffset();
+
                         try {
-                            start = ATypeHierarchy.getIntegerValue(argOut.getByteArray(), 0) - 1;
+                            start = ATypeHierarchy.getIntegerValue(bytes, offset) - 1;
                         } catch (HyracksDataException e1) {
                             throw new AlgebricksException(e1);
                         }
-                        argOut.reset();
-                        evalString.evaluate(tuple);
 
-                        byte[] bytes = argOut.getByteArray();
-                        if (bytes[0] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
+                        evalString.evaluate(tuple, argPtr);
+                        bytes = argPtr.getByteArray();
+                        offset = argPtr.getStartOffset();
+                        int len = argPtr.getLength();
+                        if (bytes[offset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                             throw new AlgebricksException(AsterixBuiltinFunctions.SUBSTRING2.getName()
                                     + ": expects type STRING for the first argument but got "
-                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut.getByteArray()[0]));
+                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes[offset]));
                         }
-                        string.set(bytes, 1, bytes.length);
+                        string.set(bytes, offset + 1, len - 1);
                         array.reset();
                         try {
                             UTF8StringPointable.substr(string, start, Integer.MAX_VALUE, builder, array);
@@ -104,6 +111,7 @@ public class Substring2Descriptor extends AbstractScalarFunctionDynamicDescripto
                         } catch (IOException e) {
                             throw new AlgebricksException(e);
                         }
+                        result.set(resultStorage);
                     }
                 };
             }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringAfterDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringAfterDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringAfterDescriptor.java
index 78f5a66..32db2c2 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringAfterDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringAfterDescriptor.java
@@ -29,10 +29,12 @@ import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.data.std.api.IPointable;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
+import org.apache.hyracks.data.std.primitive.VoidPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.data.std.util.GrowableArray;
 import org.apache.hyracks.data.std.util.UTF8StringBuilder;
@@ -48,55 +50,64 @@ public class SubstringAfterDescriptor extends AbstractScalarFunctionDynamicDescr
     };
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
-        return new ICopyEvaluatorFactory() {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
+            throws AlgebricksException {
+        return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
-                return new ICopyEvaluator() {
-
-                    private DataOutput out = output.getDataOutput();
-                    private ArrayBackedValueStorage array0 = new ArrayBackedValueStorage();
-                    private ArrayBackedValueStorage array1 = new ArrayBackedValueStorage();
-                    private ICopyEvaluator evalString = args[0].createEvaluator(array0);
-                    private ICopyEvaluator evalPattern = args[1].createEvaluator(array1);
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+                return new IScalarEvaluator() {
+                    private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+                    private DataOutput out = resultStorage.getDataOutput();
+                    private IPointable array0 = new VoidPointable();
+                    private IPointable array1 = new VoidPointable();
+                    private IScalarEvaluator evalString = args[0].createScalarEvaluator(ctx);
+                    private IScalarEvaluator evalPattern = args[1].createScalarEvaluator(ctx);
                     private final GrowableArray array = new GrowableArray();
                     private final UTF8StringBuilder builder = new UTF8StringBuilder();
                     private final UTF8StringPointable stringPtr = new UTF8StringPointable();
                     private final UTF8StringPointable patternPtr = new UTF8StringPointable();
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-                        array0.reset();
-                        evalString.evaluate(tuple);
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                        resultStorage.reset();
+                        evalString.evaluate(tuple, array0);
                         byte[] src = array0.getByteArray();
-
-                        array1.reset();
-                        evalPattern.evaluate(tuple);
+                        int srcOffset = array0.getStartOffset();
+                        int srcLen = array0.getLength();
+                        evalPattern.evaluate(tuple, array1);
                         byte[] pattern = array1.getByteArray();
+                        int patternOffset = array1.getStartOffset();
+                        int patternLen = array1.getLength();
 
-                        if ((src[0] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
-                                && src[0] != ATypeTag.SERIALIZED_NULL_TYPE_TAG)
-                                || (pattern[0] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
-                                        && pattern[0] != ATypeTag.SERIALIZED_NULL_TYPE_TAG)) {
+                        if ((src[srcOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
+                                && src[srcOffset] != ATypeTag.SERIALIZED_NULL_TYPE_TAG)
+                                || (pattern[patternOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
+                                        && pattern[patternOffset] != ATypeTag.SERIALIZED_NULL_TYPE_TAG)) {
                             throw new AlgebricksException(AsterixBuiltinFunctions.SUBSTRING_AFTER.getName()
                                     + ": expects input type (STRING/NULL, STRING/NULL) but got ("
-                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(src[0]) + ", "
-                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(pattern[0]) + ").");
+                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(src[srcOffset]) + ", "
+                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(pattern[patternOffset]) + ").");
                         }
-
-                        stringPtr.set(src, 1, src.length);
-                        patternPtr.set(pattern, 1, pattern.length);
-                        array.reset();
                         try {
+                            if (src[srcOffset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG
+                                    || pattern[patternOffset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
+                                out.writeByte(ATypeTag.SERIALIZED_NULL_TYPE_TAG);
+                                result.set(resultStorage);
+                                return;
+                            }
+                            stringPtr.set(src, srcOffset + 1, srcLen - 1);
+                            patternPtr.set(pattern, patternOffset + 1, patternLen - 1);
+                            array.reset();
+
                             UTF8StringPointable.substrAfter(stringPtr, patternPtr, builder, array);
                             out.writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                             out.write(array.getByteArray(), 0, array.getLength());
                         } catch (IOException e) {
                             throw new AlgebricksException(e);
                         }
-
+                        result.set(resultStorage);
                     }
                 }
 

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringBeforeDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringBeforeDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringBeforeDescriptor.java
index dd9a91a..f418213 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringBeforeDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringBeforeDescriptor.java
@@ -29,10 +29,12 @@ import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.data.std.api.IPointable;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
+import org.apache.hyracks.data.std.primitive.VoidPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.data.std.util.GrowableArray;
 import org.apache.hyracks.data.std.util.UTF8StringBuilder;
@@ -48,54 +50,66 @@ public class SubstringBeforeDescriptor extends AbstractScalarFunctionDynamicDesc
     };
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
-        return new ICopyEvaluatorFactory() {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
+            throws AlgebricksException {
+        return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
-                return new ICopyEvaluator() {
-                    private DataOutput out = output.getDataOutput();
-                    private ArrayBackedValueStorage array0 = new ArrayBackedValueStorage();
-                    private ArrayBackedValueStorage array1 = new ArrayBackedValueStorage();
-                    private ICopyEvaluator evalString = args[0].createEvaluator(array0);
-                    private ICopyEvaluator evalPattern = args[1].createEvaluator(array1);
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+                return new IScalarEvaluator() {
+
+                    private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+                    private DataOutput out = resultStorage.getDataOutput();
+                    private IPointable array0 = new VoidPointable();
+                    private IPointable array1 = new VoidPointable();
+                    private IScalarEvaluator evalString = args[0].createScalarEvaluator(ctx);
+                    private IScalarEvaluator evalPattern = args[1].createScalarEvaluator(ctx);
                     private final GrowableArray array = new GrowableArray();
                     private final UTF8StringBuilder builder = new UTF8StringBuilder();
                     private final UTF8StringPointable stringPtr = new UTF8StringPointable();
                     private final UTF8StringPointable patternPtr = new UTF8StringPointable();
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-                        array0.reset();
-                        evalString.evaluate(tuple);
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                        resultStorage.reset();
+                        evalString.evaluate(tuple, array0);
                         byte[] src = array0.getByteArray();
+                        int srcOffset = array0.getStartOffset();
+                        int srcLen = array0.getLength();
 
-                        array1.reset();
-                        evalPattern.evaluate(tuple);
+                        evalPattern.evaluate(tuple, array1);
                         byte[] pattern = array1.getByteArray();
+                        int patternOffset = array1.getStartOffset();
+                        int patternLen = array1.getLength();
 
-                        if ((src[0] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
-                                && src[0] != ATypeTag.SERIALIZED_NULL_TYPE_TAG)
-                                || (pattern[0] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
-                                        && pattern[0] != ATypeTag.SERIALIZED_NULL_TYPE_TAG)) {
+                        if ((src[srcOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
+                                && src[srcOffset] != ATypeTag.SERIALIZED_NULL_TYPE_TAG)
+                                || (pattern[patternOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
+                                        && pattern[patternOffset] != ATypeTag.SERIALIZED_NULL_TYPE_TAG)) {
                             throw new AlgebricksException(AsterixBuiltinFunctions.SUBSTRING_BEFORE.getName()
                                     + ": expects input type (STRING/NULL, STRING/NULL) but got ("
-                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(src[0]) + ", "
-                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(pattern[0]) + ").");
+                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(src[srcOffset]) + ", "
+                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(pattern[patternOffset]) + ").");
                         }
 
-                        stringPtr.set(src, 1, src.length);
-                        patternPtr.set(pattern, 1, pattern.length);
-                        array.reset();
                         try {
+                            if (src[srcOffset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG
+                                    || pattern[patternOffset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
+                                out.writeByte(ATypeTag.SERIALIZED_NULL_TYPE_TAG);
+                                result.set(resultStorage);
+                                return;
+                            }
+                            stringPtr.set(src, srcOffset + 1, srcLen - 1);
+                            patternPtr.set(pattern, patternOffset + 1, patternLen - 1);
+                            array.reset();
                             UTF8StringPointable.substrBefore(stringPtr, patternPtr, builder, array);
                             out.writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                             out.write(array.getByteArray(), 0, array.getLength());
                         } catch (IOException e) {
                             throw new AlgebricksException(e);
                         }
-
+                        result.set(resultStorage);
                     }
                 };
             }


Mime
View raw message