asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From buyin...@apache.org
Subject [12/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:41 GMT
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/EditDistanceListIsFilterable.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/EditDistanceListIsFilterable.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/EditDistanceListIsFilterable.java
index c1936a6..01ddb55 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/EditDistanceListIsFilterable.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/EditDistanceListIsFilterable.java
@@ -18,6 +18,7 @@
  */
 package org.apache.asterix.runtime.evaluators.functions;
 
+import java.io.DataOutput;
 import java.io.IOException;
 
 import org.apache.asterix.dataflow.data.nontagged.serde.AOrderedListSerializerDeserializer;
@@ -34,11 +35,13 @@ import org.apache.asterix.om.types.hierachy.ATypeHierarchy;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
 import org.apache.hyracks.api.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;
 
@@ -54,19 +57,21 @@ public class EditDistanceListIsFilterable extends AbstractScalarFunctionDynamicD
     private static final long serialVersionUID = 1L;
 
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        @Override
         public IFunctionDescriptor createFunctionDescriptor() {
             return new EditDistanceListIsFilterable();
         }
     };
 
     @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 EditDistanceListIsFilterableEvaluator(args, output);
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
+                return new EditDistanceListIsFilterableEvaluator(args, ctx);
             }
         };
     }
@@ -76,41 +81,44 @@ public class EditDistanceListIsFilterable extends AbstractScalarFunctionDynamicD
         return AsterixBuiltinFunctions.EDIT_DISTANCE_LIST_IS_FILTERABLE;
     }
 
-    private static class EditDistanceListIsFilterableEvaluator implements ICopyEvaluator {
+    private static class EditDistanceListIsFilterableEvaluator implements IScalarEvaluator {
 
-        protected final ArrayBackedValueStorage argBuf = new ArrayBackedValueStorage();
-        protected final IDataOutputProvider output;
+        protected final IPointable argPtr = new VoidPointable();
+        protected final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+        protected final DataOutput output = resultStorage.getDataOutput();
 
-        protected final ICopyEvaluator listEval;
-        protected final ICopyEvaluator edThreshEval;
+        protected final IScalarEvaluator listEval;
+        protected final IScalarEvaluator edThreshEval;
 
         @SuppressWarnings("unchecked")
         private final ISerializerDeserializer<ABoolean> booleanSerde = AqlSerializerDeserializerProvider.INSTANCE
                 .getSerializerDeserializer(BuiltinType.ABOOLEAN);
 
-        public EditDistanceListIsFilterableEvaluator(ICopyEvaluatorFactory[] args, IDataOutputProvider output)
+        public EditDistanceListIsFilterableEvaluator(IScalarEvaluatorFactory[] args, IHyracksTaskContext context)
                 throws AlgebricksException {
-            this.output = output;
-            listEval = args[0].createEvaluator(argBuf);
-            edThreshEval = args[1].createEvaluator(argBuf);
+            listEval = args[0].createScalarEvaluator(context);
+            edThreshEval = args[1].createScalarEvaluator(context);
         }
 
         @Override
-        public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+        public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+            resultStorage.reset();
             ATypeTag typeTag = null;
 
             // Check type and compute string length.
-            argBuf.reset();
-            listEval.evaluate(tuple);
-            typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argBuf.getByteArray()[0]);
+            listEval.evaluate(tuple, argPtr);
+            byte[] bytes = argPtr.getByteArray();
+            int offset = argPtr.getStartOffset();
+
+            typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes[offset]);
             long listLen = 0;
             switch (typeTag) {
                 case UNORDEREDLIST: {
-                    listLen = AUnorderedListSerializerDeserializer.getNumberOfItems(argBuf.getByteArray(), 0);
+                    listLen = AUnorderedListSerializerDeserializer.getNumberOfItems(bytes, offset);
                     break;
                 }
                 case ORDEREDLIST: {
-                    listLen = AOrderedListSerializerDeserializer.getNumberOfItems(argBuf.getByteArray(), 0);
+                    listLen = AOrderedListSerializerDeserializer.getNumberOfItems(bytes, offset);
                     break;
                 }
                 default: {
@@ -121,13 +129,14 @@ public class EditDistanceListIsFilterable extends AbstractScalarFunctionDynamicD
             }
 
             // Check type and extract edit-distance threshold.
-            argBuf.reset();
-            edThreshEval.evaluate(tuple);
-            typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argBuf.getByteArray()[0]);
+            edThreshEval.evaluate(tuple, argPtr);
+            bytes = argPtr.getByteArray();
+            offset = argPtr.getStartOffset();
+            typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes[offset]);
             long edThresh;
 
             try {
-                edThresh = ATypeHierarchy.getIntegerValue(argBuf.getByteArray(), 0);
+                edThresh = ATypeHierarchy.getIntegerValue(bytes, offset);
             } catch (HyracksDataException e1) {
                 throw new AlgebricksException(e1);
             }
