asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From buyin...@apache.org
Subject [17/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:46 GMT
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/common/SpatialUtils.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/common/SpatialUtils.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/common/SpatialUtils.java
index 90f67a2..8e492c3 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/common/SpatialUtils.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/common/SpatialUtils.java
@@ -92,26 +92,26 @@ public class SpatialUtils {
     }
 
     // Warning: The caller is responsible of taking the absolute value
-    public final static double polygonArea(byte[] bytes, int numOfPoints) throws HyracksDataException {
+    public final static double polygonArea(byte[] bytes, int offset, int numOfPoints) throws HyracksDataException {
         double area = 0.0;
         for (int i = 0; i < numOfPoints; i++) {
 
             double x1 = ADoubleSerializerDeserializer.getDouble(bytes,
-                    APolygonSerializerDeserializer.getCoordinateOffset(i, Coordinate.X));
+                    offset + APolygonSerializerDeserializer.getCoordinateOffset(i, Coordinate.X));
             double y1 = ADoubleSerializerDeserializer.getDouble(bytes,
-                    APolygonSerializerDeserializer.getCoordinateOffset(i, Coordinate.Y));
+                    offset + APolygonSerializerDeserializer.getCoordinateOffset(i, Coordinate.Y));
             double x2;
             double y2;
             if (i + 1 == numOfPoints) {
                 x2 = ADoubleSerializerDeserializer.getDouble(bytes,
-                        APolygonSerializerDeserializer.getCoordinateOffset(0, Coordinate.X));
+                        offset + APolygonSerializerDeserializer.getCoordinateOffset(0, Coordinate.X));
                 y2 = ADoubleSerializerDeserializer.getDouble(bytes,
-                        APolygonSerializerDeserializer.getCoordinateOffset(0, Coordinate.Y));
+                        offset + APolygonSerializerDeserializer.getCoordinateOffset(0, Coordinate.Y));
             } else {
                 x2 = ADoubleSerializerDeserializer.getDouble(bytes,
-                        APolygonSerializerDeserializer.getCoordinateOffset(i + 1, Coordinate.X));
+                        offset + APolygonSerializerDeserializer.getCoordinateOffset(i + 1, Coordinate.X));
                 y2 = ADoubleSerializerDeserializer.getDouble(bytes,
-                        APolygonSerializerDeserializer.getCoordinateOffset(i + 1, Coordinate.Y));
+                        offset + APolygonSerializerDeserializer.getCoordinateOffset(i + 1, Coordinate.Y));
             }
             area += (x1 * y2) - (x2 * y1);
         }
@@ -128,10 +128,11 @@ public class SpatialUtils {
             temp = getTriangleXCoordinate(trianglesX, triangleId, i) * xAxis
                     + getTriangleYCoordinate(trianglesY, triangleId, i) * yAxis;
 
-            if (temp > max)
+            if (temp > max) {
                 max = temp;
-            else if (temp < min)
+            } else if (temp < min) {
                 min = temp;
+            }
         }
         setMinProjection(min);
         setMaxProjection(max);

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/common/WordTokensEvaluator.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/common/WordTokensEvaluator.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/common/WordTokensEvaluator.java
index d8eceaa..faace0e 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/common/WordTokensEvaluator.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/common/WordTokensEvaluator.java
@@ -25,36 +25,37 @@ import org.apache.asterix.builders.OrderedListBuilder;
 import org.apache.asterix.om.types.AOrderedListType;
 import org.apache.asterix.om.types.BuiltinType;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
-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.storage.am.lsm.invertedindex.tokenizers.IBinaryTokenizer;
 
