asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From buyin...@apache.org
Subject [14/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:43 GMT
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/OpenRecordConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/OpenRecordConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/OpenRecordConstructorDescriptor.java
index 66631d5..af3ba54 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/OpenRecordConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/OpenRecordConstructorDescriptor.java
@@ -20,10 +20,8 @@
 package org.apache.asterix.runtime.evaluators.constructors;
 
 import java.io.DataOutput;
-import java.io.IOException;
 
 import org.apache.asterix.builders.RecordBuilder;
-import org.apache.asterix.common.exceptions.AsterixException;
 import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
@@ -32,10 +30,12 @@ import org.apache.asterix.om.types.ATypeTag;
 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.VoidPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -63,30 +63,32 @@ public class OpenRecordConstructorDescriptor extends AbstractScalarFunctionDynam
     }
 
     @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 {
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
                 int n = args.length / 2;
-                final ICopyEvaluator[] evalNames = new ICopyEvaluator[n];
-                final ICopyEvaluator[] evalFields = new ICopyEvaluator[n];
-                final ArrayBackedValueStorage fieldNameBuffer = new ArrayBackedValueStorage();
-                final ArrayBackedValueStorage fieldValueBuffer = new ArrayBackedValueStorage();
+                final IScalarEvaluator[] evalNames = new IScalarEvaluator[n];
+                final IScalarEvaluator[] evalFields = new IScalarEvaluator[n];
+                final IPointable fieldNamePointable = new VoidPointable();
+                final IPointable fieldValuePointable = new VoidPointable();
                 for (int i = 0; i < n; i++) {
-                    evalNames[i] = args[2 * i].createEvaluator(fieldNameBuffer);
-                    evalFields[i] = args[2 * i + 1].createEvaluator(fieldValueBuffer);
+                    evalNames[i] = args[2 * i].createScalarEvaluator(ctx);
+                    evalFields[i] = args[2 * i + 1].createScalarEvaluator(ctx);
                 }
-                final DataOutput out = output.getDataOutput();
-                return new ICopyEvaluator() {
+                final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+                final DataOutput out = resultStorage.getDataOutput();
+                return new IScalarEvaluator() {
                     private RecordBuilder recBuilder = new RecordBuilder();
                     private int closedFieldId;
                     private boolean first = true;
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
                         try {
+                            resultStorage.reset();
                             closedFieldId = 0;
                             if (first) {
                                 first = false;
@@ -94,20 +96,20 @@ public class OpenRecordConstructorDescriptor extends AbstractScalarFunctionDynam
                             }
                             recBuilder.init();
                             for (int i = 0; i < evalFields.length; i++) {
-                                fieldValueBuffer.reset();
-                                evalFields[i].evaluate(tuple);
+                                evalFields[i].evaluate(tuple, fieldValuePointable);
                                 if (openFields[i]) {
-                                    fieldNameBuffer.reset();
-                                    evalNames[i].evaluate(tuple);
-                                    recBuilder.addField(fieldNameBuffer, fieldValueBuffer);
+                                    evalNames[i].evaluate(tuple, fieldNamePointable);
+                                    recBuilder.addField(fieldNamePointable, fieldValuePointable);
                                 } else {
-                                    if (fieldValueBuffer.getByteArray()[0] != ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
-                                        recBuilder.addField(closedFieldId, fieldValueBuffer);
+                                    if (fieldValuePointable.getByteArray()[fieldValuePointable
+                                            .getStartOffset()] != ATypeTag.NULL.serialize()) {
+                                        recBuilder.addField(closedFieldId, fieldValuePointable);
                                     }
                                     closedFieldId++;
                                 }
                             }
                             recBuilder.write(out, true);
+                            result.set(resultStorage);
                         } catch (HyracksDataException e) {
                             throw new AlgebricksException(e);
                         }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractBinaryStringBoolEval.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractBinaryStringBoolEval.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractBinaryStringBoolEval.java
index a6f9183..4a5c59a 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractBinaryStringBoolEval.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractBinaryStringBoolEval.java
@@ -28,20 +28,26 @@ import org.apache.asterix.om.types.BuiltinType;
 import org.apache.asterix.om.types.EnumDeserializer;
 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.api.exceptions.HyracksDataException;
+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.dataflow.common.data.accessors.IFrameTupleReference;
 
-public abstract class AbstractBinaryStringBoolEval implements ICopyEvaluator {
-    private DataOutput dout;
-    private ArrayBackedValueStorage array0 = new ArrayBackedValueStorage();
-    private ArrayBackedValueStorage array1 = new ArrayBackedValueStorage();
-    private ICopyEvaluator evalLeft;
-    private ICopyEvaluator evalRight;
+public abstract class AbstractBinaryStringBoolEval implements IScalarEvaluator {
+
+    private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+    private DataOutput dout = resultStorage.getDataOutput();
+
+    private IPointable ptr0 = new VoidPointable();
+    private IPointable ptr1 = new VoidPointable();
+    private IScalarEvaluator evalLeft;
+    private IScalarEvaluator evalRight;
     private final FunctionIdentifier funcID;
 
     private final UTF8StringPointable leftPtr = new UTF8StringPointable();
@@ -54,39 +60,45 @@ public abstract class AbstractBinaryStringBoolEval implements ICopyEvaluator {
     private final ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
             .getSerializerDeserializer(BuiltinType.ANULL);
 
-    public AbstractBinaryStringBoolEval(DataOutput dout, ICopyEvaluatorFactory evalLeftFactory,
-            ICopyEvaluatorFactory evalRightFactory, FunctionIdentifier funcID) throws AlgebricksException {
-        this.dout = dout;
-        this.evalLeft = evalLeftFactory.createEvaluator(array0);
-        this.evalRight = evalRightFactory.createEvaluator(array1);
+    public AbstractBinaryStringBoolEval(IHyracksTaskContext context, IScalarEvaluatorFactory evalLeftFactory,
+            IScalarEvaluatorFactory evalRightFactory, FunctionIdentifier funcID) throws AlgebricksException {
+        this.evalLeft = evalLeftFactory.createScalarEvaluator(context);
+        this.evalRight = evalRightFactory.createScalarEvaluator(context);
         this.funcID = funcID;
     }
 
     @SuppressWarnings("unchecked")
     @Override
-    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-        array0.reset();
-        evalLeft.evaluate(tuple);
-        array1.reset();
-        evalRight.evaluate(tuple);
+    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+        evalLeft.evaluate(tuple, ptr0);
+        evalRight.evaluate(tuple, ptr1);
+
+        byte[] bytes0 = ptr0.getByteArray();
+        int offset0 = ptr0.getStartOffset();
+        int len0 = ptr0.getLength();
+        byte[] bytes1 = ptr1.getByteArray();
+        int offset1 = ptr1.getStartOffset();
+        int len1 = ptr1.getLength();
 
+        resultStorage.reset();
         try {
-            if (array0.getByteArray()[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG
-                    || array1.getByteArray()[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
+            if (bytes0[offset0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG
+                    || bytes1[offset1] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
                 nullSerde.serialize(ANull.NULL, dout);
+                result.set(resultStorage);
                 return;
-            } else if (array0.getByteArray()[0] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
-                    || array1.getByteArray()[0] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
+            } else if (bytes0[offset0] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
+                    || bytes1[offset1] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                 throw new AlgebricksException(funcID.getName() + ": expects input type STRING or NULL, but got "
-                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(array0.getByteArray()[0]) + " and "
-                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(array1.getByteArray()[0]) + ")!");
+                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes0[offset0]) + " and "
+                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes1[offset1]) + ")!");
             }
         } catch (HyracksDataException e) {
             throw new AlgebricksException(e);
         }
 
-        leftPtr.set(array0.getByteArray(), array0.getStartOffset() + 1, array0.getLength());
-        rightPtr.set(array1.getByteArray(), array1.getStartOffset() + 1, array1.getLength());
+        leftPtr.set(bytes0, offset0 + 1, len0 - 1);
+        rightPtr.set(bytes1, offset1 + 1, len1 - 1);
 
         ABoolean res = compute(leftPtr, rightPtr) ? ABoolean.TRUE : ABoolean.FALSE;
         try {
@@ -94,6 +106,7 @@ public abstract class AbstractBinaryStringBoolEval implements ICopyEvaluator {
         } catch (HyracksDataException e) {
             throw new AlgebricksException(e);
         }
+        result.set(resultStorage);
     }
 
     protected abstract boolean compute(UTF8StringPointable left, UTF8StringPointable right) throws AlgebricksException;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractNumericArithmeticEval.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractNumericArithmeticEval.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractNumericArithmeticEval.java
index 780ec99..0d262fb 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractNumericArithmeticEval.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractNumericArithmeticEval.java
@@ -51,11 +51,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.common.exceptions.NotImplementedException;
-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.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.VoidPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -76,8 +78,8 @@ public abstract class AbstractNumericArithmeticEval extends AbstractScalarFuncti
      * @return
      * @throws HyracksDataException
      */
-    abstract protected long evaluateTimeDurationArithmetic(long chronon, int yearMonth, long dayTime, boolean isTimeOnly)
-            throws HyracksDataException;
+    abstract protected long evaluateTimeDurationArithmetic(long chronon, int yearMonth, long dayTime,
+            boolean isTimeOnly) throws HyracksDataException;
 
     /**
      * abstract method for arithmetic operation between two time instances (date/time/datetime)
@@ -90,20 +92,21 @@ public abstract class AbstractNumericArithmeticEval extends AbstractScalarFuncti
     abstract protected long evaluateTimeInstanceArithmetic(long chronon0, long chronon1) throws HyracksDataException;
 
     @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();
-                    // one temp. buffer re-used by both children
-                    private ArrayBackedValueStorage argOut0 = new ArrayBackedValueStorage();
-                    private ArrayBackedValueStorage argOut1 = new ArrayBackedValueStorage();
-                    private ICopyEvaluator evalLeft = args[0].createEvaluator(argOut0);
-                    private ICopyEvaluator evalRight = args[1].createEvaluator(argOut1);
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
+
+                return new IScalarEvaluator() {
+                    private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+                    private DataOutput out = resultStorage.getDataOutput();
+                    private IPointable argPtr0 = new VoidPointable();
+                    private IPointable argPtr1 = new VoidPointable();
+                    private IScalarEvaluator evalLeft = args[0].createScalarEvaluator(ctx);
+                    private IScalarEvaluator evalRight = args[1].createScalarEvaluator(ctx);
                     private double[] operandsFloating = new double[args.length];
                     private long[] operandsInteger = new long[args.length];
                     private int resultType;
@@ -132,66 +135,60 @@ public abstract class AbstractNumericArithmeticEval extends AbstractScalarFuncti
 
                     @SuppressWarnings("unchecked")
                     @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
 
                         try {
+                            resultStorage.reset();
                             resultType = 0;
                             int currentType = 0;
                             for (int i = 0; i < args.length; i++) {
-                                ArrayBackedValueStorage argOut;
+                                IPointable argPtr;
                                 if (i == 0) {
-                                    argOut0.reset();
-                                    evalLeft.evaluate(tuple);
-                                    argOut = argOut0;
+                                    evalLeft.evaluate(tuple, argPtr0);
+                                    argPtr = argPtr0;
                                 } else {
-                                    argOut1.reset();
-                                    evalRight.evaluate(tuple);
-                                    argOut = argOut1;
+                                    evalRight.evaluate(tuple, argPtr1);
+                                    argPtr = argPtr1;
                                 }
-                                typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut.getByteArray()[0]);
+
+                                byte[] bytes = argPtr.getByteArray();
+                                int offset = argPtr.getStartOffset();
+
+                                typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes[offset]);
                                 switch (typeTag) {
                                     case INT8: {
                                         currentType = typeInt8;
-                                        operandsInteger[i] = AInt8SerializerDeserializer.getByte(argOut.getByteArray(),
-                                                1);
-                                        operandsFloating[i] = AInt8SerializerDeserializer.getByte(
-                                                argOut.getByteArray(), 1);
+                                        operandsInteger[i] = AInt8SerializerDeserializer.getByte(bytes, offset + 1);
+                                        operandsFloating[i] = operandsInteger[i];
                                         break;
                                     }
                                     case INT16: {
                                         currentType = typeInt16;
-                                        operandsInteger[i] = AInt16SerializerDeserializer.getShort(
-                                                argOut.getByteArray(), 1);
-                                        operandsFloating[i] = AInt16SerializerDeserializer.getShort(
-                                                argOut.getByteArray(), 1);
+                                        operandsInteger[i] = AInt16SerializerDeserializer.getShort(bytes, offset + 1);
+                                        operandsFloating[i] = operandsInteger[i];
                                         break;
                                     }
                                     case INT32: {
                                         currentType = typeInt32;
-                                        operandsInteger[i] = AInt32SerializerDeserializer.getInt(argOut.getByteArray(),
-                                                1);
-                                        operandsFloating[i] = AInt32SerializerDeserializer.getInt(
-                                                argOut.getByteArray(), 1);
+                                        operandsInteger[i] = AInt32SerializerDeserializer.getInt(bytes, offset + 1);
+                                        operandsFloating[i] = operandsInteger[i];
                                         break;
                                     }
                                     case INT64: {
                                         currentType = typeInt64;
-                                        operandsInteger[i] = AInt64SerializerDeserializer.getLong(
-                                                argOut.getByteArray(), 1);
-                                        operandsFloating[i] = AInt64SerializerDeserializer.getLong(
-                                                argOut.getByteArray(), 1);
+                                        operandsInteger[i] = AInt64SerializerDeserializer.getLong(bytes, offset + 1);
+                                        operandsFloating[i] = operandsInteger[i];
                                         break;
                                     }
                                     case FLOAT: {
                                         currentType = typeFloat;
-                                        operandsFloating[i] = AFloatSerializerDeserializer.getFloat(
-                                                argOut.getByteArray(), 1);
+                                        operandsFloating[i] = AFloatSerializerDeserializer.getFloat(bytes, offset + 1);
                                         break;
                                     }
                                     case DOUBLE: {
                                         currentType = typeDouble;
-                                        operandsFloating[i] = ADoubleSerializerDeserializer.getDouble(
-                                                argOut.getByteArray(), 1);
+                                        operandsFloating[i] = ADoubleSerializerDeserializer.getDouble(bytes,
+                                                offset + 1);
                                         break;
                                     }
                                     case DATE:
@@ -201,19 +198,20 @@ public abstract class AbstractNumericArithmeticEval extends AbstractScalarFuncti
                                     case YEARMONTHDURATION:
                                     case DAYTIMEDURATION:
                                         evaluateTemporalArthmeticOperation(typeTag, tuple);
+                                        result.set(resultStorage);
                                         return;
                                     case NULL: {
                                         serde = AqlSerializerDeserializerProvider.INSTANCE
                                                 .getSerializerDeserializer(BuiltinType.ANULL);
                                         serde.serialize(ANull.NULL, out);
+                                        result.set(resultStorage);
                                         return;
                                     }
                                     default: {
                                         throw new NotImplementedException(getIdentifier().getName()
                                                 + (i == 0 ? ": Left" : ": Right")
                                                 + " operand expects INT8/INT16/INT32/INT64/FLOAT/DOUBLE/NULL, but got "
-                                                + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut
-                                                        .getByteArray()[0]));
+                                                + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes[offset]));
                                     }
                                 }
 
@@ -291,6 +289,7 @@ public abstract class AbstractNumericArithmeticEval extends AbstractScalarFuncti
                                     serde.serialize(aDouble, out);
                                     break;
                             }
+                            result.set(resultStorage);
                         } catch (HyracksDataException hde) {
                             throw new AlgebricksException(hde);
                         }
@@ -299,10 +298,12 @@ public abstract class AbstractNumericArithmeticEval extends AbstractScalarFuncti
                     @SuppressWarnings("unchecked")
                     private void evaluateTemporalArthmeticOperation(ATypeTag leftType, IFrameTupleReference tuple)
                             throws HyracksDataException, AlgebricksException {
-                        argOut1.reset();
-                        evalRight.evaluate(tuple);
-                        ATypeTag rightType = EnumDeserializer.ATYPETAGDESERIALIZER
-                                .deserialize(argOut1.getByteArray()[0]);
+                        evalRight.evaluate(tuple, argPtr1);
+                        byte[] bytes1 = argPtr1.getByteArray();
+                        int offset1 = argPtr1.getStartOffset();
+                        ATypeTag rightType = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes1[offset1]);
+                        byte[] bytes0 = argPtr0.getByteArray();
+                        int offset0 = argPtr0.getStartOffset();
 
                         if (leftType == ATypeTag.NULL || rightType == ATypeTag.NULL) {
                             serde = AqlSerializerDeserializerProvider.INSTANCE
@@ -322,33 +323,30 @@ public abstract class AbstractNumericArithmeticEval extends AbstractScalarFuncti
 
                             switch (leftType) {
                                 case DATE:
-                                    leftChronon = ADateSerializerDeserializer.getChronon(argOut0.getByteArray(), 1)
+                                    leftChronon = ADateSerializerDeserializer.getChronon(bytes0, offset0 + 1)
                                             * GregorianCalendarSystem.CHRONON_OF_DAY;
-                                    rightChronon = ADateSerializerDeserializer.getChronon(argOut1.getByteArray(), 1)
+                                    rightChronon = ADateSerializerDeserializer.getChronon(bytes1, offset1 + 1)
                                             * GregorianCalendarSystem.CHRONON_OF_DAY;
 
                                     break;
                                 case TIME:
-                                    leftChronon = ATimeSerializerDeserializer.getChronon(argOut0.getByteArray(), 1);
-                                    rightChronon = ATimeSerializerDeserializer.getChronon(argOut1.getByteArray(), 1);
+                                    leftChronon = ATimeSerializerDeserializer.getChronon(bytes0, offset0 + 1);
+                                    rightChronon = ATimeSerializerDeserializer.getChronon(bytes1, offset1 + 1);
                                     break;
                                 case DATETIME:
-                                    leftChronon = ADateTimeSerializerDeserializer.getChronon(argOut0.getByteArray(), 1);
-                                    rightChronon = ADateTimeSerializerDeserializer
-                                            .getChronon(argOut1.getByteArray(), 1);
+                                    leftChronon = ADateTimeSerializerDeserializer.getChronon(bytes0, offset0 + 1);
+                                    rightChronon = ADateTimeSerializerDeserializer.getChronon(bytes1, offset1 + 1);
                                     break;
                                 case YEARMONTHDURATION:
                                     yearMonth = (int) evaluateTimeInstanceArithmetic(
-                                            AYearMonthDurationSerializerDeserializer.getYearMonth(
-                                                    argOut0.getByteArray(), 1),
-                                            AYearMonthDurationSerializerDeserializer.getYearMonth(
-                                                    argOut1.getByteArray(), 1));
+                                            AYearMonthDurationSerializerDeserializer.getYearMonth(bytes0, offset0 + 1),
+                                            AYearMonthDurationSerializerDeserializer.getYearMonth(bytes1, offset1 + 1));
                                     break;
                                 case DAYTIMEDURATION:
-                                    leftChronon = ADayTimeDurationSerializerDeserializer.getDayTime(
-                                            argOut0.getByteArray(), 1);
-                                    rightChronon = ADayTimeDurationSerializerDeserializer.getDayTime(
-                                            argOut1.getByteArray(), 1);
+                                    leftChronon = ADayTimeDurationSerializerDeserializer.getDayTime(bytes0,
+                                            offset0 + 1);
+                                    rightChronon = ADayTimeDurationSerializerDeserializer.getDayTime(bytes1,
+                                            offset1 + 1);
                                     break;
                                 default:
                                     throw new NotImplementedException();
@@ -371,19 +369,18 @@ public abstract class AbstractNumericArithmeticEval extends AbstractScalarFuncti
                                 case TIME:
                                     serde = AqlSerializerDeserializerProvider.INSTANCE
                                             .getSerializerDeserializer(BuiltinType.ATIME);
-                                    chronon = ATimeSerializerDeserializer.getChronon(argOut0.getByteArray(), 1);
+                                    chronon = ATimeSerializerDeserializer.getChronon(bytes0, offset0 + 1);
                                     isTimeOnly = true;
                                     resultType = ATypeTag.TIME;
                                     switch (rightType) {
                                         case DAYTIMEDURATION:
-                                            dayTime = ADayTimeDurationSerializerDeserializer.getDayTime(
-                                                    argOut1.getByteArray(), 1);
+                                            dayTime = ADayTimeDurationSerializerDeserializer.getDayTime(bytes1,
+                                                    offset1 + 1);
                                             break;
                                         case DURATION:
-                                            dayTime = ADurationSerializerDeserializer.getDayTime(
-                                                    argOut1.getByteArray(), 1);
-                                            yearMonth = ADurationSerializerDeserializer.getYearMonth(
-                                                    argOut1.getByteArray(), 1);
+                                            dayTime = ADurationSerializerDeserializer.getDayTime(bytes1, offset1 + 1);
+                                            yearMonth = ADurationSerializerDeserializer.getYearMonth(bytes1,
+                                                    offset1 + 1);
                                             break;
                                         default:
                                             throw new NotImplementedException(getIdentifier().getName()
@@ -395,29 +392,28 @@ public abstract class AbstractNumericArithmeticEval extends AbstractScalarFuncti
                                     serde = AqlSerializerDeserializerProvider.INSTANCE
                                             .getSerializerDeserializer(BuiltinType.ADATE);
                                     resultType = ATypeTag.DATE;
-                                    chronon = ADateSerializerDeserializer.getChronon(argOut0.getByteArray(), 1)
+                                    chronon = ADateSerializerDeserializer.getChronon(bytes0, offset0 + 1)
                                             * GregorianCalendarSystem.CHRONON_OF_DAY;
                                 case DATETIME:
                                     if (leftType == ATypeTag.DATETIME) {
                                         serde = AqlSerializerDeserializerProvider.INSTANCE
                                                 .getSerializerDeserializer(BuiltinType.ADATETIME);
                                         resultType = ATypeTag.DATETIME;
-                                        chronon = ADateTimeSerializerDeserializer.getChronon(argOut0.getByteArray(), 1);
+                                        chronon = ADateTimeSerializerDeserializer.getChronon(bytes0, offset0 + 1);
                                     }
                                     switch (rightType) {
                                         case DURATION:
-                                            yearMonth = ADurationSerializerDeserializer.getYearMonth(
-                                                    argOut1.getByteArray(), 1);
-                                            dayTime = ADurationSerializerDeserializer.getDayTime(
-                                                    argOut1.getByteArray(), 1);
+                                            yearMonth = ADurationSerializerDeserializer.getYearMonth(bytes1,
+                                                    offset1 + 1);
+                                            dayTime = ADurationSerializerDeserializer.getDayTime(bytes1, offset1 + 1);
                                             break;
                                         case YEARMONTHDURATION:
-                                            yearMonth = AYearMonthDurationSerializerDeserializer.getYearMonth(
-                                                    argOut1.getByteArray(), 1);
+                                            yearMonth = AYearMonthDurationSerializerDeserializer.getYearMonth(bytes1,
+                                                    offset1 + 1);
                                             break;
                                         case DAYTIMEDURATION:
-                                            dayTime = ADayTimeDurationSerializerDeserializer.getDayTime(
-                                                    argOut1.getByteArray(), 1);
+                                            dayTime = ADayTimeDurationSerializerDeserializer.getDayTime(bytes1,
+                                                    offset1 + 1);
                                             break;
                                         default:
                                             throw new NotImplementedException(getIdentifier().getName()
@@ -426,21 +422,20 @@ public abstract class AbstractNumericArithmeticEval extends AbstractScalarFuncti
                                     }
                                     break;
                                 case YEARMONTHDURATION:
-                                    yearMonth = AYearMonthDurationSerializerDeserializer.getYearMonth(
-                                            argOut0.getByteArray(), 1);
+                                    yearMonth = AYearMonthDurationSerializerDeserializer.getYearMonth(bytes0,
+                                            offset0 + 1);
                                     switch (rightType) {
                                         case DATETIME:
                                             serde = AqlSerializerDeserializerProvider.INSTANCE
                                                     .getSerializerDeserializer(BuiltinType.ADATETIME);
                                             resultType = ATypeTag.DATETIME;
-                                            chronon = ADateTimeSerializerDeserializer.getChronon(
-                                                    argOut1.getByteArray(), 1);
+                                            chronon = ADateTimeSerializerDeserializer.getChronon(bytes1, offset1 + 1);
                                             break;
                                         case DATE:
                                             serde = AqlSerializerDeserializerProvider.INSTANCE
                                                     .getSerializerDeserializer(BuiltinType.ADATE);
                                             resultType = ATypeTag.DATE;
-                                            chronon = ADateSerializerDeserializer.getChronon(argOut1.getByteArray(), 1)
+                                            chronon = ADateSerializerDeserializer.getChronon(bytes1, offset1 + 1)
                                                     * GregorianCalendarSystem.CHRONON_OF_DAY;
                                             break;
                                         default:
@@ -450,26 +445,25 @@ public abstract class AbstractNumericArithmeticEval extends AbstractScalarFuncti
                                     }
                                     break;
                                 case DURATION:
-                                    yearMonth = ADurationSerializerDeserializer.getYearMonth(argOut0.getByteArray(), 1);
-                                    dayTime = ADurationSerializerDeserializer.getDayTime(argOut0.getByteArray(), 1);
+                                    yearMonth = ADurationSerializerDeserializer.getYearMonth(bytes0, offset0 + 1);
+                                    dayTime = ADurationSerializerDeserializer.getDayTime(bytes0, offset0 + 1);
                                 case DAYTIMEDURATION:
                                     if (leftType == ATypeTag.DAYTIMEDURATION) {
-                                        dayTime = ADayTimeDurationSerializerDeserializer.getDayTime(
-                                                argOut0.getByteArray(), 1);
+                                        dayTime = ADayTimeDurationSerializerDeserializer.getDayTime(bytes0,
+                                                offset0 + 1);
                                     }
                                     switch (rightType) {
                                         case DATETIME:
                                             serde = AqlSerializerDeserializerProvider.INSTANCE
                                                     .getSerializerDeserializer(BuiltinType.ADATETIME);
                                             resultType = ATypeTag.DATETIME;
-                                            chronon = ADateTimeSerializerDeserializer.getChronon(
-                                                    argOut1.getByteArray(), 1);
+                                            chronon = ADateTimeSerializerDeserializer.getChronon(bytes1, offset1 + 1);
                                             break;
                                         case DATE:
                                             serde = AqlSerializerDeserializerProvider.INSTANCE
                                                     .getSerializerDeserializer(BuiltinType.ADATE);
                                             resultType = ATypeTag.DATE;
-                                            chronon = ADateSerializerDeserializer.getChronon(argOut1.getByteArray(), 1)
+                                            chronon = ADateSerializerDeserializer.getChronon(bytes1, offset1 + 1)
                                                     * GregorianCalendarSystem.CHRONON_OF_DAY;
                                             break;
                                         case TIME:
@@ -477,8 +471,7 @@ public abstract class AbstractNumericArithmeticEval extends AbstractScalarFuncti
                                                 serde = AqlSerializerDeserializerProvider.INSTANCE
                                                         .getSerializerDeserializer(BuiltinType.ATIME);
                                                 resultType = ATypeTag.TIME;
-                                                chronon = ATimeSerializerDeserializer.getChronon(
-                                                        argOut1.getByteArray(), 1);
+                                                chronon = ATimeSerializerDeserializer.getChronon(bytes1, offset1 + 1);
                                                 isTimeOnly = true;
                                                 break;
                                             }
@@ -489,9 +482,9 @@ public abstract class AbstractNumericArithmeticEval extends AbstractScalarFuncti
                                     }
                                     break;
                                 default:
-                                    throw new NotImplementedException(getIdentifier().getName()
-                                            + ": arithmetic operation between " + leftType + " and a " + rightType
-                                            + " value is not supported.");
+                                    throw new NotImplementedException(
+                                            getIdentifier().getName() + ": arithmetic operation between " + leftType
+                                                    + " and a " + rightType + " value is not supported.");
                             }
 
                             chronon = evaluateTimeDurationArithmetic(chronon, yearMonth, dayTime, isTimeOnly);
@@ -516,9 +509,9 @@ public abstract class AbstractNumericArithmeticEval extends AbstractScalarFuncti
                                     serde.serialize(aDatetime, out);
                                     break;
                                 default:
-                                    throw new NotImplementedException(getIdentifier().getName()
-                                            + ": arithmetic operation between " + leftType + " and a " + rightType
-                                            + " value is not supported.");
+                                    throw new NotImplementedException(
+                                            getIdentifier().getName() + ": arithmetic operation between " + leftType
+                                                    + " and a " + rightType + " value is not supported.");
 
                             }
                         }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractQuadStringStringEval.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractQuadStringStringEval.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractQuadStringStringEval.java
index a08551f..0085461 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractQuadStringStringEval.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractQuadStringStringEval.java
@@ -32,25 +32,29 @@ import org.apache.asterix.om.types.BuiltinType;
 import org.apache.asterix.om.types.EnumDeserializer;
 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.api.exceptions.HyracksDataException;
+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.dataflow.common.data.accessors.IFrameTupleReference;
 
-public abstract class AbstractQuadStringStringEval implements ICopyEvaluator {
+public abstract class AbstractQuadStringStringEval implements IScalarEvaluator {
 
-    private DataOutput dout;
-    private ArrayBackedValueStorage array0 = new ArrayBackedValueStorage();
-    private ArrayBackedValueStorage array1 = new ArrayBackedValueStorage();
-    private ArrayBackedValueStorage array2 = new ArrayBackedValueStorage();
-    private ArrayBackedValueStorage array3 = new ArrayBackedValueStorage();
-    private ICopyEvaluator eval0;
-    private ICopyEvaluator eval1;
-    private ICopyEvaluator eval2;
-    private ICopyEvaluator eval3;
+    private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+    private DataOutput dout = resultStorage.getDataOutput();
+    private IPointable array0 = new VoidPointable();
+    private IPointable array1 = new VoidPointable();
+    private IPointable array2 = new VoidPointable();
+    private IPointable array3 = new VoidPointable();
+    private IScalarEvaluator eval0;
+    private IScalarEvaluator eval1;
+    private IScalarEvaluator eval2;
+    private IScalarEvaluator eval3;
 
     private final FunctionIdentifier funcID;
 
@@ -67,46 +71,50 @@ public abstract class AbstractQuadStringStringEval implements ICopyEvaluator {
     private final UTF8StringPointable strPtr3rd = new UTF8StringPointable();
     private final UTF8StringPointable strPtr4th = new UTF8StringPointable();
 
-    public AbstractQuadStringStringEval(DataOutput dout, ICopyEvaluatorFactory eval0, ICopyEvaluatorFactory eval1,
-            ICopyEvaluatorFactory eval2, ICopyEvaluatorFactory eval3, FunctionIdentifier funcID)
-                    throws AlgebricksException {
-        this.dout = dout;
-        this.eval0 = eval0.createEvaluator(array0);
-        this.eval1 = eval1.createEvaluator(array1);
-        this.eval2 = eval2.createEvaluator(array2);
-        this.eval3 = eval3.createEvaluator(array3);
+    public AbstractQuadStringStringEval(IHyracksTaskContext context, IScalarEvaluatorFactory eval0,
+            IScalarEvaluatorFactory eval1, IScalarEvaluatorFactory eval2, IScalarEvaluatorFactory eval3,
+            FunctionIdentifier funcID) throws AlgebricksException {
+        this.eval0 = eval0.createScalarEvaluator(context);
+        this.eval1 = eval1.createScalarEvaluator(context);
+        this.eval2 = eval2.createScalarEvaluator(context);
+        this.eval3 = eval3.createScalarEvaluator(context);
         this.funcID = funcID;
     }
 
     @SuppressWarnings("unchecked")
     @Override
-    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-        array0.reset();
-        eval0.evaluate(tuple);
-        array1.reset();
-        eval1.evaluate(tuple);
-        array2.reset();
-        eval2.evaluate(tuple);
-        array3.reset();
-        eval3.evaluate(tuple);
+    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+        eval0.evaluate(tuple, array0);
+        eval1.evaluate(tuple, array1);
+        eval2.evaluate(tuple, array2);
+        eval3.evaluate(tuple, array3);
 
+        resultStorage.reset();
         try {
-            if (array0.getByteArray()[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG
-                    || array1.getByteArray()[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG
-                    || array2.getByteArray()[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG
-                    || array3.getByteArray()[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
+            if (array0.getByteArray()[array0.getStartOffset()] == ATypeTag.SERIALIZED_NULL_TYPE_TAG
+                    || array1.getByteArray()[array1.getStartOffset()] == ATypeTag.SERIALIZED_NULL_TYPE_TAG
+                    || array2.getByteArray()[array2.getStartOffset()] == ATypeTag.SERIALIZED_NULL_TYPE_TAG
+                    || array3.getByteArray()[array3.getStartOffset()] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
                 nullSerde.serialize(ANull.NULL, dout);
+                result.set(resultStorage);
                 return;
-            } else if (array0.getByteArray()[0] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
-                    || array1.getByteArray()[0] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
-                    || array2.getByteArray()[0] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
-                    || array3.getByteArray()[0] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
+            } else if (array0.getByteArray()[array0.getStartOffset()] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
+                    || array1.getByteArray()[array1.getStartOffset()] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
+                    || array2.getByteArray()[array2.getStartOffset()] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
+                    || array3.getByteArray()[array3.getStartOffset()] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                 throw new AlgebricksException(funcID.getName()
                         + ": expects input type (STRING/NULL, STRING/NULL, STRING/NULL, STRING/NULL), but got ("
-                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(array0.getByteArray()[0]) + ", "
-                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(array1.getByteArray()[0]) + ", "
-                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(array2.getByteArray()[0]) + ", "
-                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(array3.getByteArray()[0]) + ".");
+                        + EnumDeserializer.ATYPETAGDESERIALIZER
+                                .deserialize(array0.getByteArray()[array0.getStartOffset()])
+                        + ", "
+                        + EnumDeserializer.ATYPETAGDESERIALIZER
+                                .deserialize(array1.getByteArray()[array1.getStartOffset()])
+                        + ", "
+                        + EnumDeserializer.ATYPETAGDESERIALIZER
+                                .deserialize(array2.getByteArray()[array2.getStartOffset()])
+                        + ", " + EnumDeserializer.ATYPETAGDESERIALIZER
+                                .deserialize(array3.getByteArray()[array3.getStartOffset()])
+                        + ".");
             }
         } catch (HyracksDataException e) {
             throw new AlgebricksException(e);
@@ -124,6 +132,7 @@ public abstract class AbstractQuadStringStringEval implements ICopyEvaluator {
         } catch (HyracksDataException e) {
             throw new AlgebricksException(e);
         }
+        result.set(resultStorage);
     }
 
     protected abstract String compute(UTF8StringPointable strPtr1st, UTF8StringPointable strPtr2nd,

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractTripleStringBoolEval.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractTripleStringBoolEval.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractTripleStringBoolEval.java
index eb32ac2..f1f07dd 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractTripleStringBoolEval.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractTripleStringBoolEval.java
@@ -28,23 +28,28 @@ import org.apache.asterix.om.types.BuiltinType;
 import org.apache.asterix.om.types.EnumDeserializer;
 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.api.exceptions.HyracksDataException;
+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.dataflow.common.data.accessors.IFrameTupleReference;
 
-public abstract class AbstractTripleStringBoolEval implements ICopyEvaluator {
+public abstract class AbstractTripleStringBoolEval implements IScalarEvaluator {
+
+    private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+    private DataOutput dout = resultStorage.getDataOutput();
+    private IPointable array0 = new VoidPointable();
+    private IPointable array1 = new VoidPointable();
+    private IPointable array2 = new VoidPointable();
+    private IScalarEvaluator eval0;
+    private IScalarEvaluator eval1;
+    private IScalarEvaluator eval2;
 
-    private DataOutput dout;
-    private ArrayBackedValueStorage array0 = new ArrayBackedValueStorage();
-    private ArrayBackedValueStorage array1 = new ArrayBackedValueStorage();
-    private ArrayBackedValueStorage array2 = new ArrayBackedValueStorage();
-    private ICopyEvaluator eval0;
-    private ICopyEvaluator eval1;
-    private ICopyEvaluator eval2;
     @SuppressWarnings("rawtypes")
     private ISerializerDeserializer boolSerde = AqlSerializerDeserializerProvider.INSTANCE
             .getSerializerDeserializer(BuiltinType.ABOOLEAN);
@@ -58,41 +63,45 @@ public abstract class AbstractTripleStringBoolEval implements ICopyEvaluator {
     private final UTF8StringPointable strPtr2nd = new UTF8StringPointable();
     private final UTF8StringPointable strPtr3rd = new UTF8StringPointable();
 
-    public AbstractTripleStringBoolEval(DataOutput dout, ICopyEvaluatorFactory eval0, ICopyEvaluatorFactory eval1,
-            ICopyEvaluatorFactory eval2, FunctionIdentifier funcID) throws AlgebricksException {
-        this.dout = dout;
-        this.eval0 = eval0.createEvaluator(array0);
-        this.eval1 = eval1.createEvaluator(array1);
-        this.eval2 = eval2.createEvaluator(array2);
+    public AbstractTripleStringBoolEval(IHyracksTaskContext context, IScalarEvaluatorFactory eval0,
+            IScalarEvaluatorFactory eval1, IScalarEvaluatorFactory eval2, FunctionIdentifier funcID)
+                    throws AlgebricksException {
+        this.eval0 = eval0.createScalarEvaluator(context);
+        this.eval1 = eval1.createScalarEvaluator(context);
+        this.eval2 = eval2.createScalarEvaluator(context);
         this.funcID = funcID;
     }
 
     @SuppressWarnings("unchecked")
     @Override
-    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-        array0.reset();
-        eval0.evaluate(tuple);
-        array1.reset();
-        eval1.evaluate(tuple);
-        array2.reset();
-        eval2.evaluate(tuple);
+    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+        eval0.evaluate(tuple, array0);
+        eval1.evaluate(tuple, array1);
+        eval2.evaluate(tuple, array2);
 
+        resultStorage.reset();
         try {
-            if (array0.getByteArray()[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG
-                    || array1.getByteArray()[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG
-                    || array2.getByteArray()[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
+            if (array0.getByteArray()[array0.getStartOffset()] == ATypeTag.SERIALIZED_NULL_TYPE_TAG
+                    || array1.getByteArray()[array1.getStartOffset()] == ATypeTag.SERIALIZED_NULL_TYPE_TAG
+                    || array2.getByteArray()[array2.getStartOffset()] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
                 nullSerde.serialize(ANull.NULL, dout);
+                result.set(resultStorage);
                 return;
             }
 
-            if (array0.getByteArray()[0] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
-                    || array1.getByteArray()[0] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
-                    || array2.getByteArray()[0] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
+            if (array0.getByteArray()[array0.getStartOffset()] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
+                    || array1.getByteArray()[array1.getStartOffset()] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
+                    || array2.getByteArray()[array2.getStartOffset()] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                 throw new AlgebricksException(
                         funcID.getName() + ": expects iput type (STRING/NULL, STRING/NULL, STRING) but got ("
-                                + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(array0.getByteArray()[0]) + ", "
-                                + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(array1.getByteArray()[0]) + ", "
-                                + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(array2.getByteArray()[0]) + ")");
+                                + EnumDeserializer.ATYPETAGDESERIALIZER
+                                        .deserialize(array0.getByteArray()[array0.getStartOffset()])
+                                + ", "
+                                + EnumDeserializer.ATYPETAGDESERIALIZER
+                                        .deserialize(array1.getByteArray()[array1.getStartOffset()])
+                                + ", " + EnumDeserializer.ATYPETAGDESERIALIZER
+                                        .deserialize(array2.getByteArray()[array2.getStartOffset()])
+                                + ")");
             }
 
         } catch (HyracksDataException e) {
@@ -109,6 +118,7 @@ public abstract class AbstractTripleStringBoolEval implements ICopyEvaluator {
         } catch (HyracksDataException e) {
             throw new AlgebricksException(e);
         }
+        result.set(resultStorage);
     }
 
     protected abstract boolean compute(UTF8StringPointable strPtr1st, UTF8StringPointable strPtr2nd,

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractTripleStringStringEval.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractTripleStringStringEval.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractTripleStringStringEval.java
index bc602c3..7511b82 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractTripleStringStringEval.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AbstractTripleStringStringEval.java
@@ -28,22 +28,27 @@ import org.apache.asterix.om.types.BuiltinType;
 import org.apache.asterix.om.types.EnumDeserializer;
 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.api.exceptions.HyracksDataException;
+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.dataflow.common.data.accessors.IFrameTupleReference;
 
-public abstract class AbstractTripleStringStringEval implements ICopyEvaluator {
-    private DataOutput dout;
-    private ArrayBackedValueStorage array0 = new ArrayBackedValueStorage();
-    private ArrayBackedValueStorage array1 = new ArrayBackedValueStorage();
-    private ArrayBackedValueStorage array2 = new ArrayBackedValueStorage();
-    private ICopyEvaluator eval0;
-    private ICopyEvaluator eval1;
-    private ICopyEvaluator eval2;
+public abstract class AbstractTripleStringStringEval implements IScalarEvaluator {
+
+    private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+    private DataOutput dout = resultStorage.getDataOutput();
+    private IPointable array0 = new VoidPointable();
+    private IPointable array1 = new VoidPointable();
+    private IPointable array2 = new VoidPointable();
+    private IScalarEvaluator eval0;
+    private IScalarEvaluator eval1;
+    private IScalarEvaluator eval2;
 
     private AMutableString resultBuffer = new AMutableString("");
     @SuppressWarnings("rawtypes")
@@ -59,39 +64,43 @@ public abstract class AbstractTripleStringStringEval implements ICopyEvaluator {
 
     private final FunctionIdentifier funcID;
 
-    public AbstractTripleStringStringEval(DataOutput dout, ICopyEvaluatorFactory eval0, ICopyEvaluatorFactory eval1,
-            ICopyEvaluatorFactory eval2, FunctionIdentifier funcID) throws AlgebricksException {
-        this.dout = dout;
-        this.eval0 = eval0.createEvaluator(array0);
-        this.eval1 = eval1.createEvaluator(array1);
-        this.eval2 = eval2.createEvaluator(array2);
+    public AbstractTripleStringStringEval(IHyracksTaskContext context, IScalarEvaluatorFactory eval0,
+            IScalarEvaluatorFactory eval1, IScalarEvaluatorFactory eval2, FunctionIdentifier funcID)
+                    throws AlgebricksException {
+        this.eval0 = eval0.createScalarEvaluator(context);
+        this.eval1 = eval1.createScalarEvaluator(context);
+        this.eval2 = eval2.createScalarEvaluator(context);
         this.funcID = funcID;
     }
 
     @SuppressWarnings("unchecked")
     @Override
-    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-        array0.reset();
-        eval0.evaluate(tuple);
-        array1.reset();
-        eval1.evaluate(tuple);
-        array2.reset();
-        eval2.evaluate(tuple);
+    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+        eval0.evaluate(tuple, array0);
+        eval1.evaluate(tuple, array1);
+        eval2.evaluate(tuple, array2);
 
+        resultStorage.reset();
         try {
-            if (array0.getByteArray()[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG
-                    || array1.getByteArray()[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG
-                    || array2.getByteArray()[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
+            if (array0.getByteArray()[array0.getStartOffset()] == ATypeTag.SERIALIZED_NULL_TYPE_TAG
+                    || array1.getByteArray()[array1.getStartOffset()] == ATypeTag.SERIALIZED_NULL_TYPE_TAG
+                    || array2.getByteArray()[array2.getStartOffset()] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
                 nullSerde.serialize(ANull.NULL, dout);
+                result.set(resultStorage);
                 return;
-            } else if (array0.getByteArray()[0] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
-                    || array1.getByteArray()[0] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
-                    || array2.getByteArray()[0] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
+            } else if (array0.getByteArray()[array0.getStartOffset()] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
+                    || array1.getByteArray()[array1.getStartOffset()] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
+                    || array2.getByteArray()[array2.getStartOffset()] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                 throw new AlgebricksException(
                         funcID.getName() + ": expects input type (STRING/NULL, STRING/NULL, STRING/NULL), but got ("
-                                + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(array0.getByteArray()[0]) + ", "
-                                + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(array1.getByteArray()[0]) + ", "
-                                + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(array2.getByteArray()[0]) + ".");
+                                + EnumDeserializer.ATYPETAGDESERIALIZER
+                                        .deserialize(array0.getByteArray()[array0.getStartOffset()])
+                                + ", "
+                                + EnumDeserializer.ATYPETAGDESERIALIZER
+                                        .deserialize(array1.getByteArray()[array1.getStartOffset()])
+                                + ", " + EnumDeserializer.ATYPETAGDESERIALIZER
+                                        .deserialize(array2.getByteArray()[array2.getStartOffset()])
+                                + ".");
             }
         } catch (HyracksDataException e) {
             throw new AlgebricksException(e);
@@ -108,6 +117,7 @@ public abstract class AbstractTripleStringStringEval implements ICopyEvaluator {
         } catch (HyracksDataException e) {
             throw new AlgebricksException(e);
         }
+        result.set(resultStorage);
     }
 
     protected abstract String compute(UTF8StringPointable strPtr1st, UTF8StringPointable strPtr2nd,

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AndDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AndDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AndDescriptor.java
index e310953..01abb1b 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AndDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AndDescriptor.java
@@ -18,6 +18,8 @@
  */
 package org.apache.asterix.runtime.evaluators.functions;
 
+import java.io.DataOutput;
+
 import org.apache.asterix.dataflow.data.nontagged.serde.ABooleanSerializerDeserializer;
 import org.apache.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import org.apache.asterix.om.base.ABoolean;
@@ -30,11 +32,13 @@ import org.apache.asterix.om.types.BuiltinType;
 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.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.VoidPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -53,21 +57,23 @@ public class AndDescriptor extends AbstractScalarFunctionDynamicDescriptor {
     }
 
     @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(final IDataOutputProvider output) throws AlgebricksException {
-                // one temp. buffer re-used by all children
-                final ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
-                final ICopyEvaluator[] evals = new ICopyEvaluator[args.length];
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
+                final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+                final DataOutput out = resultStorage.getDataOutput();
+                final IPointable argPtr = new VoidPointable();
+                final IScalarEvaluator[] evals = new IScalarEvaluator[args.length];
                 for (int i = 0; i < evals.length; i++) {
-                    evals[i] = args[i].createEvaluator(argOut);
+                    evals[i] = args[i].createScalarEvaluator(ctx);
                 }
 
-                return new ICopyEvaluator() {
+                return new IScalarEvaluator() {
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ABoolean> booleanSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ABOOLEAN);
@@ -76,31 +82,36 @@ public class AndDescriptor extends AbstractScalarFunctionDynamicDescriptor {
                             .getSerializerDeserializer(BuiltinType.ANULL);
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
                         try {
+                            resultStorage.reset();
                             int n = args.length;
                             boolean res = true;
                             boolean metNull = false;
                             for (int i = 0; i < n; i++) {
-                                argOut.reset();
-                                evals[i].evaluate(tuple);
-                                if (argOut.getByteArray()[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
+                                evals[i].evaluate(tuple, argPtr);
+                                byte[] bytes = argPtr.getByteArray();
+                                int offset = argPtr.getStartOffset();
+
+                                if (bytes[offset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
                                     metNull = true;
                                     continue;
                                 }
-                                boolean argResult = ABooleanSerializerDeserializer.getBoolean(argOut.getByteArray(), 1);
+                                boolean argResult = ABooleanSerializerDeserializer.getBoolean(bytes, offset + 1);
                                 res = res && argResult;
                             }
                             if (metNull) {
                                 if (!res) {
                                     ABoolean aResult = ABoolean.FALSE;
-                                    booleanSerde.serialize(aResult, output.getDataOutput());
-                                } else
-                                    nullSerde.serialize(ANull.NULL, output.getDataOutput());
+                                    booleanSerde.serialize(aResult, out);
+                                } else {
+                                    nullSerde.serialize(ANull.NULL, out);
+                                }
                             } else {
                                 ABoolean aResult = res ? (ABoolean.TRUE) : (ABoolean.FALSE);
-                                booleanSerde.serialize(aResult, output.getDataOutput());
+                                booleanSerde.serialize(aResult, out);
                             }
+                            result.set(resultStorage);
                         } catch (HyracksDataException hde) {
                             throw new AlgebricksException(hde);
                         }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AnyCollectionMemberDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AnyCollectionMemberDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AnyCollectionMemberDescriptor.java
index bc5d26c..546eebd 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AnyCollectionMemberDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/AnyCollectionMemberDescriptor.java
@@ -36,10 +36,12 @@ import org.apache.asterix.om.util.NonTaggedFormatUtil;
 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;
 
@@ -54,7 +56,7 @@ public class AnyCollectionMemberDescriptor extends AbstractScalarFunctionDynamic
     };
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new AnyCollectionMemberEvalFactory(args[0]);
     }
 
@@ -63,25 +65,27 @@ public class AnyCollectionMemberDescriptor extends AbstractScalarFunctionDynamic
         return AsterixBuiltinFunctions.ANY_COLLECTION_MEMBER;
     }
 
-    private static class AnyCollectionMemberEvalFactory implements ICopyEvaluatorFactory {
+    private static class AnyCollectionMemberEvalFactory implements IScalarEvaluatorFactory {
 
         private static final long serialVersionUID = 1L;
-        private ICopyEvaluatorFactory listEvalFactory;
+
+        private IScalarEvaluatorFactory listEvalFactory;
         private byte serItemTypeTag;
         private ATypeTag itemTag;
         private boolean selfDescList = false;
 
-        public AnyCollectionMemberEvalFactory(ICopyEvaluatorFactory arg) {
+        public AnyCollectionMemberEvalFactory(IScalarEvaluatorFactory arg) {
             this.listEvalFactory = arg;
         }
 
         @Override
-        public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
-            return new ICopyEvaluator() {
+        public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
+            return new IScalarEvaluator() {
 
-                private DataOutput out = output.getDataOutput();
-                private ArrayBackedValueStorage outInputList = new ArrayBackedValueStorage();
-                private ICopyEvaluator evalList = listEvalFactory.createEvaluator(outInputList);
+                private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+                private DataOutput out = resultStorage.getDataOutput();
+                private IPointable inputArgList = new VoidPointable();
+                private IScalarEvaluator evalList = listEvalFactory.createScalarEvaluator(ctx);
                 @SuppressWarnings("unchecked")
                 private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                         .getSerializerDeserializer(BuiltinType.ANULL);
@@ -89,54 +93,60 @@ public class AnyCollectionMemberDescriptor extends AbstractScalarFunctionDynamic
                 private int itemLength;
 
                 @Override
-                public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
 
                     try {
-                        outInputList.reset();
-                        evalList.evaluate(tuple);
-                        byte[] serList = outInputList.getByteArray();
+                        resultStorage.reset();
+                        evalList.evaluate(tuple, inputArgList);
+                        byte[] serList = inputArgList.getByteArray();
+                        int offset = inputArgList.getStartOffset();
 
-                        if (serList[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
+                        if (serList[offset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
                             nullSerde.serialize(ANull.NULL, out);
+                            result.set(resultStorage);
                             return;
                         }
 
-                        if (serList[0] != ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG
-                                && serList[0] != ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG) {
+                        if (serList[offset] != ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG
+                                && serList[offset] != ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG) {
                             throw new AlgebricksException(AsterixBuiltinFunctions.ANY_COLLECTION_MEMBER.getName()
                                     + ": expects input type ORDEREDLIST/UNORDEREDLIST, but got "
-                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serList[0]));
+                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serList[offset]));
                         }
 
-                        if (serList[0] == ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG) {
-                            if (AOrderedListSerializerDeserializer.getNumberOfItems(serList) == 0) {
+                        if (serList[offset] == ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG) {
+                            if (AOrderedListSerializerDeserializer.getNumberOfItems(serList, offset) == 0) {
                                 out.writeByte(ATypeTag.SERIALIZED_NULL_TYPE_TAG);
+                                result.set(resultStorage);
                                 return;
                             }
-                            itemOffset = AOrderedListSerializerDeserializer.getItemOffset(serList, 0);
+                            itemOffset = AOrderedListSerializerDeserializer.getItemOffset(serList, offset, 0);
                         } else {
-                            if (AUnorderedListSerializerDeserializer.getNumberOfItems(serList) == 0) {
+                            if (AUnorderedListSerializerDeserializer.getNumberOfItems(serList, offset) == 0) {
                                 out.writeByte(ATypeTag.SERIALIZED_NULL_TYPE_TAG);
+                                result.set(resultStorage);
                                 return;
                             }
-                            itemOffset = AUnorderedListSerializerDeserializer.getItemOffset(serList, 0);
+                            itemOffset = AUnorderedListSerializerDeserializer.getItemOffset(serList, offset, 0);
                         }
 
-                        itemTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serList[1]);
-                        if (itemTag == ATypeTag.ANY)
+                        itemTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serList[offset + 1]);
+                        if (itemTag == ATypeTag.ANY) {
                             selfDescList = true;
-                        else
-                            serItemTypeTag = serList[1];
+                        } else {
+                            serItemTypeTag = serList[offset + 1];
+                        }
 
                         if (selfDescList) {
                             itemTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serList[itemOffset]);
                             itemLength = NonTaggedFormatUtil.getFieldValueLength(serList, itemOffset, itemTag, true)
                                     + 1;
-                            out.write(serList, itemOffset, itemLength);
+                            result.set(serList, itemOffset, itemLength);
                         } else {
                             itemLength = NonTaggedFormatUtil.getFieldValueLength(serList, itemOffset, itemTag, false);
                             out.writeByte(serItemTypeTag);
                             out.write(serList, itemOffset, itemLength);
+                            result.set(resultStorage);
                         }
                     } catch (IOException e) {
                         throw new AlgebricksException(e);

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/CastListDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/CastListDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/CastListDescriptor.java
index e024014..f776d1d 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/CastListDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/CastListDescriptor.java
@@ -19,8 +19,6 @@
 
 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;
@@ -33,10 +31,11 @@ import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicD
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.common.utils.Triple;
 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.data.std.util.ArrayBackedValueStorage;
+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.dataflow.common.data.accessors.IFrameTupleReference;
 
 /**
@@ -47,6 +46,7 @@ import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 public class CastListDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        @Override
         public IFunctionDescriptor createFunctionDescriptor() {
             return new CastListDescriptor();
         }
@@ -67,19 +67,18 @@ public class CastListDescriptor extends AbstractScalarFunctionDynamicDescriptor
     }
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
-        final ICopyEvaluatorFactory recordEvalFactory = args[0];
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
+        final IScalarEvaluatorFactory recordEvalFactory = args[0];
 
-        return new ICopyEvaluatorFactory() {
+        return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
-                final DataOutput out = output.getDataOutput();
-                final ArrayBackedValueStorage recordBuffer = new ArrayBackedValueStorage();
-                final ICopyEvaluator recEvaluator = recordEvalFactory.createEvaluator(recordBuffer);
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
+                final IPointable recordPtr = new VoidPointable();
+                final IScalarEvaluator recEvaluator = recordEvalFactory.createScalarEvaluator(ctx);
 
-                return new ICopyEvaluator() {
+                return new IScalarEvaluator() {
                     // pointable allocator
                     private PointableAllocator allocator = new PointableAllocator();
                     final IVisitablePointable recAccessor = allocator.allocateListValue(inputType);
@@ -89,14 +88,12 @@ public class CastListDescriptor extends AbstractScalarFunctionDynamicDescriptor
                             resultAccessor, reqType, Boolean.FALSE);
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
                         try {
-                            recordBuffer.reset();
-                            recEvaluator.evaluate(tuple);
-                            recAccessor.set(recordBuffer);
+                            recEvaluator.evaluate(tuple, recordPtr);
+                            recAccessor.set(recordPtr);
                             recAccessor.accept(castVisitor, arg);
-                            out.write(resultAccessor.getByteArray(), resultAccessor.getStartOffset(),
-                                    resultAccessor.getLength());
+                            result.set(resultAccessor);
                         } catch (Exception ioe) {
                             throw new AlgebricksException(ioe);
                         }



Mime
View raw message