@@ -136,13 +145,14 @@ public class EditDistanceListIsFilterable extends AbstractScalarFunctionDynamicD
             long lowerBound = listLen - edThresh;
             try {
                 if (lowerBound <= 0) {
-                    booleanSerde.serialize(ABoolean.FALSE, output.getDataOutput());
+                    booleanSerde.serialize(ABoolean.FALSE, output);
                 } else {
-                    booleanSerde.serialize(ABoolean.TRUE, output.getDataOutput());
+                    booleanSerde.serialize(ABoolean.TRUE, output);
                 }
             } catch (IOException e) {
                 throw new AlgebricksException(e);
             }
+            result.set(resultStorage);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/EditDistanceStringIsFilterable.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/EditDistanceStringIsFilterable.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/EditDistanceStringIsFilterable.java
index 15ce3d4..a707e46 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/EditDistanceStringIsFilterable.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/EditDistanceStringIsFilterable.java
@@ -18,6 +18,7 @@
  */
 package org.apache.asterix.runtime.evaluators.functions;
 
+import java.io.DataOutput;
 import java.io.IOException;
 
 import org.apache.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
@@ -32,13 +33,15 @@ import org.apache.asterix.om.types.hierachy.ATypeHierarchy;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
 import org.apache.hyracks.api.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.BooleanPointable;
 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,19 +56,21 @@ public class EditDistanceStringIsFilterable extends AbstractScalarFunctionDynami
 
     private static final long serialVersionUID = 1L;
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        @Override
         public IFunctionDescriptor createFunctionDescriptor() {
             return new EditDistanceStringIsFilterable();
         }
     };
 
     @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 EditDistanceStringIsFilterableEvaluator(args, output);
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
+                return new EditDistanceStringIsFilterableEvaluator(args, ctx);
             }
         };
     }
@@ -75,15 +80,16 @@ public class EditDistanceStringIsFilterable extends AbstractScalarFunctionDynami
         return AsterixBuiltinFunctions.EDIT_DISTANCE_STRING_IS_FILTERABLE;
     }
 
-    private static class EditDistanceStringIsFilterableEvaluator implements ICopyEvaluator {
+    private static class EditDistanceStringIsFilterableEvaluator implements IScalarEvaluator {
 
-        protected final ArrayBackedValueStorage argBuf = new ArrayBackedValueStorage();
-        protected final IDataOutputProvider output;
+        protected final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+        protected final DataOutput output = resultStorage.getDataOutput();
+        protected final IPointable argPtr = new VoidPointable();
 
-        protected final ICopyEvaluator stringEval;
-        protected final ICopyEvaluator edThreshEval;
-        protected final ICopyEvaluator gramLenEval;
-        protected final ICopyEvaluator usePrePostEval;
+        protected final IScalarEvaluator stringEval;
+        protected final IScalarEvaluator edThreshEval;
+        protected final IScalarEvaluator gramLenEval;
+        protected final IScalarEvaluator usePrePostEval;
 
         @SuppressWarnings("unchecked")
         private final ISerializerDeserializer<ABoolean> booleanSerde = AqlSerializerDeserializerProvider.INSTANCE
@@ -91,78 +97,75 @@ public class EditDistanceStringIsFilterable extends AbstractScalarFunctionDynami
 
         private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
 
-        public EditDistanceStringIsFilterableEvaluator(ICopyEvaluatorFactory[] args, IDataOutputProvider output)
+        public EditDistanceStringIsFilterableEvaluator(IScalarEvaluatorFactory[] args, IHyracksTaskContext context)
                 throws AlgebricksException {
-            this.output = output;
-            stringEval = args[0].createEvaluator(argBuf);
-            edThreshEval = args[1].createEvaluator(argBuf);
-            gramLenEval = args[2].createEvaluator(argBuf);
-            usePrePostEval = args[3].createEvaluator(argBuf);
+            stringEval = args[0].createScalarEvaluator(context);
+            edThreshEval = args[1].createScalarEvaluator(context);
+            gramLenEval = args[2].createScalarEvaluator(context);
+            usePrePostEval = args[3].createScalarEvaluator(context);
         }
 
         @Override
-        public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+        public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+            resultStorage.reset();
             ATypeTag typeTag = null;
 
             // Check type and compute string length.
-            argBuf.reset();
-            stringEval.evaluate(tuple);
-            typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argBuf.getByteArray()[0]);
+            stringEval.evaluate(tuple, argPtr);
+            typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argPtr.getByteArray()[argPtr.getStartOffset()]);
             if (!typeTag.equals(ATypeTag.STRING)) {
                 throw new AlgebricksException(AsterixBuiltinFunctions.EDIT_DISTANCE_STRING_IS_FILTERABLE.getName()
                         + ": expects input type STRING as first argument, but got " + typeTag + ".");
             }
 
-            utf8Ptr.set(argBuf.getByteArray(), 1, argBuf.getLength());
+            utf8Ptr.set(argPtr.getByteArray(), argPtr.getStartOffset() + 1, argPtr.getLength());
             int strLen = utf8Ptr.getStringLength();
 
             // Check type and extract edit-distance threshold.