-public class WordTokensEvaluator implements ICopyEvaluator {
-    private final DataOutput out;
-    private final ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
-    private final ICopyEvaluator stringEval;
+public class WordTokensEvaluator implements IScalarEvaluator {
+    private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+    private final DataOutput out = resultStorage.getDataOutput();
+    private final IPointable argPtr = new VoidPointable();
+    private final IScalarEvaluator stringEval;
 
     private final IBinaryTokenizer tokenizer;
     private final OrderedListBuilder listBuilder = new OrderedListBuilder();
     private final AOrderedListType listType;
 
-    public WordTokensEvaluator(ICopyEvaluatorFactory[] args, IDataOutputProvider output, IBinaryTokenizer tokenizer,
+    public WordTokensEvaluator(IScalarEvaluatorFactory[] args, IHyracksTaskContext context, IBinaryTokenizer tokenizer,
             BuiltinType itemType) throws AlgebricksException {
-        out = output.getDataOutput();
-        stringEval = args[0].createEvaluator(argOut);
+        stringEval = args[0].createScalarEvaluator(context);
         this.tokenizer = tokenizer;
         this.listType = new AOrderedListType(itemType, null);
     }
 
     @Override
-    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-        argOut.reset();
-        stringEval.evaluate(tuple);
-        byte[] bytes = argOut.getByteArray();
-        tokenizer.reset(bytes, 0, argOut.getLength());
+    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+        resultStorage.reset();
+        stringEval.evaluate(tuple, argPtr);
+        tokenizer.reset(argPtr.getByteArray(), argPtr.getStartOffset(), argPtr.getLength());
         try {
             listBuilder.reset(listType);
             while (tokenizer.hasNext()) {
@@ -65,5 +66,6 @@ public class WordTokensEvaluator implements ICopyEvaluator {
         } 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/comparisons/AbstractComparisonEvaluator.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/AbstractComparisonEvaluator.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/AbstractComparisonEvaluator.java
index b2a91ea..b4e391f 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/AbstractComparisonEvaluator.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/AbstractComparisonEvaluator.java
@@ -44,20 +44,23 @@ import org.apache.asterix.om.types.ATypeTag;
 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.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.BinaryComparatorConstant.ComparableResultCode;
 import org.apache.hyracks.api.dataflow.value.IBinaryComparator;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.data.std.accessors.PointableBinaryComparatorFactory;
+import org.apache.hyracks.data.std.api.IPointable;
 import org.apache.hyracks.data.std.primitive.ByteArrayPointable;
 import org.apache.hyracks.data.std.primitive.FloatPointable;
 import org.apache.hyracks.data.std.primitive.IntegerPointable;
+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 AbstractComparisonEvaluator implements ICopyEvaluator {
+public abstract class AbstractComparisonEvaluator implements IScalarEvaluator {
 
     protected enum ComparisonResult {
         LESS_THAN,
@@ -66,13 +69,12 @@ public abstract class AbstractComparisonEvaluator implements ICopyEvaluator {
         UNKNOWN
     }
 
-    ;
-
-    protected DataOutput out;
-    protected ArrayBackedValueStorage outLeft = new ArrayBackedValueStorage();
-    protected ArrayBackedValueStorage outRight = new ArrayBackedValueStorage();
-    protected ICopyEvaluator evalLeft;
-    protected ICopyEvaluator evalRight;
+    protected ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+    protected DataOutput out = resultStorage.getDataOutput();
+    protected IPointable outLeft = new VoidPointable();
+    protected IPointable outRight = new VoidPointable();
+    protected IScalarEvaluator evalLeft;
+    protected IScalarEvaluator evalRight;
     @SuppressWarnings("unchecked")
     protected ISerializerDeserializer<ABoolean> serde = AqlSerializerDeserializerProvider.INSTANCE
             .getSerializerDeserializer(BuiltinType.ABOOLEAN);
@@ -103,25 +105,23 @@ public abstract class AbstractComparisonEvaluator implements ICopyEvaluator {
     protected final IBinaryComparator byteArrayComparator = new PointableBinaryComparatorFactory(
             ByteArrayPointable.FACTORY).createBinaryComparator();
 
-    public AbstractComparisonEvaluator(DataOutput out, ICopyEvaluatorFactory evalLeftFactory,
-            ICopyEvaluatorFactory evalRightFactory) throws AlgebricksException {
-        this.out = out;
-        this.evalLeft = evalLeftFactory.createEvaluator(outLeft);
-        this.evalRight = evalRightFactory.createEvaluator(outRight);
+    public AbstractComparisonEvaluator(IScalarEvaluatorFactory evalLeftFactory,
+            IScalarEvaluatorFactory evalRightFactory, IHyracksTaskContext context) throws AlgebricksException {
+        this.evalLeft = evalLeftFactory.createScalarEvaluator(context);
+        this.evalRight = evalRightFactory.createScalarEvaluator(context);
     }
 
     protected void evalInputs(IFrameTupleReference tuple) throws AlgebricksException {
-        outLeft.reset();
-        evalLeft.evaluate(tuple);
-        outRight.reset();
-        evalRight.evaluate(tuple);
+        evalLeft.evaluate(tuple, outLeft);
+        evalRight.evaluate(tuple, outRight);
     }
 
     // checks whether we can apply >, >=, <, and <= operations to the given type since
     // these operations can not be defined for certain types.
     protected void checkTotallyOrderable() throws AlgebricksException {
         if (outLeft.getLength() != 0) {
-            ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(outLeft.getByteArray()[0]);
+            ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER
+                    .deserialize(outLeft.getByteArray()[outLeft.getStartOffset()]);
             switch (typeTag) {
                 case DURATION:
                 case INTERVAL:
@@ -142,7 +142,8 @@ public abstract class AbstractComparisonEvaluator implements ICopyEvaluator {
     // checks whether two types are comparable
     protected ComparableResultCode comparabilityCheck() {
         // just check TypeTags
-        return ABinaryComparator.isComparable(outLeft.getByteArray(), 0, 1, outRight.getByteArray(), 0, 1);
+        return ABinaryComparator.isComparable(outLeft.getByteArray(), outLeft.getStartOffset(), 1,
+                outRight.getByteArray(), outRight.getStartOffset(), 1);
     }
 
     protected ComparisonResult compareResults() throws AlgebricksException {
@@ -151,10 +152,15 @@ public abstract class AbstractComparisonEvaluator implements ICopyEvaluator {
         ATypeTag typeTag1 = null;
         ATypeTag typeTag2 = null;
 
+        byte[] leftBytes = outLeft.getByteArray();
+        int leftStartOffset = outLeft.getStartOffset();
+        byte[] rightBytes = outRight.getByteArray();
+        int rightStartOffset = outRight.getStartOffset();
+
         if (outLeft.getLength() == 0) {
             isLeftNull = true;
         } else {
-            typeTag1 = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(outLeft.getByteArray()[0]);
+            typeTag1 = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(leftBytes[leftStartOffset]);
             if (typeTag1 == ATypeTag.NULL) {
                 isLeftNull = true;
             }
@@ -162,7 +168,7 @@ public abstract class AbstractComparisonEvaluator implements ICopyEvaluator {
         if (outRight.getLength() == 0) {
             isRightNull = true;
         } else {
-            typeTag2 = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(outRight.getByteArray()[0]);
+            typeTag2 = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(rightBytes[rightStartOffset]);
             if (typeTag2 == ATypeTag.NULL) {
                 isRightNull = true;
             }
@@ -211,58 +217,65 @@ public abstract class AbstractComparisonEvaluator implements ICopyEvaluator {
                     "Comparison is undefined between " + expectedTypeTag + " and " + actualTypeTag + ".");
         }
         int result = 0;
+        byte[] leftBytes = outLeft.getByteArray();
+        int leftOffset = outLeft.getStartOffset() + 1;
+        int leftLen = outLeft.getLength() - 1;
+        byte[] rightBytes = outRight.getByteArray();
+        int rightOffset = outRight.getStartOffset() + 1;
+        int rightLen = outRight.getLength() - 1;
+
         try {
             switch (actualTypeTag) {
                 case YEARMONTHDURATION:
                 case TIME:
                 case DATE:
-                    result = Integer.compare(AInt32SerializerDeserializer.getInt(outLeft.getByteArray(), 1),
-                            AInt32SerializerDeserializer.getInt(outRight.getByteArray(), 1));
+                    result = Integer.compare(AInt32SerializerDeserializer.getInt(leftBytes, leftOffset),
+                            AInt32SerializerDeserializer.getInt(rightBytes, rightOffset));
                     break;
                 case DAYTIMEDURATION:
                 case DATETIME:
-                    result = Long.compare(AInt64SerializerDeserializer.getLong(outLeft.getByteArray(), 1),
-                            AInt64SerializerDeserializer.getLong(outRight.getByteArray(), 1));
+                    result = Long.compare(AInt64SerializerDeserializer.getLong(leftBytes, leftOffset),
+                            AInt64SerializerDeserializer.getLong(rightBytes, rightOffset));
                     break;
                 case CIRCLE:
-                    result = circleBinaryComp.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
-                            outRight.getByteArray(), 1, outRight.getLength() - 1);
+                    result = circleBinaryComp.compare(leftBytes, leftOffset, leftLen, rightBytes, rightOffset,
+                            rightLen);
                     break;
                 case LINE:
-                    result = lineBinaryComparator.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
-                            outRight.getByteArray(), 1, outRight.getLength() - 1);
+                    result = lineBinaryComparator.compare(leftBytes, leftOffset, leftLen, rightBytes, rightOffset,
+                            rightLen);
                     break;
                 case POINT:
-                    result = pointBinaryComparator.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
-                            outRight.getByteArray(), 1, outRight.getLength() - 1);
+                    result = pointBinaryComparator.compare(leftBytes, leftOffset, leftLen, rightBytes, rightOffset,
+                            rightLen);
                     break;
                 case POINT3D:
-                    result = point3DBinaryComparator.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
-                            outRight.getByteArray(), 1, outRight.getLength() - 1);
+                    result = point3DBinaryComparator.compare(leftBytes, leftOffset, leftLen, rightBytes, rightOffset,
+                            rightLen);
                     break;
                 case POLYGON:
-                    result = polygonBinaryComparator.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
-                            outRight.getByteArray(), 1, outRight.getLength() - 1);
+                    result = polygonBinaryComparator.compare(leftBytes, leftOffset, leftLen, rightBytes, rightOffset,
+                            rightLen);
                     break;
                 case DURATION:
-                    result = durationBinaryComp.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
-                            outRight.getByteArray(), 1, outRight.getLength() - 1);
+                    result = durationBinaryComp.compare(leftBytes, leftOffset, leftLen, rightBytes, rightOffset,
+                            rightLen);
                     break;
                 case INTERVAL:
-                    result = intervalBinaryComp.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
-                            outRight.getByteArray(), 1, outRight.getLength() - 1);
+                    result = intervalBinaryComp.compare(leftBytes, leftOffset, leftLen, rightBytes, rightOffset,
+                            rightLen);
                     break;
                 case RECTANGLE:
-                    result = rectangleBinaryComparator.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
-                            outRight.getByteArray(), 1, outRight.getLength() - 1);
+                    result = rectangleBinaryComparator.compare(leftBytes, leftOffset, leftLen, rightBytes, rightOffset,
+                            rightLen);
                     break;
                 case BINARY:
-                    result = byteArrayComparator.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
-                            outRight.getByteArray(), 1, outRight.getLength() - 1);
+                    result = byteArrayComparator.compare(leftBytes, leftOffset, leftLen, rightBytes, rightOffset,
+                            rightLen);
                     break;
                 case UUID:
-                    result = uuidBinaryComparator.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
-                            outRight.getByteArray(), 1, outRight.getLength() - 1);
+                    result = uuidBinaryComparator.compare(leftBytes, leftOffset, leftLen, rightBytes, rightOffset,
+                            rightLen);
                     break;
                 default:
                     throw new AlgebricksException("Comparison for " + actualTypeTag + " is not supported.");
@@ -281,8 +294,8 @@ public abstract class AbstractComparisonEvaluator implements ICopyEvaluator {
 
     private ComparisonResult compareBooleanWithArg(ATypeTag typeTag2) throws AlgebricksException {
         if (typeTag2 == ATypeTag.BOOLEAN) {
-            byte b0 = outLeft.getByteArray()[1];
-            byte b1 = outRight.getByteArray()[1];
+            byte b0 = outLeft.getByteArray()[outLeft.getStartOffset() + 1];
+            byte b1 = outRight.getByteArray()[outRight.getStartOffset() + 1];
             return compareByte(b0, b1);
         }
         throw new AlgebricksException("Comparison is undefined between types ABoolean and " + typeTag2 + " .");
@@ -292,8 +305,9 @@ public abstract class AbstractComparisonEvaluator implements ICopyEvaluator {
         if (typeTag2 == ATypeTag.STRING) {
             int result;
             try {
-                result = strBinaryComp.compare(outLeft.getByteArray(), 1, outLeft.getLength() - 1,
-                        outRight.getByteArray(), 1, outRight.getLength() - 1);
+                result = strBinaryComp.compare(outLeft.getByteArray(), outLeft.getStartOffset() + 1,
+                        outLeft.getLength() - 1, outRight.getByteArray(), outRight.getStartOffset() + 1,
+                        outRight.getLength() - 1);
             } catch (HyracksDataException e) {
                 throw new AlgebricksException(e);
             }
@@ -309,30 +323,35 @@ public abstract class AbstractComparisonEvaluator implements ICopyEvaluator {
     }
 
     private ComparisonResult compareDoubleWithArg(ATypeTag typeTag2) throws AlgebricksException {
-        double s = ADoubleSerializerDeserializer.getDouble(outLeft.getByteArray(), 1);
+        byte[] leftBytes = outLeft.getByteArray();
+        int leftOffset = outLeft.getStartOffset() + 1;
+        byte[] rightBytes = outRight.getByteArray();
+        int rightOffset = outRight.getStartOffset() + 1;
+
+        double s = ADoubleSerializerDeserializer.getDouble(leftBytes, leftOffset);
         switch (typeTag2) {
             case INT8: {
-                byte v2 = AInt8SerializerDeserializer.getByte(outRight.getByteArray(), 1);
+                byte v2 = AInt8SerializerDeserializer.getByte(rightBytes, rightOffset);
                 return compareDouble(s, v2);
             }
             case INT16: {
-                short v2 = AInt16SerializerDeserializer.getShort(outRight.getByteArray(), 1);
+                short v2 = AInt16SerializerDeserializer.getShort(rightBytes, rightOffset);
                 return compareDouble(s, v2);
             }
             case INT32: {
-                int v2 = AInt32SerializerDeserializer.getInt(outRight.getByteArray(), 1);
+                int v2 = AInt32SerializerDeserializer.getInt(rightBytes, rightOffset);
                 return compareDouble(s, v2);
             }
             case INT64: {
-                long v2 = AInt64SerializerDeserializer.getLong(outRight.getByteArray(), 1);
+                long v2 = AInt64SerializerDeserializer.getLong(rightBytes, rightOffset);
                 return compareDouble(s, v2);
             }
             case FLOAT: {
-                float v2 = AFloatSerializerDeserializer.getFloat(outRight.getByteArray(), 1);
+                float v2 = AFloatSerializerDeserializer.getFloat(rightBytes, rightOffset);
                 return compareDouble(s, v2);
             }
             case DOUBLE: {
-                double v2 = ADoubleSerializerDeserializer.getDouble(outRight.getByteArray(), 1);
+                double v2 = ADoubleSerializerDeserializer.getDouble(rightBytes, rightOffset);
                 return compareDouble(s, v2);
             }
             default: {
@@ -342,30 +361,35 @@ public abstract class AbstractComparisonEvaluator implements ICopyEvaluator {
     }
 
     private ComparisonResult compareFloatWithArg(ATypeTag typeTag2) throws AlgebricksException {
-        float s = FloatPointable.getFloat(outLeft.getByteArray(), 1);
+        byte[] leftBytes = outLeft.getByteArray();
+        int leftOffset = outLeft.getStartOffset() + 1;
+        byte[] rightBytes = outRight.getByteArray();
+        int rightOffset = outRight.getStartOffset() + 1;
+
+        float s = FloatPointable.getFloat(leftBytes, leftOffset);
         switch (typeTag2) {
             case INT8: {
-                byte v2 = AInt8SerializerDeserializer.getByte(outRight.getByteArray(), 1);
+                byte v2 = AInt8SerializerDeserializer.getByte(rightBytes, rightOffset);
                 return compareFloat(s, v2);
             }
             case INT16: {
-                short v2 = AInt16SerializerDeserializer.getShort(outRight.getByteArray(), 1);
+                short v2 = AInt16SerializerDeserializer.getShort(rightBytes, rightOffset);
                 return compareFloat(s, v2);
             }
             case INT32: {
-                int v2 = AInt32SerializerDeserializer.getInt(outRight.getByteArray(), 1);
+                int v2 = AInt32SerializerDeserializer.getInt(rightBytes, rightOffset);
                 return compareFloat(s, v2);
             }
             case INT64: {
-                long v2 = AInt64SerializerDeserializer.getLong(outRight.getByteArray(), 1);
+                long v2 = AInt64SerializerDeserializer.getLong(rightBytes, rightOffset);
                 return compareFloat(s, v2);
             }
             case FLOAT: {
-                float v2 = AFloatSerializerDeserializer.getFloat(outRight.getByteArray(), 1);
+                float v2 = AFloatSerializerDeserializer.getFloat(rightBytes, rightOffset);
                 return compareFloat(s, v2);
             }
             case DOUBLE: {
-                double v2 = ADoubleSerializerDeserializer.getDouble(outRight.getByteArray(), 1);
+                double v2 = ADoubleSerializerDeserializer.getDouble(rightBytes, rightOffset);
                 return compareDouble(s, v2);
             }
             default: {
@@ -375,30 +399,35 @@ public abstract class AbstractComparisonEvaluator implements ICopyEvaluator {
     }
 
     private ComparisonResult compareInt64WithArg(ATypeTag typeTag2) throws AlgebricksException {
-        long s = AInt64SerializerDeserializer.getLong(outLeft.getByteArray(), 1);
+        byte[] leftBytes = outLeft.getByteArray();
+        int leftOffset = outLeft.getStartOffset() + 1;
+        byte[] rightBytes = outRight.getByteArray();
+        int rightOffset = outRight.getStartOffset() + 1;
+
+        long s = AInt64SerializerDeserializer.getLong(leftBytes, leftOffset);
         switch (typeTag2) {
             case INT8: {
-                byte v2 = AInt8SerializerDeserializer.getByte(outRight.getByteArray(), 1);
+                byte v2 = AInt8SerializerDeserializer.getByte(rightBytes, rightOffset);
                 return compareLong(s, v2);
             }
             case INT16: {
-                short v2 = AInt16SerializerDeserializer.getShort(outRight.getByteArray(), 1);
+                short v2 = AInt16SerializerDeserializer.getShort(rightBytes, rightOffset);
                 return compareLong(s, v2);
             }
             case INT32: {
-                int v2 = AInt32SerializerDeserializer.getInt(outRight.getByteArray(), 1);
+                int v2 = AInt32SerializerDeserializer.getInt(rightBytes, rightOffset);
                 return compareLong(s, v2);
             }
             case INT64: {
-                long v2 = AInt64SerializerDeserializer.getLong(outRight.getByteArray(), 1);
+                long v2 = AInt64SerializerDeserializer.getLong(rightBytes, rightOffset);
                 return compareLong(s, v2);
             }
             case FLOAT: {
-                float v2 = AFloatSerializerDeserializer.getFloat(outRight.getByteArray(), 1);
+                float v2 = AFloatSerializerDeserializer.getFloat(rightBytes, rightOffset);
                 return compareFloat(s, v2);
             }
             case DOUBLE: {
-                double v2 = ADoubleSerializerDeserializer.getDouble(outRight.getByteArray(), 1);
+                double v2 = ADoubleSerializerDeserializer.getDouble(rightBytes, rightOffset);
                 return compareDouble(s, v2);
             }
             default: {
@@ -408,30 +437,35 @@ public abstract class AbstractComparisonEvaluator implements ICopyEvaluator {
     }
 
     private ComparisonResult compareInt32WithArg(ATypeTag typeTag2) throws AlgebricksException {
-        int s = IntegerPointable.getInteger(outLeft.getByteArray(), 1);
+        byte[] leftBytes = outLeft.getByteArray();
+        int leftOffset = outLeft.getStartOffset() + 1;
+        byte[] rightBytes = outRight.getByteArray();
+        int rightOffset = outRight.getStartOffset() + 1;
+
+        int s = IntegerPointable.getInteger(leftBytes, leftOffset);
         switch (typeTag2) {
             case INT8: {
-                byte v2 = AInt8SerializerDeserializer.getByte(outRight.getByteArray(), 1);
+                byte v2 = AInt8SerializerDeserializer.getByte(rightBytes, rightOffset);
                 return compareInt(s, v2);
             }
             case INT16: {
-                short v2 = AInt16SerializerDeserializer.getShort(outRight.getByteArray(), 1);
+                short v2 = AInt16SerializerDeserializer.getShort(rightBytes, rightOffset);
                 return compareInt(s, v2);
             }
             case INT32: {
-                int v2 = AInt32SerializerDeserializer.getInt(outRight.getByteArray(), 1);
+                int v2 = AInt32SerializerDeserializer.getInt(rightBytes, rightOffset);
                 return compareInt(s, v2);
             }
             case INT64: {
-                long v2 = AInt64SerializerDeserializer.getLong(outRight.getByteArray(), 1);
+                long v2 = AInt64SerializerDeserializer.getLong(rightBytes, rightOffset);
                 return compareLong(s, v2);
             }
             case FLOAT: {
-                float v2 = AFloatSerializerDeserializer.getFloat(outRight.getByteArray(), 1);
+                float v2 = AFloatSerializerDeserializer.getFloat(rightBytes, rightOffset);
                 return compareFloat(s, v2);
             }
             case DOUBLE: {
-                double v2 = ADoubleSerializerDeserializer.getDouble(outRight.getByteArray(), 1);
+                double v2 = ADoubleSerializerDeserializer.getDouble(rightBytes, rightOffset);
                 return compareDouble(s, v2);
             }
             default: {
@@ -441,30 +475,35 @@ public abstract class AbstractComparisonEvaluator implements ICopyEvaluator {
     }
 
     private ComparisonResult compareInt16WithArg(ATypeTag typeTag2) throws AlgebricksException {
-        short s = AInt16SerializerDeserializer.getShort(outLeft.getByteArray(), 1);
+        byte[] leftBytes = outLeft.getByteArray();
+        int leftOffset = outLeft.getStartOffset() + 1;
+        byte[] rightBytes = outRight.getByteArray();
+        int rightOffset = outRight.getStartOffset() + 1;
+
+        short s = AInt16SerializerDeserializer.getShort(leftBytes, leftOffset);
         switch (typeTag2) {
             case INT8: {
-                byte v2 = AInt8SerializerDeserializer.getByte(outRight.getByteArray(), 1);
+                byte v2 = AInt8SerializerDeserializer.getByte(rightBytes, rightOffset);
                 return compareShort(s, v2);
             }
             case INT16: {
-                short v2 = AInt16SerializerDeserializer.getShort(outRight.getByteArray(), 1);
+                short v2 = AInt16SerializerDeserializer.getShort(rightBytes, rightOffset);
                 return compareShort(s, v2);
             }
             case INT32: {
-                int v2 = AInt32SerializerDeserializer.getInt(outRight.getByteArray(), 1);
+                int v2 = AInt32SerializerDeserializer.getInt(rightBytes, rightOffset);
                 return compareInt(s, v2);
             }
             case INT64: {
-                long v2 = AInt64SerializerDeserializer.getLong(outRight.getByteArray(), 1);
+                long v2 = AInt64SerializerDeserializer.getLong(rightBytes, rightOffset);
                 return compareLong(s, v2);
             }
             case FLOAT: {
-                float v2 = AFloatSerializerDeserializer.getFloat(outRight.getByteArray(), 1);
+                float v2 = AFloatSerializerDeserializer.getFloat(rightBytes, rightOffset);
                 return compareFloat(s, v2);
             }
             case DOUBLE: {
-                double v2 = ADoubleSerializerDeserializer.getDouble(outRight.getByteArray(), 1);
+                double v2 = ADoubleSerializerDeserializer.getDouble(rightBytes, rightOffset);
                 return compareDouble(s, v2);
             }
             default: {
@@ -474,30 +513,35 @@ public abstract class AbstractComparisonEvaluator implements ICopyEvaluator {
     }
 
     private ComparisonResult compareInt8WithArg(ATypeTag typeTag2) throws AlgebricksException {
-        byte s = AInt8SerializerDeserializer.getByte(outLeft.getByteArray(), 1);
+        byte[] leftBytes = outLeft.getByteArray();
+        int leftStart = outLeft.getStartOffset() + 1;
+        byte[] rightBytes = outRight.getByteArray();
+        int rightStart = outRight.getStartOffset() + 1;
+
+        byte s = AInt8SerializerDeserializer.getByte(leftBytes, leftStart);
         switch (typeTag2) {
             case INT8: {
-                byte v2 = AInt8SerializerDeserializer.getByte(outRight.getByteArray(), 1);
+                byte v2 = AInt8SerializerDeserializer.getByte(rightBytes, rightStart);
                 return compareByte(s, v2);
             }
             case INT16: {
-                short v2 = AInt16SerializerDeserializer.getShort(outRight.getByteArray(), 1);
+                short v2 = AInt16SerializerDeserializer.getShort(rightBytes, rightStart);
                 return compareShort(s, v2);
             }
             case INT32: {
-                int v2 = AInt32SerializerDeserializer.getInt(outRight.getByteArray(), 1);
+                int v2 = AInt32SerializerDeserializer.getInt(rightBytes, rightStart);
                 return compareInt(s, v2);
             }
             case INT64: {
-                long v2 = AInt64SerializerDeserializer.getLong(outRight.getByteArray(), 1);
+                long v2 = AInt64SerializerDeserializer.getLong(rightBytes, rightStart);
                 return compareLong(s, v2);
             }
             case FLOAT: {
-                float v2 = AFloatSerializerDeserializer.getFloat(outRight.getByteArray(), 1);
+                float v2 = AFloatSerializerDeserializer.getFloat(rightBytes, rightStart);
                 return compareFloat(s, v2);
             }
             case DOUBLE: {
-                double v2 = ADoubleSerializerDeserializer.getDouble(outRight.getByteArray(), 1);
+                double v2 = ADoubleSerializerDeserializer.getDouble(rightBytes, rightStart);
                 return compareDouble(s, v2);
             }
             default: {

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/ComparisonEvalFactory.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/ComparisonEvalFactory.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/ComparisonEvalFactory.java
index bc210c5..8c515b9 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/ComparisonEvalFactory.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/comparisons/ComparisonEvalFactory.java
@@ -18,27 +18,25 @@
  */
 package org.apache.asterix.runtime.evaluators.comparisons;
 
-import java.io.DataOutput;
-
 import org.apache.asterix.om.base.ABoolean;
 import org.apache.asterix.om.base.ANull;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.AlgebricksBuiltinFunctions.ComparisonKind;
-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.dataflow.common.data.accessors.IFrameTupleReference;
 
-public class ComparisonEvalFactory implements ICopyEvaluatorFactory {
-
+public class ComparisonEvalFactory implements IScalarEvaluatorFactory {
     private static final long serialVersionUID = 1L;
 
-    private ICopyEvaluatorFactory evalLeftFactory;
-    private ICopyEvaluatorFactory evalRightFactory;
+    private IScalarEvaluatorFactory evalLeftFactory;
+    private IScalarEvaluatorFactory evalRightFactory;
     private ComparisonKind comparisonKind;
 
-    public ComparisonEvalFactory(ICopyEvaluatorFactory evalLeftFactory, ICopyEvaluatorFactory evalRightFactory,
+    public ComparisonEvalFactory(IScalarEvaluatorFactory evalLeftFactory, IScalarEvaluatorFactory evalRightFactory,
             ComparisonKind comparisonKind) {
         this.evalLeftFactory = evalLeftFactory;
         this.evalRightFactory = evalRightFactory;
@@ -46,27 +44,26 @@ public class ComparisonEvalFactory implements ICopyEvaluatorFactory {
     }
 
     @Override
-    public ICopyEvaluator createEvaluator(IDataOutputProvider output) throws AlgebricksException {
-        DataOutput out = output.getDataOutput();
+    public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
         switch (comparisonKind) {
-        // Should we do any normalization?
+            // Should we do any normalization?
             case EQ: {
-                return new EqualityComparisonEvaluator(out, evalLeftFactory, evalRightFactory);
+                return new EqualityComparisonEvaluator(evalLeftFactory, evalRightFactory, ctx);
             }
             case GE: {
-                return new GreaterThanOrEqualComparisonEvaluator(out, evalLeftFactory, evalRightFactory);
+                return new GreaterThanOrEqualComparisonEvaluator(evalLeftFactory, evalRightFactory, ctx);
             }
             case GT: {
-                return new GreaterThanComparisonEvaluator(out, evalLeftFactory, evalRightFactory);
+                return new GreaterThanComparisonEvaluator(evalLeftFactory, evalRightFactory, ctx);
             }
             case LE: {
-                return new LessThanOrEqualComparisonEvaluator(out, evalLeftFactory, evalRightFactory);
+                return new LessThanOrEqualComparisonEvaluator(evalLeftFactory, evalRightFactory, ctx);
             }
             case LT: {
-                return new LessThanComparisonEvaluator(out, evalLeftFactory, evalRightFactory);
+                return new LessThanComparisonEvaluator(evalLeftFactory, evalRightFactory, ctx);
             }
             case NEQ: {
-                return new InequalityComparisonEvaluator(out, evalLeftFactory, evalRightFactory);
+                return new InequalityComparisonEvaluator(evalLeftFactory, evalRightFactory, ctx);
             }
             default: {
                 throw new IllegalStateException();
@@ -75,21 +72,22 @@ public class ComparisonEvalFactory implements ICopyEvaluatorFactory {
     }
 
     static class EqualityComparisonEvaluator extends AbstractComparisonEvaluator {
-        public EqualityComparisonEvaluator(DataOutput out, ICopyEvaluatorFactory evalLeftFactory,
-                ICopyEvaluatorFactory evalRightFactory) throws AlgebricksException {
-            super(out, evalLeftFactory, evalRightFactory);
+        public EqualityComparisonEvaluator(IScalarEvaluatorFactory evalLeftFactory,
+                IScalarEvaluatorFactory evalRightFactory, IHyracksTaskContext context) throws AlgebricksException {
+            super(evalLeftFactory, evalRightFactory, context);
         }
 
         @Override
-        public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+        public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+            resultStorage.reset();
             evalInputs(tuple);
-
             // Checks whether two types are comparable
             switch (comparabilityCheck()) {
                 case UNKNOWN:
                     // result:UNKNOWN - NULL value found
                     try {
                         nullSerde.serialize(ANull.NULL, out);
+                        result.set(resultStorage);
                         return;
                     } catch (HyracksDataException e) {
                         throw new AlgebricksException(e);
@@ -117,19 +115,20 @@ public class ComparisonEvalFactory implements ICopyEvaluatorFactory {
                     throw new AlgebricksException(
                             "Equality Comparison cannot be processed. The return code from ComparabilityCheck is not correct.");
             }
-
+            result.set(resultStorage);
         }
 
     }
 
     static class InequalityComparisonEvaluator extends AbstractComparisonEvaluator {
-        public InequalityComparisonEvaluator(DataOutput out, ICopyEvaluatorFactory evalLeftFactory,
-                ICopyEvaluatorFactory evalRightFactory) throws AlgebricksException {
-            super(out, evalLeftFactory, evalRightFactory);
+        public InequalityComparisonEvaluator(IScalarEvaluatorFactory evalLeftFactory,
+                IScalarEvaluatorFactory evalRightFactory, IHyracksTaskContext context) throws AlgebricksException {
+            super(evalLeftFactory, evalRightFactory, context);
         }
 
         @Override
-        public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+        public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+            resultStorage.reset();
             evalInputs(tuple);
 
             // Checks whether two types are comparable
@@ -138,6 +137,7 @@ public class ComparisonEvalFactory implements ICopyEvaluatorFactory {
                     // result:UNKNOWN - NULL value found
                     try {
                         nullSerde.serialize(ANull.NULL, out);
+                        result.set(resultStorage);
                         return;
                     } catch (HyracksDataException e) {
                         throw new AlgebricksException(e);
@@ -165,19 +165,20 @@ public class ComparisonEvalFactory implements ICopyEvaluatorFactory {
                     throw new AlgebricksException(
                             "Inequality Comparison cannot be processed. The return code from ComparabilityCheck is not correct.");
             }
-
+            result.set(resultStorage);
         }
 
     }
 
     static class GreaterThanOrEqualComparisonEvaluator extends AbstractComparisonEvaluator {
-        public GreaterThanOrEqualComparisonEvaluator(DataOutput out, ICopyEvaluatorFactory evalLeftFactory,
-                ICopyEvaluatorFactory evalRightFactory) throws AlgebricksException {
-            super(out, evalLeftFactory, evalRightFactory);
+        public GreaterThanOrEqualComparisonEvaluator(IScalarEvaluatorFactory evalLeftFactory,
+                IScalarEvaluatorFactory evalRightFactory, IHyracksTaskContext context) throws AlgebricksException {
+            super(evalLeftFactory, evalRightFactory, context);
         }
 
         @Override
-        public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+        public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+            resultStorage.reset();
             evalInputs(tuple);
 
             // checks whether we can apply >, >=, <, and <= to the given type since
@@ -190,6 +191,7 @@ public class ComparisonEvalFactory implements ICopyEvaluatorFactory {
                     // result:UNKNOWN - NULL value found
                     try {
                         nullSerde.serialize(ANull.NULL, out);
+                        result.set(resultStorage);
                         return;
                     } catch (HyracksDataException e) {
                         throw new AlgebricksException(e);
@@ -218,19 +220,20 @@ public class ComparisonEvalFactory implements ICopyEvaluatorFactory {
                     throw new AlgebricksException(
                             "Inequality Comparison cannot be processed. The return code from ComparabilityCheck is not correct.");
             }
-
+            result.set(resultStorage);
         }
 
     }
 
     static class GreaterThanComparisonEvaluator extends AbstractComparisonEvaluator {
-        public GreaterThanComparisonEvaluator(DataOutput out, ICopyEvaluatorFactory evalLeftFactory,
-                ICopyEvaluatorFactory evalRightFactory) throws AlgebricksException {
-            super(out, evalLeftFactory, evalRightFactory);
+        public GreaterThanComparisonEvaluator(IScalarEvaluatorFactory evalLeftFactory,
+                IScalarEvaluatorFactory evalRightFactory, IHyracksTaskContext context) throws AlgebricksException {
+            super(evalLeftFactory, evalRightFactory, context);
         }
 
         @Override
-        public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+        public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+            resultStorage.reset();
             evalInputs(tuple);
 
             // checks whether we can apply >, >=, <, and <= to the given type since
@@ -243,6 +246,7 @@ public class ComparisonEvalFactory implements ICopyEvaluatorFactory {
                     // result:UNKNOWN - NULL value found
                     try {
                         nullSerde.serialize(ANull.NULL, out);
+                        result.set(resultStorage);
                         return;
                     } catch (HyracksDataException e) {
                         throw new AlgebricksException(e);
@@ -270,19 +274,20 @@ public class ComparisonEvalFactory implements ICopyEvaluatorFactory {
                     throw new AlgebricksException(
                             "Inequality Comparison cannot be processed. The return code from ComparabilityCheck is not correct.");
             }
-
+            result.set(resultStorage);
         }
 
     }
 
     static class LessThanOrEqualComparisonEvaluator extends AbstractComparisonEvaluator {
-        public LessThanOrEqualComparisonEvaluator(DataOutput out, ICopyEvaluatorFactory evalLeftFactory,
-                ICopyEvaluatorFactory evalRightFactory) throws AlgebricksException {
-            super(out, evalLeftFactory, evalRightFactory);
+        public LessThanOrEqualComparisonEvaluator(IScalarEvaluatorFactory evalLeftFactory,
+                IScalarEvaluatorFactory evalRightFactory, IHyracksTaskContext context) throws AlgebricksException {
+            super(evalLeftFactory, evalRightFactory, context);
         }
 
         @Override
-        public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+        public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+            resultStorage.reset();
             evalInputs(tuple);
 
             // checks whether we can apply >, >=, <, and <= to the given type since
@@ -295,6 +300,7 @@ public class ComparisonEvalFactory implements ICopyEvaluatorFactory {
                     // result:UNKNOWN - NULL value found
                     try {
                         nullSerde.serialize(ANull.NULL, out);
+                        result.set(resultStorage);
                         return;
                     } catch (HyracksDataException e) {
                         throw new AlgebricksException(e);
@@ -323,19 +329,20 @@ public class ComparisonEvalFactory implements ICopyEvaluatorFactory {
                     throw new AlgebricksException(
                             "Inequality Comparison cannot be processed. The return code from ComparabilityCheck is not correct.");
             }
-
+            result.set(resultStorage);
         }
 
     }
 
     static class LessThanComparisonEvaluator extends AbstractComparisonEvaluator {
-        public LessThanComparisonEvaluator(DataOutput out, ICopyEvaluatorFactory evalLeftFactory,
-                ICopyEvaluatorFactory evalRightFactory) throws AlgebricksException {
-            super(out, evalLeftFactory, evalRightFactory);
+        public LessThanComparisonEvaluator(IScalarEvaluatorFactory evalLeftFactory,
+                IScalarEvaluatorFactory evalRightFactory, IHyracksTaskContext context) throws AlgebricksException {
+            super(evalLeftFactory, evalRightFactory, context);
         }
 
         @Override
-        public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+        public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+            resultStorage.reset();
             evalInputs(tuple);
 
             // checks whether we can apply >, >=, <, and <= to the given type since
@@ -348,6 +355,7 @@ public class ComparisonEvalFactory implements ICopyEvaluatorFactory {
                     // result:UNKNOWN - NULL value found
                     try {
                         nullSerde.serialize(ANull.NULL, out);
+                        result.set(resultStorage);
                         return;
                     } catch (HyracksDataException e) {
                         throw new AlgebricksException(e);
@@ -375,7 +383,7 @@ public class ComparisonEvalFactory implements ICopyEvaluatorFactory {
                     throw new AlgebricksException(
                             "Inequality Comparison cannot be processed. The return code from ComparabilityCheck is not correct.");
             }
-
+            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/constructors/ABinaryBase64StringConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ABinaryBase64StringConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ABinaryBase64StringConstructorDescriptor.java
index a589aa7..2d1155b 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ABinaryBase64StringConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ABinaryBase64StringConstructorDescriptor.java
@@ -24,9 +24,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.dataflow.common.data.parsers.ByteArrayBase64ParserFactory;
 
 public class ABinaryBase64StringConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
@@ -39,14 +39,15 @@ public class ABinaryBase64StringConstructorDescriptor extends AbstractScalarFunc
     };
 
     @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(IDataOutputProvider output) throws AlgebricksException {
-                return new ABinaryHexStringConstructorDescriptor.ABinaryConstructorEvaluator(output, args[0],
-                        ByteArrayBase64ParserFactory.INSTANCE);
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
+                return new ABinaryHexStringConstructorDescriptor.ABinaryConstructorEvaluator(args[0],
+                        ByteArrayBase64ParserFactory.INSTANCE, ctx);
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ABinaryHexStringConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ABinaryHexStringConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ABinaryHexStringConstructorDescriptor.java
index 7b38f50..422f325 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ABinaryHexStringConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ABinaryHexStringConstructorDescriptor.java
@@ -32,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.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.dataflow.common.data.accessors.IFrameTupleReference;
 import org.apache.hyracks.dataflow.common.data.parsers.ByteArrayHexParserFactory;
@@ -53,13 +55,14 @@ public class ABinaryHexStringConstructorDescriptor extends AbstractScalarFunctio
     };
 
     @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 ABinaryConstructorEvaluator(output, args[0], ByteArrayHexParserFactory.INSTANCE);
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
+                return new ABinaryConstructorEvaluator(args[0], ByteArrayHexParserFactory.INSTANCE, ctx);
             }
         };
     }
@@ -69,10 +72,11 @@ public class ABinaryHexStringConstructorDescriptor extends AbstractScalarFunctio
         return AsterixBuiltinFunctions.BINARY_HEX_CONSTRUCTOR;
     }
 
-    static class ABinaryConstructorEvaluator implements ICopyEvaluator {
-        private DataOutput out;
-        private ArrayBackedValueStorage outInput;
-        private ICopyEvaluator eval;
+    static class ABinaryConstructorEvaluator implements IScalarEvaluator {
+        private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+        private final DataOutput out = resultStorage.getDataOutput();
+        private final IPointable inputArg = new VoidPointable();
+        private final IScalarEvaluator eval;
         private IValueParser byteArrayParser;
         private UTF8StringPointable utf8Ptr = new UTF8StringPointable();
 
@@ -80,33 +84,34 @@ public class ABinaryHexStringConstructorDescriptor extends AbstractScalarFunctio
         private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                 .getSerializerDeserializer(BuiltinType.ANULL);
 
-        public ABinaryConstructorEvaluator(final IDataOutputProvider output, ICopyEvaluatorFactory copyEvaluatorFactory,
-                IValueParserFactory valueParserFactory) throws AlgebricksException {
-            out = output.getDataOutput();
-            outInput = new ArrayBackedValueStorage();
-            eval = copyEvaluatorFactory.createEvaluator(outInput);
+        public ABinaryConstructorEvaluator(IScalarEvaluatorFactory copyEvaluatorFactory,
+                IValueParserFactory valueParserFactory, IHyracksTaskContext context) throws AlgebricksException {
+            eval = copyEvaluatorFactory.createScalarEvaluator(context);
             byteArrayParser = valueParserFactory.createValueParser();
         }
 
         @Override
-        public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-
+        public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
             try {
-                outInput.reset();
-                eval.evaluate(tuple);
-                byte[] binary = outInput.getByteArray();
+                eval.evaluate(tuple, inputArg);
+                byte[] binary = inputArg.getByteArray();
+                int startOffset = inputArg.getStartOffset();
+                int len = inputArg.getLength();
 
-                ATypeTag tt = ATypeTag.VALUE_TYPE_MAPPING[binary[0]];
+                ATypeTag tt = ATypeTag.VALUE_TYPE_MAPPING[binary[startOffset]];
                 if (tt == ATypeTag.NULL) {
+                    resultStorage.reset();
                     nullSerde.serialize(ANull.NULL, out);
+                    result.set(resultStorage);
                 } else if (tt == ATypeTag.BINARY) {
-                    out.write(outInput.getByteArray(), outInput.getStartOffset(), outInput.getLength());
+                    result.set(inputArg);
                 } else if (tt == ATypeTag.STRING) {
-                    utf8Ptr.set(outInput.getByteArray(), 1, outInput.getLength() - 1);
-
+                    resultStorage.reset();
+                    utf8Ptr.set(inputArg.getByteArray(), startOffset + 1, len - 1);
                     char[] buffer = utf8Ptr.toString().toCharArray();
                     out.write(ATypeTag.BINARY.serialize());
                     byteArrayParser.parse(buffer, 0, buffer.length, out);
+                    result.set(resultStorage);
                 } else {
                     throw new AlgebricksException("binary type of " + tt + "haven't implemented yet.");
                 }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ABooleanConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ABooleanConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ABooleanConstructorDescriptor.java
index c07d6f4..0f36310 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ABooleanConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ABooleanConstructorDescriptor.java
@@ -33,11 +33,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.IBinaryComparator;
 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,17 @@ public class ABooleanConstructorDescriptor extends AbstractScalarFunctionDynamic
     };
 
     @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 ArrayBackedValueStorage outInput = new ArrayBackedValueStorage();
-                    private ICopyEvaluator eval = args[0].createEvaluator(outInput);
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
+                return new IScalarEvaluator() {
+                    private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+                    private DataOutput out = resultStorage.getDataOutput();
+                    private IPointable inputArg = new VoidPointable();
+                    private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
                     private String errorMessage = "This can not be an instance of boolean";
                     private final byte[] TRUE = UTF8StringUtil.writeStringToBytes("true");
                     private final byte[] FALSE = UTF8StringUtil.writeStringToBytes("false");
@@ -76,28 +78,34 @@ public class ABooleanConstructorDescriptor extends AbstractScalarFunctionDynamic
                             .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();
-                            if (serString[0] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
-                                if (utf8BinaryComparator.compare(serString, 1, outInput.getLength(), TRUE, 0,
+                            resultStorage.reset();
+                            eval.evaluate(tuple, inputArg);
+                            byte[] serString = inputArg.getByteArray();
+                            int startOffset = inputArg.getStartOffset();
+                            int len = inputArg.getLength();
+
+                            if (serString[startOffset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
+                                if (utf8BinaryComparator.compare(serString, startOffset + 1, len - 1, TRUE, 0,
                                         TRUE.length) == 0) {
                                     booleanSerde.serialize(ABoolean.TRUE, out);
+                                    result.set(resultStorage);
                                     return;
-                                } else if (utf8BinaryComparator.compare(serString, 1, outInput.getLength(), FALSE, 0,
+                                } else if (utf8BinaryComparator.compare(serString, startOffset + 1, len - 1, FALSE, 0,
                                         FALSE.length) == 0) {
                                     booleanSerde.serialize(ABoolean.FALSE, out);
+                                    result.set(resultStorage);
                                     return;
-                                } else
+                                } else {
                                     throw new AlgebricksException(errorMessage);
-
-                            } else if (serString[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG)
+                                }
+                            } else if (serString[startOffset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
                                 nullSerde.serialize(ANull.NULL, out);
-                            else
+                            } else {
                                 throw new AlgebricksException(errorMessage);
+                            }
+                            result.set(resultStorage);
                         } catch (IOException e1) {
                             throw new AlgebricksException(errorMessage);
                         }
@@ -105,6 +113,7 @@ public class ABooleanConstructorDescriptor extends AbstractScalarFunctionDynamic
                 };
             }
         };
+
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ACircleConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ACircleConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ACircleConstructorDescriptor.java
index e91cf0d..3c9c04f 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ACircleConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ACircleConstructorDescriptor.java
@@ -34,11 +34,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.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.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -53,20 +55,19 @@ public class ACircleConstructorDescriptor extends AbstractScalarFunctionDynamicD
     };
 
     @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 ArrayBackedValueStorage outInput = new ArrayBackedValueStorage();
-                    private ICopyEvaluator eval = args[0].createEvaluator(outInput);
-                    private String errorMessage = "This can not be an instance of circle";
-                    private AMutablePoint aPoint = new AMutablePoint(0, 0);
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
+                return new IScalarEvaluator() {
+                    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 String errorMessage = "This can not be an instance of circle";
+                    private final AMutablePoint aPoint = new AMutablePoint(0, 0);
                     private AMutableCircle aCircle = new AMutableCircle(null, 0);
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ACircle> circleSerde = AqlSerializerDeserializerProvider.INSTANCE
@@ -78,14 +79,17 @@ public class ACircleConstructorDescriptor extends AbstractScalarFunctionDynamicD
                     private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
 
                     @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();
-                            if (serString[0] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
-                                utf8Ptr.set(serString, 1, outInput.getLength() - 1);
+                            resultStorage.reset();
+                            eval.evaluate(tuple, inputArg);
+
+                            byte[] serString = inputArg.getByteArray();
+                            int offset = inputArg.getStartOffset();
+                            int len = inputArg.getLength();
+
+                            if (serString[offset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
+                                utf8Ptr.set(serString, offset + 1, len - 1);
                                 String s = utf8Ptr.toString();
                                 int commaIndex = s.indexOf(',');
                                 int spaceIndex = s.indexOf(' ', commaIndex + 1);
@@ -93,10 +97,12 @@ public class ACircleConstructorDescriptor extends AbstractScalarFunctionDynamicD
                                         Double.parseDouble(s.substring(commaIndex + 1, spaceIndex)));
                                 aCircle.setValue(aPoint, Double.parseDouble(s.substring(spaceIndex + 1, s.length())));
                                 circleSerde.serialize(aCircle, 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(errorMessage);
+                            }
+                            result.set(resultStorage);
                         } catch (IOException e1) {
                             throw new AlgebricksException(errorMessage);
                         }
@@ -104,6 +110,7 @@ public class ACircleConstructorDescriptor extends AbstractScalarFunctionDynamicD
                 };
             }
         };
+
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADateConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADateConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADateConstructorDescriptor.java
index 5c43f15..fcd2c00 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADateConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADateConstructorDescriptor.java
@@ -35,11 +35,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.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.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -53,18 +55,18 @@ public class ADateConstructorDescriptor extends AbstractScalarFunctionDynamicDes
     };
 
     @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(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 String errorMessage = "This can not be an instance of date";
                     private AMutableDate aDate = new AMutableDate(0);
                     @SuppressWarnings("unchecked")
@@ -77,15 +79,16 @@ public class ADateConstructorDescriptor extends AbstractScalarFunctionDynamicDes
                     private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
 
                     @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();
-                            if (serString[0] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
-
-                                utf8Ptr.set(serString, 1, outInput.getLength() - 1);
+                            resultStorage.reset();
+                            eval.evaluate(tuple, inputArg);
+                            byte[] serString = inputArg.getByteArray();
+                            int offset = inputArg.getStartOffset();
+                            int len = inputArg.getLength();
+
+                            if (serString[offset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
+                                utf8Ptr.set(serString, offset + 1, len - 1);
                                 int stringLength = utf8Ptr.getUTF8Length();
 
                                 // the string to be parsed should be at least 8 characters: YYYYMMDD
@@ -116,11 +119,12 @@ public class ADateConstructorDescriptor extends AbstractScalarFunctionDynamicDes
                                 aDate.setValue((int) (chrononTimeInMs / GregorianCalendarSystem.CHRONON_OF_DAY) - temp);
 
                                 dateSerde.serialize(aDate, 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 {
                                 throw new AlgebricksException(errorMessage);
                             }
+                            result.set(resultStorage);
                         } catch (IOException e1) {
                             throw new AlgebricksException(errorMessage);
                         }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADateTimeConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADateTimeConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADateTimeConstructorDescriptor.java
index 3f6a746..722dd73 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADateTimeConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ADateTimeConstructorDescriptor.java
@@ -35,11 +35,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.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.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -53,18 +55,17 @@ public class ADateTimeConstructorDescriptor extends AbstractScalarFunctionDynami
     };
 
     @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 ArrayBackedValueStorage outInput = new ArrayBackedValueStorage();
-                    private ICopyEvaluator eval = args[0].createEvaluator(outInput);
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
+                return new IScalarEvaluator() {
+                    private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+                    private DataOutput out = resultStorage.getDataOutput();
+                    private IPointable inputArg = new VoidPointable();
+                    private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
                     private String errorMessage = "This can not be an instance of datetime";
                     private AMutableDateTime aDateTime = new AMutableDateTime(0L);
                     @SuppressWarnings("unchecked")
@@ -76,15 +77,16 @@ public class ADateTimeConstructorDescriptor extends AbstractScalarFunctionDynami
                     private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
 
                     @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();
-                            if (serString[0] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
-
-                                utf8Ptr.set(serString, 1, outInput.getLength() - 1);
+                            resultStorage.reset();
+                            eval.evaluate(tuple, inputArg);
+                            byte[] serString = inputArg.getByteArray();
+                            int offset = inputArg.getStartOffset();
+                            int len = inputArg.getLength();
+
+                            if (serString[offset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
+                                utf8Ptr.set(serString, offset + 1, len - 1);
                                 int stringLength = utf8Ptr.getUTF8Length();
                                 int startOffset = utf8Ptr.getCharStartOffset();
                                 // the string to be parsed should be at least 14 characters: YYYYMMDDhhmmss
@@ -113,11 +115,12 @@ public class ADateTimeConstructorDescriptor extends AbstractScalarFunctionDynami
 
                                 aDateTime.setValue(chrononTimeInMs);
                                 datetimeSerde.serialize(aDateTime, 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 {
                                 throw new AlgebricksException(errorMessage);
                             }
+                            result.set(resultStorage);
                         } catch (IOException e1) {
                             throw new AlgebricksException(errorMessage);
                         }


Mime
View raw message