-            argBuf.reset();
-            edThreshEval.evaluate(tuple);
-            typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argBuf.getByteArray()[0]);
+            edThreshEval.evaluate(tuple, argPtr);
+            typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argPtr.getByteArray()[argPtr.getStartOffset()]);
 
             long edThresh = 0;
 
             try {
-                edThresh = ATypeHierarchy.getIntegerValue(argBuf.getByteArray(), 0);
+                edThresh = ATypeHierarchy.getIntegerValue(argPtr.getByteArray(), argPtr.getStartOffset());
             } catch (HyracksDataException e1) {
                 throw new AlgebricksException(e1);
             }
 
             // Check type and extract gram length.
-            argBuf.reset();
-            gramLenEval.evaluate(tuple);
-            typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argBuf.getByteArray()[0]);
+            gramLenEval.evaluate(tuple, argPtr);
+            typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argPtr.getByteArray()[argPtr.getStartOffset()]);
 
             long gramLen = 0;
             try {
-                gramLen = ATypeHierarchy.getIntegerValue(argBuf.getByteArray(), 0);
+                gramLen = ATypeHierarchy.getIntegerValue(argPtr.getByteArray(), argPtr.getStartOffset());
             } catch (HyracksDataException e1) {
                 throw new AlgebricksException(e1);
             }
 
             // Check type and extract usePrePost flag.
-            argBuf.reset();
-            usePrePostEval.evaluate(tuple);
-            typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argBuf.getByteArray()[0]);
+            usePrePostEval.evaluate(tuple, argPtr);
+            typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argPtr.getByteArray()[argPtr.getStartOffset()]);
             if (!typeTag.equals(ATypeTag.BOOLEAN)) {
                 throw new AlgebricksException(AsterixBuiltinFunctions.EDIT_DISTANCE_STRING_IS_FILTERABLE.getName()
                         + ": expects input type BOOLEAN as fourth argument, but got " + typeTag + ".");
             }
-            boolean usePrePost = BooleanPointable.getBoolean(argBuf.getByteArray(), 1);
+            boolean usePrePost = BooleanPointable.getBoolean(argPtr.getByteArray(), argPtr.getStartOffset() + 1);
 
             // Compute result.
             long numGrams = (usePrePost) ? strLen + gramLen - 1 : strLen - gramLen + 1;
             long lowerBound = numGrams - edThresh * gramLen;
             try {
                 if (lowerBound <= 0 || strLen == 0) {
-                    booleanSerde.serialize(ABoolean.FALSE, output.getDataOutput());
+                    booleanSerde.serialize(ABoolean.FALSE, output);
                 } else {
-                    booleanSerde.serialize(ABoolean.TRUE, output.getDataOutput());
+                    booleanSerde.serialize(ABoolean.TRUE, output);
                 }
             } catch (IOException e) {
                 throw new AlgebricksException(e);
             }
+            result.set(resultStorage);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/EmbedTypeDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/EmbedTypeDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/EmbedTypeDescriptor.java
index 4773f7d..0bfa5a8 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/EmbedTypeDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/EmbedTypeDescriptor.java
@@ -25,15 +25,17 @@ import org.apache.asterix.om.types.IAType;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.data.std.api.IPointable;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
 public class EmbedTypeDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        @Override
         public IFunctionDescriptor createFunctionDescriptor() {
             return new EmbedTypeDescriptor();
         }
@@ -47,18 +49,18 @@ public class EmbedTypeDescriptor extends AbstractScalarFunctionDynamicDescriptor
     }
 
     @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(IDataOutputProvider output) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
                 // TODO Auto-generated method stub
-                return new ICopyEvaluator() {
+                return new IScalarEvaluator() {
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
                         // TODO Auto-generated method stub
 
                     }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/FlowRecordDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/FlowRecordDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/FlowRecordDescriptor.java
index ec30302..5c9d8ef 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/FlowRecordDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/FlowRecordDescriptor.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;
@@ -30,15 +28,17 @@ import org.apache.asterix.om.types.ARecordType;
 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.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;
 
 public class FlowRecordDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        @Override
         public IFunctionDescriptor createFunctionDescriptor() {
             return new FlowRecordDescriptor();
         }
@@ -57,30 +57,28 @@ public class FlowRecordDescriptor extends AbstractScalarFunctionDynamicDescripto
     }
 
     @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(final 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.allocateRecordValue(inputType);
 
                     @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);
-                            out.write(recAccessor.getByteArray(), recAccessor.getStartOffset(), recAccessor.getLength());
+                            recEvaluator.evaluate(tuple, recordPtr);
+                            recAccessor.set(recordPtr);
+                            result.set(recAccessor);
                         } catch (Exception ioe) {
                             throw new AlgebricksException(ioe);
                         }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/FuzzyEqDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/FuzzyEqDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/FuzzyEqDescriptor.java
index 350e629..eaa6028 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/FuzzyEqDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/FuzzyEqDescriptor.java
@@ -25,7 +25,7 @@ import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicD
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.common.exceptions.NotImplementedException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
 
 public class FuzzyEqDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
@@ -37,7 +37,7 @@ public class FuzzyEqDescriptor extends AbstractScalarFunctionDynamicDescriptor {
     };
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(ICopyEvaluatorFactory[] args) throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) throws AlgebricksException {
         throw new NotImplementedException();
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/GetItemDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/GetItemDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/GetItemDescriptor.java
index ab58da2..020336f 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/GetItemDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/GetItemDescriptor.java
@@ -23,23 +23,21 @@ import java.io.IOException;
 
 import org.apache.asterix.common.exceptions.AsterixException;
 import org.apache.asterix.dataflow.data.nontagged.serde.AOrderedListSerializerDeserializer;
-import org.apache.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import org.apache.asterix.om.base.ANull;
 import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
 import org.apache.asterix.om.types.ATypeTag;
-import org.apache.asterix.om.types.BuiltinType;
 import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.asterix.om.types.hierachy.ATypeHierarchy;
 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.api.dataflow.value.ISerializerDeserializer;
-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;
 
@@ -54,7 +52,7 @@ public class GetItemDescriptor extends AbstractScalarFunctionDynamicDescriptor {
     };
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new GetItemEvalFactory(args);
     }
 
@@ -63,88 +61,94 @@ public class GetItemDescriptor extends AbstractScalarFunctionDynamicDescriptor {
         return AsterixBuiltinFunctions.GET_ITEM;
     }
 
-    private static class GetItemEvalFactory implements ICopyEvaluatorFactory {
+    private static class GetItemEvalFactory implements IScalarEvaluatorFactory {
 
         private static final long serialVersionUID = 1L;
-
-        private ICopyEvaluatorFactory listEvalFactory;
-        private ICopyEvaluatorFactory indexEvalFactory;
+        private IScalarEvaluatorFactory listEvalFactory;
+        private IScalarEvaluatorFactory indexEvalFactory;
         private byte serItemTypeTag;
         private ATypeTag itemTag;
         private boolean selfDescList = false;
 
-        public GetItemEvalFactory(ICopyEvaluatorFactory[] args) {
+        public GetItemEvalFactory(IScalarEvaluatorFactory[] args) {
             this.listEvalFactory = args[0];
             this.indexEvalFactory = args[1];
         }
 
         @Override
-        public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
-            return new ICopyEvaluator() {
-
-                private DataOutput out = output.getDataOutput();
-                private ArrayBackedValueStorage outInputList = new ArrayBackedValueStorage();
-                private ArrayBackedValueStorage outInputIdx = new ArrayBackedValueStorage();
-                private ICopyEvaluator evalList = listEvalFactory.createEvaluator(outInputList);
-                private ICopyEvaluator evalIdx = indexEvalFactory.createEvaluator(outInputIdx);
-                @SuppressWarnings("unchecked")
-                private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
-                        .getSerializerDeserializer(BuiltinType.ANULL);
+        public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+            return new IScalarEvaluator() {
+
+                private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+                private final DataOutput output = resultStorage.getDataOutput();
+                private IPointable inputArgList = new VoidPointable();
+                private IPointable inputArgIdx = new VoidPointable();
+                private IScalarEvaluator evalList = listEvalFactory.createScalarEvaluator(ctx);
+                private IScalarEvaluator evalIdx = indexEvalFactory.createScalarEvaluator(ctx);
+                private byte[] nullBytes = new byte[] { ATypeTag.SERIALIZED_NULL_TYPE_TAG };
                 private int itemIndex;
                 private int itemOffset;
                 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);
-                        outInputIdx.reset();
-                        evalIdx.evaluate(tuple);
-                        byte[] serOrderedList = outInputList.getByteArray();
-
-                        if (serOrderedList[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
-                            nullSerde.serialize(ANull.NULL, out);
+                        evalList.evaluate(tuple, inputArgList);
+                        evalIdx.evaluate(tuple, inputArgIdx);
+
+                        byte[] serOrderedList = inputArgList.getByteArray();
+                        int offset = inputArgList.getStartOffset();
+                        byte[] indexBytes = inputArgIdx.getByteArray();
+                        int indexOffset = inputArgIdx.getStartOffset();
+
+                        if (serOrderedList[offset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
+                            result.set(nullBytes, 0, 1);
                             return;
                         }
 
-                        if (serOrderedList[0] == ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG) {
-                            itemIndex = ATypeHierarchy.getIntegerValue(outInputIdx.getByteArray(), 0);
+                        if (serOrderedList[offset] == ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG) {
+                            itemIndex = ATypeHierarchy.getIntegerValue(indexBytes, indexOffset);
                         } else {
                             throw new AlgebricksException(AsterixBuiltinFunctions.GET_ITEM.getName()
                                     + ": expects input type (NULL/ORDEREDLIST, [INT8/16/32/64/FLOAT/DOUBLE]), but got ("
-                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serOrderedList[0]) + ", "
-                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(outInputIdx.getByteArray()[0])
+                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serOrderedList[offset]) + ", "
+                                    + EnumDeserializer.ATYPETAGDESERIALIZER
+                                            .deserialize(inputArgIdx.getByteArray()[offset])
                                     + ").");
                         }
 
-                        if (itemIndex >= AOrderedListSerializerDeserializer.getNumberOfItems(serOrderedList)) {
-                            out.writeByte(ATypeTag.SERIALIZED_NULL_TYPE_TAG);
+                        if (itemIndex >= AOrderedListSerializerDeserializer.getNumberOfItems(serOrderedList, offset)) {
+                            result.set(nullBytes, 0, 1);
                             return;
                         }
-                        if (itemIndex < 0)
+                        if (itemIndex < 0) {
                             throw new AlgebricksException(
                                     AsterixBuiltinFunctions.GET_ITEM.getName() + ": item index cannot be negative!");
+                        }
 
-                        itemTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serOrderedList[1]);
-                        if (itemTag == ATypeTag.ANY)
+                        itemTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serOrderedList[offset + 1]);
+                        if (itemTag == ATypeTag.ANY) {
                             selfDescList = true;
-                        else
-                            serItemTypeTag = serOrderedList[1];
+                        } else {
+                            serItemTypeTag = serOrderedList[offset + 1];
+                        }
 
-                        itemOffset = AOrderedListSerializerDeserializer.getItemOffset(serOrderedList, itemIndex);
+                        itemOffset = AOrderedListSerializerDeserializer.getItemOffset(serOrderedList, offset,
+                                itemIndex);
 
                         if (selfDescList) {
                             itemTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serOrderedList[itemOffset]);
                             itemLength = NonTaggedFormatUtil.getFieldValueLength(serOrderedList, itemOffset, itemTag,
                                     true) + 1;
-                            out.write(serOrderedList, itemOffset, itemLength);
+                            result.set(serOrderedList, itemOffset, itemLength);
                         } else {
                             itemLength = NonTaggedFormatUtil.getFieldValueLength(serOrderedList, itemOffset, itemTag,
                                     false);
-                            out.writeByte(serItemTypeTag);
-                            out.write(serOrderedList, itemOffset, itemLength);
+                            resultStorage.reset();
+                            output.writeByte(serItemTypeTag);
+                            output.write(serOrderedList, 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/GramTokensDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/GramTokensDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/GramTokensDescriptor.java
index 87aa1f6..3b7941e 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/GramTokensDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/GramTokensDescriptor.java
@@ -26,9 +26,9 @@ import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicD
 import org.apache.asterix.runtime.evaluators.common.GramTokensEvaluator;
 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.storage.am.lsm.invertedindex.tokenizers.ITokenFactory;
 import org.apache.hyracks.storage.am.lsm.invertedindex.tokenizers.NGramUTF8StringBinaryTokenizer;
 import org.apache.hyracks.storage.am.lsm.invertedindex.tokenizers.UTF8NGramTokenFactory;
@@ -37,6 +37,7 @@ public class GramTokensDescriptor extends AbstractScalarFunctionDynamicDescripto
 
     private static final long serialVersionUID = 1L;
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        @Override
         public IFunctionDescriptor createFunctionDescriptor() {
             return new GramTokensDescriptor();
         }
@@ -48,16 +49,17 @@ public class GramTokensDescriptor extends AbstractScalarFunctionDynamicDescripto
     }
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
-        return new ICopyEvaluatorFactory() {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
+            throws AlgebricksException {
+        return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public ICopyEvaluator createEvaluator(IDataOutputProvider output) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
                 ITokenFactory tokenFactory = new UTF8NGramTokenFactory();
                 NGramUTF8StringBinaryTokenizer tokenizer = new NGramUTF8StringBinaryTokenizer(3, true, true, true,
                         tokenFactory);
-                return new GramTokensEvaluator(args, output, tokenizer, BuiltinType.ASTRING);
+                return new GramTokensEvaluator(args, ctx, tokenizer, BuiltinType.ASTRING);
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/HashedGramTokensDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/HashedGramTokensDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/HashedGramTokensDescriptor.java
index 74ffc67..575dacf 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/HashedGramTokensDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/HashedGramTokensDescriptor.java
@@ -26,9 +26,9 @@ import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicD
 import org.apache.asterix.runtime.evaluators.common.GramTokensEvaluator;
 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.storage.am.lsm.invertedindex.tokenizers.HashedUTF8NGramTokenFactory;
 import org.apache.hyracks.storage.am.lsm.invertedindex.tokenizers.ITokenFactory;
 import org.apache.hyracks.storage.am.lsm.invertedindex.tokenizers.NGramUTF8StringBinaryTokenizer;
@@ -37,6 +37,7 @@ public class HashedGramTokensDescriptor extends AbstractScalarFunctionDynamicDes
 
     private static final long serialVersionUID = 1L;
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        @Override
         public IFunctionDescriptor createFunctionDescriptor() {
             return new HashedGramTokensDescriptor();
         }
@@ -48,16 +49,17 @@ public class HashedGramTokensDescriptor extends AbstractScalarFunctionDynamicDes
     }
 
     @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 {
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
                 ITokenFactory tokenFactory = new HashedUTF8NGramTokenFactory();
                 NGramUTF8StringBinaryTokenizer tokenizer = new NGramUTF8StringBinaryTokenizer(3, true, true, true,
                         tokenFactory);
-                return new GramTokensEvaluator(args, output, tokenizer, BuiltinType.AINT32);
+                return new GramTokensEvaluator(args, ctx, tokenizer, BuiltinType.AINT32);
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/HashedWordTokensDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/HashedWordTokensDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/HashedWordTokensDescriptor.java
index 33706ce..c32c6ae 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/HashedWordTokensDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/HashedWordTokensDescriptor.java
@@ -26,9 +26,9 @@ import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicD
 import org.apache.asterix.runtime.evaluators.common.WordTokensEvaluator;
 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.storage.am.lsm.invertedindex.tokenizers.DelimitedUTF8StringBinaryTokenizer;
 import org.apache.hyracks.storage.am.lsm.invertedindex.tokenizers.HashedUTF8WordTokenFactory;
 import org.apache.hyracks.storage.am.lsm.invertedindex.tokenizers.IBinaryTokenizer;
@@ -38,6 +38,7 @@ public class HashedWordTokensDescriptor extends AbstractScalarFunctionDynamicDes
 
     private static final long serialVersionUID = 1L;
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        @Override
         public IFunctionDescriptor createFunctionDescriptor() {
             return new HashedWordTokensDescriptor();
         }
@@ -49,15 +50,16 @@ public class HashedWordTokensDescriptor extends AbstractScalarFunctionDynamicDes
     }
 
     @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 {
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
                 ITokenFactory tokenFactory = new HashedUTF8WordTokenFactory();
                 IBinaryTokenizer tokenizer = new DelimitedUTF8StringBinaryTokenizer(true, true, tokenFactory);
-                return new WordTokensEvaluator(args, output, tokenizer, BuiltinType.AINT32);
+                return new WordTokensEvaluator(args, ctx, tokenizer, BuiltinType.AINT32);
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/InjectFailureDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/InjectFailureDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/InjectFailureDescriptor.java
index f402cec..0d1cf4d 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/InjectFailureDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/InjectFailureDescriptor.java
@@ -18,8 +18,6 @@
  */
 package org.apache.asterix.runtime.evaluators.functions;
 
-import java.io.IOException;
-
 import org.apache.asterix.dataflow.data.nontagged.serde.ABooleanSerializerDeserializer;
 import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
@@ -29,16 +27,18 @@ import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-import org.apache.hyracks.data.std.api.IDataOutputProvider;
-import org.apache.hyracks.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;
 
 public class InjectFailureDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        @Override
         public IFunctionDescriptor createFunctionDescriptor() {
             return new InjectFailureDescriptor();
         }
@@ -50,44 +50,39 @@ public class InjectFailureDescriptor extends AbstractScalarFunctionDynamicDescri
     }
 
     @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 {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
 
-                final ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
-                final ICopyEvaluator[] evals = new ICopyEvaluator[args.length];
-                evals[0] = args[0].createEvaluator(argOut);
-                evals[1] = args[1].createEvaluator(argOut);
+                final IPointable argPtr = new VoidPointable();
+                final IScalarEvaluator[] evals = new IScalarEvaluator[args.length];
+                evals[0] = args[0].createScalarEvaluator(ctx);
+                evals[1] = args[1].createScalarEvaluator(ctx);
 
-                return new ICopyEvaluator() {
+                return new IScalarEvaluator() {
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-                        try {
-                            // evaluator the failure condition
-                            argOut.reset();
-                            evals[1].evaluate(tuple);
-                            ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER
-                                    .deserialize(argOut.getByteArray()[0]);
-                            if (typeTag == ATypeTag.BOOLEAN) {
-                                boolean argResult = ABooleanSerializerDeserializer.getBoolean(argOut.getByteArray(), 1);
-                                if (argResult)
-                                    throw new AlgebricksException(AsterixBuiltinFunctions.INJECT_FAILURE
-                                            + ": injecting a intended failure");
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                        evals[1].evaluate(tuple, argPtr);
+                        ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER
+                                .deserialize(argPtr.getByteArray()[argPtr.getStartOffset()]);
+                        if (typeTag == ATypeTag.BOOLEAN) {
+                            boolean argResult = ABooleanSerializerDeserializer.getBoolean(argPtr.getByteArray(),
+                                    argPtr.getStartOffset() + 1);
+                            if (argResult) {
+                                throw new AlgebricksException(
+                                        AsterixBuiltinFunctions.INJECT_FAILURE + ": injecting a intended failure");
                             }
-
-                            // evaluate the real evaluator
-                            argOut.reset();
-                            evals[0].evaluate(tuple);
-                            output.getDataOutput().write(argOut.getByteArray(), argOut.getStartOffset(),
-                                    argOut.getLength());
-                        } catch (IOException e) {
-                            throw new AlgebricksException(e);
                         }
+
+                        // evaluate the real evaluator
+                        evals[0].evaluate(tuple, argPtr);
+                        result.set(argPtr.getByteArray(), argPtr.getStartOffset(), argPtr.getLength());
                     }
 
                 };

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsNullDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsNullDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsNullDescriptor.java
index 17065e8..a528dae 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsNullDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsNullDescriptor.java
@@ -29,10 +29,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;
 
@@ -46,29 +48,32 @@ public class IsNullDescriptor extends AbstractScalarFunctionDynamicDescriptor {
     };
 
     @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() {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+                return new IScalarEvaluator() {
 
-                    private DataOutput out = output.getDataOutput();
-                    private ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
-                    private ICopyEvaluator eval = args[0].createEvaluator(argOut);
+                    private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+                    private DataOutput out = resultStorage.getDataOutput();
+                    private IPointable argPtr = new VoidPointable();
+                    private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
                     private final AObjectSerializerDeserializer aObjSerDer = AObjectSerializerDeserializer.INSTANCE;
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-                        argOut.reset();
-                        eval.evaluate(tuple);
-                        boolean isNull = argOut.getByteArray()[argOut
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                        eval.evaluate(tuple, argPtr);
+                        boolean isNull = argPtr.getByteArray()[argPtr
                                 .getStartOffset()] == ATypeTag.SERIALIZED_NULL_TYPE_TAG;
                         ABoolean res = isNull ? ABoolean.TRUE : ABoolean.FALSE;
                         try {
+                            resultStorage.reset();
                             aObjSerDer.serialize(res, out);
+                            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/IsSystemNullDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsSystemNullDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsSystemNullDescriptor.java
index 40fac14..7ff2c5f 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsSystemNullDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/IsSystemNullDescriptor.java
@@ -29,18 +29,18 @@ 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;
 
 public class IsSystemNullDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-
-    private final static byte SER_SYSTEM_NULL_TYPE_TAG = ATypeTag.SYSTEM_NULL.serialize();
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         @Override
         public IFunctionDescriptor createFunctionDescriptor() {
@@ -49,26 +49,27 @@ public class IsSystemNullDescriptor extends AbstractScalarFunctionDynamicDescrip
     };
 
     @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() {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+                return new IScalarEvaluator() {
 
-                    private DataOutput out = output.getDataOutput();
-                    private ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
-                    private ICopyEvaluator eval = args[0].createEvaluator(argOut);
+                    private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+                    private DataOutput out = resultStorage.getDataOutput();
+                    private IPointable argPtr = new VoidPointable();
+                    private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
                     private final AObjectSerializerDeserializer aObjSerDer = AObjectSerializerDeserializer.INSTANCE;
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-                        argOut.reset();
-                        eval.evaluate(tuple);
-                        boolean isSystemNull = argOut.getByteArray()[argOut
-                                .getStartOffset()] == SER_SYSTEM_NULL_TYPE_TAG;
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                        eval.evaluate(tuple, argPtr);
+                        boolean isSystemNull = argPtr.getByteArray()[argPtr
+                                .getStartOffset()] == ATypeTag.SERIALIZED_SYSTEM_NULL_TYPE_TAG;
                         ABoolean res = isSystemNull ? ABoolean.TRUE : ABoolean.FALSE;
                         try {
                             aObjSerDer.serialize(res, out);

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/LenDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/LenDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/LenDescriptor.java
index bfe6a5c..d42d96f 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/LenDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/LenDescriptor.java
@@ -36,11 +36,13 @@ import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.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;
 
@@ -54,19 +56,21 @@ public class LenDescriptor 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 {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
 
-                return new ICopyEvaluator() {
+                return new IScalarEvaluator() {
 
-                    private final DataOutput out = output.getDataOutput();
-                    private final ArrayBackedValueStorage inputVal = new ArrayBackedValueStorage();
-                    private final ICopyEvaluator evalList = args[0].createEvaluator(inputVal);
+                    private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+                    private final DataOutput out = resultStorage.getDataOutput();
+                    private final IPointable inputVal = new VoidPointable();
+                    private final IScalarEvaluator evalList = args[0].createScalarEvaluator(ctx);
 
                     // result
                     private final AMutableInt64 res = new AMutableInt64(0);
@@ -78,33 +82,35 @@ public class LenDescriptor extends AbstractScalarFunctionDynamicDescriptor {
                             .getSerializerDeserializer(BuiltinType.ANULL);
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-                        inputVal.reset();
-                        evalList.evaluate(tuple);
-
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                        resultStorage.reset();
+                        evalList.evaluate(tuple, inputVal);
                         byte[] serList = inputVal.getByteArray();
+                        int offset = inputVal.getStartOffset();
 
-                        if (serList[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
+                        if (serList[offset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
                             try {
                                 nullSerde.serialize(ANull.NULL, out);
                             } catch (HyracksDataException e) {
                                 throw new AlgebricksException(e);
                             }
+                            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.LEN.getName()
                                     + ": expects input type ORDEREDLIST/UNORDEREDLIST but got "
-                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serList[0]));
+                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serList[offset]));
                         }
 
                         int numberOfitems = 0;
-                        if (serList[0] == ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG)
-                            numberOfitems = AOrderedListSerializerDeserializer.getNumberOfItems(serList);
-                        else
-                            numberOfitems = AUnorderedListSerializerDeserializer.getNumberOfItems(serList);
+                        if (serList[offset] == ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG) {
+                            numberOfitems = AOrderedListSerializerDeserializer.getNumberOfItems(serList, offset);
+                        } else {
+                            numberOfitems = AUnorderedListSerializerDeserializer.getNumberOfItems(serList, offset);
+                        }
 
                         res.setValue(numberOfitems);
                         try {
@@ -112,6 +118,7 @@ public class LenDescriptor extends AbstractScalarFunctionDynamicDescriptor {
                         } catch (IOException e) {
                             throw new AlgebricksException(e);
                         }
+                        result.set(resultStorage);
                     }
                 };
             }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NotDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NotDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NotDescriptor.java
index 1f97509..f05c2ed 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NotDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NotDescriptor.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.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;
 
@@ -55,18 +57,20 @@ public class NotDescriptor extends AbstractScalarFunctionDynamicDescriptor {
     }
 
     @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 {
-                final DataOutput out = output.getDataOutput();
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
 
-                return new ICopyEvaluator() {
+                return new IScalarEvaluator() {
 
-                    private ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
-                    private ICopyEvaluator eval = args[0].createEvaluator(argOut);
+                    private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+                    private DataOutput out = resultStorage.getDataOutput();
+                    private IPointable argPtr = new VoidPointable();
+                    private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
 
                     private String errorMessage = AsterixBuiltinFunctions.NOT.getName()
                             + ": expects input type BOOLEAN/NULL";
@@ -78,21 +82,27 @@ public class NotDescriptor extends AbstractScalarFunctionDynamicDescriptor {
                             .getSerializerDeserializer(BuiltinType.ANULL);
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-                        argOut.reset();
-                        eval.evaluate(tuple);
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                        resultStorage.reset();
+                        eval.evaluate(tuple, argPtr);
+
+                        byte[] bytes = argPtr.getByteArray();
+                        int offset = argPtr.getStartOffset();
+
                         try {
-                            if (argOut.getByteArray()[0] == ATypeTag.SERIALIZED_BOOLEAN_TYPE_TAG) {
-                                boolean argRes = ABooleanSerializerDeserializer.getBoolean(argOut.getByteArray(), 1);
+                            if (bytes[offset] == ATypeTag.SERIALIZED_BOOLEAN_TYPE_TAG) {
+                                boolean argRes = ABooleanSerializerDeserializer.getBoolean(bytes, offset + 1);
                                 ABoolean aResult = argRes ? (ABoolean.FALSE) : (ABoolean.TRUE);
                                 booleanSerde.serialize(aResult, out);
-                            } else if (argOut.getByteArray()[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG)
+                            } else if (bytes[offset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
                                 nullSerde.serialize(ANull.NULL, out);
-                            else
+                            } else {
                                 throw new AlgebricksException(errorMessage);
+                            }
                         } catch (HyracksDataException hde) {
                             throw new AlgebricksException(hde);
                         }
+                        result.set(resultStorage);
                     }
                 };
             }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NotNullDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NotNullDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NotNullDescriptor.java
index b0e3640..090a56b 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NotNullDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NotNullDescriptor.java
@@ -19,9 +19,6 @@
 
 package org.apache.asterix.runtime.evaluators.functions;
 
-import java.io.DataOutput;
-import java.io.IOException;
-
 import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
@@ -29,10 +26,11 @@ 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.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;
 
 /**
@@ -51,33 +49,28 @@ public class NotNullDescriptor extends AbstractScalarFunctionDynamicDescriptor {
     };
 
     @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(final IHyracksTaskContext ctx) throws AlgebricksException {
+                return new IScalarEvaluator() {
+                    private IPointable inputArg = new VoidPointable();
+                    private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
                     private String errorMessage = AsterixBuiltinFunctions.NOT_NULL
                             + ": the input value cannot be NULL.";
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                        eval.evaluate(tuple, inputArg);
+                        byte[] data = inputArg.getByteArray();
+                        int offset = inputArg.getStartOffset();
 
-                        try {
-                            outInput.reset();
-                            eval.evaluate(tuple);
-                            byte[] data = outInput.getByteArray();
-                            if (data[outInput.getStartOffset()] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
-                                throw new AlgebricksException(errorMessage);
-                            }
-                            out.write(data, outInput.getStartOffset(), outInput.getLength());
-                        } catch (IOException e1) {
+                        if (data[offset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
                             throw new AlgebricksException(errorMessage);
                         }
+                        result.set(inputArg);
                     }
                 };
             }


Mime
View raw message