asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From buyin...@apache.org
Subject [06/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:35 GMT
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringDescriptor.java
index 07b3b64..660fbb8 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringDescriptor.java
@@ -28,15 +28,17 @@ 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.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.DoublePointable;
 import org.apache.hyracks.data.std.primitive.FloatPointable;
 import org.apache.hyracks.data.std.primitive.IntegerPointable;
 import org.apache.hyracks.data.std.primitive.LongPointable;
 import org.apache.hyracks.data.std.primitive.ShortPointable;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
+import org.apache.hyracks.data.std.primitive.VoidPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.data.std.util.GrowableArray;
 import org.apache.hyracks.data.std.util.UTF8StringBuilder;
@@ -54,100 +56,105 @@ public class SubstringDescriptor 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 final DataOutput out = output.getDataOutput();
-                    private final ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
-                    private final ICopyEvaluator evalString = args[0].createEvaluator(argOut);
-                    private final ICopyEvaluator evalStart = args[1].createEvaluator(argOut);
-                    private final ICopyEvaluator evalLen = args[2].createEvaluator(argOut);
+                    private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+                    private final DataOutput out = resultStorage.getDataOutput();
+                    private final IPointable argPtr = new VoidPointable();
+                    private final IScalarEvaluator evalString = args[0].createScalarEvaluator(ctx);
+                    private final IScalarEvaluator evalStart = args[1].createScalarEvaluator(ctx);
+                    private final IScalarEvaluator evalLen = args[2].createScalarEvaluator(ctx);
 
                     private final GrowableArray array = new GrowableArray();
                     private final UTF8StringBuilder builder = new UTF8StringBuilder();
                     private final UTF8StringPointable string = new UTF8StringPointable();
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-                        argOut.reset();
-                        evalStart.evaluate(tuple);
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                        resultStorage.reset();
+                        evalStart.evaluate(tuple, argPtr);
+                        byte[] bytes = argPtr.getByteArray();
+                        int offset = argPtr.getStartOffset();
                         int start = 0;
 
-                        ATypeTag argOutTypeTag = ATypeTag.VALUE_TYPE_MAPPING[argOut.getByteArray()[0]];
+                        ATypeTag argPtrTypeTag = ATypeTag.VALUE_TYPE_MAPPING[bytes[offset]];
 
-                        switch (argOutTypeTag) {
+                        switch (argPtrTypeTag) {
                             case INT64:
-                                start = (int) LongPointable.getLong(argOut.getByteArray(), 1) - 1;
+                                start = (int) LongPointable.getLong(bytes, offset + 1) - 1;
                                 break;
                             case INT32:
-                                start = IntegerPointable.getInteger(argOut.getByteArray(), 1) - 1;
+                                start = IntegerPointable.getInteger(bytes, offset + 1) - 1;
                                 break;
                             case INT8:
-                                start = argOut.getByteArray()[1] - 1;
+                                start = bytes[offset + 1] - 1;
                                 break;
                             case INT16:
-                                start = ShortPointable.getShort(argOut.getByteArray(), 1) - 1;
+                                start = ShortPointable.getShort(bytes, offset + 1) - 1;
                                 break;
                             case FLOAT:
-                                start = (int) FloatPointable.getFloat(argOut.getByteArray(), 1) - 1;
+                                start = (int) FloatPointable.getFloat(bytes, offset + 1) - 1;
                                 break;
                             case DOUBLE:
-                                start = (int) DoublePointable.getDouble(argOut.getByteArray(), 1) - 1;
+                                start = (int) DoublePointable.getDouble(bytes, offset + 1) - 1;
                                 break;
                             default:
                                 throw new AlgebricksException(AsterixBuiltinFunctions.SUBSTRING.getName()
                                         + ": expects type INT8/16/32/64/FLOAT/DOUBLE for the second argument but got "
-                                        + argOutTypeTag);
+                                        + argPtrTypeTag);
                         }
 
-                        argOut.reset();
-                        evalLen.evaluate(tuple);
+                        evalLen.evaluate(tuple, argPtr);
+                        bytes = argPtr.getByteArray();
+                        offset = argPtr.getStartOffset();
                         int len = 0;
 
-                        argOutTypeTag = ATypeTag.VALUE_TYPE_MAPPING[argOut.getByteArray()[0]];
+                        argPtrTypeTag = ATypeTag.VALUE_TYPE_MAPPING[bytes[offset]];
 
-                        switch (argOutTypeTag) {
+                        switch (argPtrTypeTag) {
                             case INT64:
-                                len = (int) LongPointable.getLong(argOut.getByteArray(), 1);
+                                len = (int) LongPointable.getLong(bytes, offset + 1);
                                 break;
                             case INT32:
-                                len = IntegerPointable.getInteger(argOut.getByteArray(), 1);
+                                len = IntegerPointable.getInteger(bytes, offset + 1);
                                 break;
                             case INT8:
-                                len = argOut.getByteArray()[1];
+                                len = bytes[offset + 1];
                                 break;
                             case INT16:
-                                len = ShortPointable.getShort(argOut.getByteArray(), 1);
+                                len = ShortPointable.getShort(bytes, offset + 1);
                                 break;
                             case FLOAT:
-                                len = (int) FloatPointable.getFloat(argOut.getByteArray(), 1);
+                                len = (int) FloatPointable.getFloat(bytes, offset + 1);
                                 break;
                             case DOUBLE:
-                                len = (int) DoublePointable.getDouble(argOut.getByteArray(), 1);
+                                len = (int) DoublePointable.getDouble(bytes, offset + 1);
                                 break;
                             default:
                                 throw new AlgebricksException(AsterixBuiltinFunctions.SUBSTRING.getName()
                                         + ": expects type INT8/16/32/64/FLOAT/DOUBLE for the third argument but got "
-                                        + argOutTypeTag);
+                                        + argPtrTypeTag);
                         }
 
-                        argOut.reset();
-                        evalString.evaluate(tuple);
+                        evalString.evaluate(tuple, argPtr);
+                        bytes = argPtr.getByteArray();
+                        offset = argPtr.getStartOffset();
+                        int length = argPtr.getLength();
+                        argPtrTypeTag = ATypeTag.VALUE_TYPE_MAPPING[bytes[offset]];
 
-                        byte[] bytes = argOut.getByteArray();
-                        argOutTypeTag = ATypeTag.VALUE_TYPE_MAPPING[bytes[0]];
-
-                        if (argOutTypeTag != ATypeTag.STRING) {
+                        if (argPtrTypeTag != ATypeTag.STRING) {
                             throw new AlgebricksException(AsterixBuiltinFunctions.SUBSTRING.getName()
-                                    + ": expects type STRING for the first argument but got " + argOutTypeTag);
+                                    + ": expects type STRING for the first argument but got " + argPtrTypeTag);
                         }
 
-                        string.set(bytes, 1, bytes.length);
+                        string.set(bytes, offset + 1, length - 1);
                         array.reset();
                         try {
                             UTF8StringPointable.substr(string, start, len, builder, array);
@@ -164,6 +171,7 @@ public class SubstringDescriptor 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/SwitchCaseDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SwitchCaseDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SwitchCaseDescriptor.java
index 1fb3108..df0b973 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SwitchCaseDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SwitchCaseDescriptor.java
@@ -18,25 +18,24 @@
  */
 package org.apache.asterix.runtime.evaluators.functions;
 
-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;
 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.exceptions.HyracksDataException;
-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 SwitchCaseDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        @Override
         public IFunctionDescriptor createFunctionDescriptor() {
             return new SwitchCaseDescriptor();
         }
@@ -48,65 +47,55 @@ public class SwitchCaseDescriptor extends AbstractScalarFunctionDynamicDescripto
     }
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
+            throws AlgebricksException {
 
-        return new ICopyEvaluatorFactory() {
+        return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
-                final ArrayBackedValueStorage condOut = new ArrayBackedValueStorage();
-                final ArrayBackedValueStorage caseOut = new ArrayBackedValueStorage();
-                final ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+                final IPointable condPtr = new VoidPointable();
+                final IPointable casePtr = new VoidPointable();
+                final IPointable argPtr = new VoidPointable();
 
-                final ICopyEvaluator[] evals = new ICopyEvaluator[args.length];
+                final IScalarEvaluator[] evals = new IScalarEvaluator[args.length];
                 // condition
-                evals[0] = args[0].createEvaluator(condOut);
+                evals[0] = args[0].createScalarEvaluator(ctx);
                 // case value
                 for (int i = 1; i < evals.length - 1; i += 2) {
-                    evals[i] = args[i].createEvaluator(caseOut);
+                    evals[i] = args[i].createScalarEvaluator(ctx);
                 }
                 // case expression
                 for (int i = 2; i < evals.length - 1; i += 2) {
-                    evals[i] = args[i].createEvaluator(argOut);
+                    evals[i] = args[i].createScalarEvaluator(ctx);
                 }
                 // default expression
-                evals[evals.length - 1] = args[evals.length - 1].createEvaluator(argOut);
+                evals[evals.length - 1] = args[evals.length - 1].createScalarEvaluator(ctx);
 
-                return new ICopyEvaluator() {
+                return new IScalarEvaluator() {
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-                        try {
-                            int n = args.length;
-                            condOut.reset();
-                            evals[0].evaluate(tuple);
-                            for (int i = 1; i < n; i += 2) {
-                                caseOut.reset();
-                                evals[i].evaluate(tuple);
-                                if (equals(condOut, caseOut)) {
-                                    argOut.reset();
-                                    evals[i + 1].evaluate(tuple);
-                                    output.getDataOutput().write(argOut.getByteArray(), argOut.getStartOffset(),
-                                            argOut.getLength());
-                                    return;
-                                }
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                        int n = args.length;
+                        evals[0].evaluate(tuple, condPtr);
+                        for (int i = 1; i < n; i += 2) {
+                            evals[i].evaluate(tuple, casePtr);
+                            if (equals(condPtr, casePtr)) {
+                                evals[i + 1].evaluate(tuple, argPtr);
+                                result.set(argPtr);
+                                return;
                             }
-                            // the default case
-                            argOut.reset();
-                            evals[n - 1].evaluate(tuple);
-                            output.getDataOutput().write(argOut.getByteArray(), argOut.getStartOffset(),
-                                    argOut.getLength());
-                        } catch (HyracksDataException hde) {
-                            throw new AlgebricksException(hde);
-                        } catch (IOException ioe) {
-                            throw new AlgebricksException(ioe);
                         }
+                        // the default case
+                        evals[n - 1].evaluate(tuple, argPtr);
+                        result.set(argPtr);
                     }
 
-                    private boolean equals(ArrayBackedValueStorage out1, ArrayBackedValueStorage out2) {
-                        if (out1.getStartOffset() != out2.getStartOffset() || out1.getLength() != out2.getLength())
+                    private boolean equals(IPointable out1, IPointable out2) {
+                        if (out1.getStartOffset() != out2.getStartOffset() || out1.getLength() != out2.getLength()) {
                             return false;
+                        }
                         byte[] data1 = out1.getByteArray();
                         byte[] data2 = out2.getByteArray();
                         for (int i = out1.getStartOffset(); i < out1.getLength(); i++) {

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/UnorderedListConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/UnorderedListConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/UnorderedListConstructorDescriptor.java
index 14e28e8..ce08ba8 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/UnorderedListConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/UnorderedListConstructorDescriptor.java
@@ -30,9 +30,11 @@ import org.apache.asterix.om.types.AUnorderedListType;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.data.std.api.IPointable;
+import org.apache.hyracks.data.std.primitive.VoidPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -40,6 +42,7 @@ public class UnorderedListConstructorDescriptor extends AbstractScalarFunctionDy
 
     private static final long serialVersionUID = 1L;
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        @Override
         public IFunctionDescriptor createFunctionDescriptor() {
             return new UnorderedListConstructorDescriptor();
         }
@@ -57,43 +60,44 @@ public class UnorderedListConstructorDescriptor extends AbstractScalarFunctionDy
     }
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new UnorderedListConstructorEvaluatorFactory(args, ultype);
     }
 
-    private static class UnorderedListConstructorEvaluatorFactory implements ICopyEvaluatorFactory {
+    private static class UnorderedListConstructorEvaluatorFactory implements IScalarEvaluatorFactory {
 
         private static final long serialVersionUID = 1L;
-        private ICopyEvaluatorFactory[] args;
+        private IScalarEvaluatorFactory[] args;
 
         private boolean selfDescList = false;
         private boolean homoList = false;
         private AUnorderedListType unorderedlistType;
 
-        public UnorderedListConstructorEvaluatorFactory(ICopyEvaluatorFactory[] args, AUnorderedListType type) {
+        public UnorderedListConstructorEvaluatorFactory(IScalarEvaluatorFactory[] args, AUnorderedListType type) {
             this.args = args;
             this.unorderedlistType = type;
-            if (type == null || type.getItemType() == null || type.getItemType().getTypeTag() == ATypeTag.ANY)
+            if (type == null || type.getItemType() == null || type.getItemType().getTypeTag() == ATypeTag.ANY) {
                 this.selfDescList = true;
-            else
+            } else {
                 this.homoList = true;
+            }
         }
 
         @Override
-        public ICopyEvaluator createEvaluator(IDataOutputProvider output) throws AlgebricksException {
-            final DataOutput out = output.getDataOutput();
-            final ArrayBackedValueStorage inputVal = new ArrayBackedValueStorage();
-            final ICopyEvaluator[] argEvals = new ICopyEvaluator[args.length];
+        public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
+            final IPointable inputVal = new VoidPointable();
+            final IScalarEvaluator[] argEvals = new IScalarEvaluator[args.length];
             for (int i = 0; i < args.length; i++) {
-                argEvals[i] = args[i].createEvaluator(inputVal);
+                argEvals[i] = args[i].createScalarEvaluator(ctx);
             }
 
-            return new ICopyEvaluator() {
-
+            return new IScalarEvaluator() {
+                private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+                private DataOutput out = resultStorage.getDataOutput();
                 private UnorderedListBuilder builder = new UnorderedListBuilder();
 
                 @Override
-                public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
                     try {
                         builder.reset(unorderedlistType);
                         if (selfDescList) {
@@ -102,7 +106,9 @@ public class UnorderedListConstructorDescriptor extends AbstractScalarFunctionDy
                         if (homoList) {
                             this.writeTypedItems(tuple);
                         }
+                        resultStorage.reset();
                         builder.write(out, true);
+                        result.set(resultStorage);
                     } catch (IOException ioe) {
                         throw new AlgebricksException(ioe);
                     }
@@ -112,8 +118,7 @@ public class UnorderedListConstructorDescriptor extends AbstractScalarFunctionDy
 
                     try {
                         for (int i = 0; i < argEvals.length; i++) {
-                            inputVal.reset();
-                            argEvals[i].evaluate(tuple);
+                            argEvals[i].evaluate(tuple, inputVal);
                             builder.addItem(inputVal);
                         }
                     } catch (IOException ioe) {
@@ -125,8 +130,7 @@ public class UnorderedListConstructorDescriptor extends AbstractScalarFunctionDy
 
                     try {
                         for (int i = 0; i < argEvals.length; i++) {
-                            inputVal.reset();
-                            argEvals[i].evaluate(tuple);
+                            argEvals[i].evaluate(tuple, inputVal);
                             builder.addItem(inputVal);
                         }
                     } catch (IOException ioe) {

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/WordTokensDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/WordTokensDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/WordTokensDescriptor.java
index baad139..7c1117f 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/WordTokensDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/WordTokensDescriptor.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.IBinaryTokenizer;
 import org.apache.hyracks.storage.am.lsm.invertedindex.tokenizers.ITokenFactory;
@@ -38,6 +38,7 @@ public class WordTokensDescriptor extends AbstractScalarFunctionDynamicDescripto
 
     private static final long serialVersionUID = 1L;
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        @Override
         public IFunctionDescriptor createFunctionDescriptor() {
             return new WordTokensDescriptor();
         }
@@ -49,15 +50,16 @@ public class WordTokensDescriptor 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 UTF8WordTokenFactory();
                 IBinaryTokenizer tokenizer = new DelimitedUTF8StringBinaryTokenizer(true, true, tokenFactory);
-                return new WordTokensEvaluator(args, output, tokenizer, BuiltinType.ASTRING);
+                return new WordTokensEvaluator(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/binary/AbstractBinaryScalarEvaluator.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/AbstractBinaryScalarEvaluator.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/AbstractBinaryScalarEvaluator.java
new file mode 100644
index 0000000..e87c4eb
--- /dev/null
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/AbstractBinaryScalarEvaluator.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.asterix.runtime.evaluators.functions.binary;
+
+import java.io.DataOutput;
+
+import org.apache.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import org.apache.asterix.om.base.ANull;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.hierachy.ATypeHierarchy;
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.data.std.api.IPointable;
+import org.apache.hyracks.data.std.primitive.VoidPointable;
+import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
+import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+public abstract class AbstractBinaryScalarEvaluator implements IScalarEvaluator {
+    @SuppressWarnings("unchecked")
+    protected ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
+            .getSerializerDeserializer(BuiltinType.ANULL);
+
+    protected ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
+    protected DataOutput dataOutput = resultStorage.getDataOutput();
+    protected IPointable[] pointables;
+    protected IScalarEvaluator[] evaluators;
+
+    public AbstractBinaryScalarEvaluator(final IHyracksTaskContext context, final IScalarEvaluatorFactory[] evaluatorFactories)
+            throws AlgebricksException {
+        pointables = new IPointable[evaluatorFactories.length];
+        evaluators = new IScalarEvaluator[evaluatorFactories.length];
+        for (int i = 0; i < evaluators.length; ++i) {
+            pointables[i] = new VoidPointable();
+            evaluators[i] = evaluatorFactories[i].createScalarEvaluator(context);
+        }
+    }
+
+    public ATypeTag evaluateTuple(IFrameTupleReference tuple, int id) throws AlgebricksException {
+        evaluators[id].evaluate(tuple, pointables[id]);
+        return ATypeTag.VALUE_TYPE_MAPPING[pointables[id].getByteArray()[pointables[id].getStartOffset()]];
+    }
+
+    public boolean serializeNullIfAnyNull(ATypeTag... tags) throws HyracksDataException {
+        for (ATypeTag typeTag : tags) {
+            if (typeTag == ATypeTag.NULL) {
+                nullSerde.serialize(ANull.NULL, dataOutput);
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private static final String FIRST = "1st";
+    private static final String SECOND = "2nd";
+    private static final String THIRD = "3rd";
+    private static final String TH = "th";
+
+    public static String rankToString(int i) {
+        String prefix = "";
+        if (i >= 10) {
+            prefix = String.valueOf(i / 10);
+        }
+        switch (i % 10) {
+            case 1:
+                return prefix + FIRST;
+            case 2:
+                return prefix + SECOND;
+            case 3:
+                return prefix + THIRD;
+            default:
+                return String.valueOf(i) + TH;
+        }
+    }
+
+    public static void checkTypeMachingThrowsIfNot(String title, ATypeTag[] expected, ATypeTag... actual)
+            throws AlgebricksException {
+        for (int i = 0; i < expected.length; i++) {
+            if (expected[i] != actual[i]) {
+                if (!ATypeHierarchy.canPromote(actual[i], expected[i])
+                        && !ATypeHierarchy.canPromote(expected[i], actual[i])) {
+                    throw new AlgebricksException(title + ": expects " + expected[i] + " at " + rankToString(i + 1)
+                            + " argument, but got " + actual[i]);
+                }
+            }
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/AbstractCopyEvaluator.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/AbstractCopyEvaluator.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/AbstractCopyEvaluator.java
deleted file mode 100644
index 6de63a2..0000000
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/AbstractCopyEvaluator.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.asterix.runtime.evaluators.functions.binary;
-
-import org.apache.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import org.apache.asterix.om.base.ANull;
-import org.apache.asterix.om.types.ATypeTag;
-import org.apache.asterix.om.types.BuiltinType;
-import org.apache.asterix.om.types.hierachy.ATypeHierarchy;
-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.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.util.ArrayBackedValueStorage;
-import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
-
-import java.io.DataOutput;
-
-public abstract class AbstractCopyEvaluator implements ICopyEvaluator {
-    @SuppressWarnings("unchecked")
-    protected ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
-            .getSerializerDeserializer(BuiltinType.ANULL);
-
-    protected DataOutput dataOutput;
-    protected ArrayBackedValueStorage[] storages;
-    protected ICopyEvaluator[] evaluators;
-
-    public AbstractCopyEvaluator(final IDataOutputProvider output, final ICopyEvaluatorFactory[] copyEvaluatorFactories)
-            throws AlgebricksException {
-        dataOutput = output.getDataOutput();
-        storages = new ArrayBackedValueStorage[copyEvaluatorFactories.length];
-        evaluators = new ICopyEvaluator[copyEvaluatorFactories.length];
-        for (int i = 0; i < evaluators.length; ++i) {
-            storages[i] = new ArrayBackedValueStorage();
-            evaluators[i] = copyEvaluatorFactories[i].createEvaluator(storages[i]);
-        }
-    }
-
-    public ATypeTag evaluateTuple(IFrameTupleReference tuple, int id) throws AlgebricksException {
-        storages[id].reset();
-        evaluators[id].evaluate(tuple);
-        return ATypeTag.VALUE_TYPE_MAPPING[storages[id].getByteArray()[0]];
-    }
-
-    public boolean serializeNullIfAnyNull(ATypeTag... tags) throws HyracksDataException {
-        for (ATypeTag typeTag : tags) {
-            if (typeTag == ATypeTag.NULL) {
-                nullSerde.serialize(ANull.NULL, dataOutput);
-                return true;
-            }
-        }
-        return false;
-    }
-
-    private static final String FIRST = "1st";
-    private static final String SECOND = "2nd";
-    private static final String THIRD = "3rd";
-    private static final String TH = "th";
-
-    public static String rankToString(int i) {
-        String prefix = "";
-        if (i >= 10) {
-            prefix = String.valueOf(i / 10);
-        }
-        switch (i % 10) {
-            case 1:
-                return prefix + FIRST;
-            case 2:
-                return prefix + SECOND;
-            case 3:
-                return prefix + THIRD;
-            default:
-                return String.valueOf(i) + TH;
-        }
-    }
-
-    public static void checkTypeMachingThrowsIfNot(String title, ATypeTag[] expected, ATypeTag... actual)
-            throws AlgebricksException {
-        for (int i = 0; i < expected.length; i++) {
-            if (expected[i] != actual[i]) {
-                if (!ATypeHierarchy.canPromote(actual[i], expected[i])
-                        && !ATypeHierarchy.canPromote(expected[i], actual[i])) {
-                    throw new AlgebricksException(title + ": expects " + expected[i] + " at " + rankToString(i + 1)
-                            + " argument, but got " + actual[i]);
-                }
-            }
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/BinaryConcatDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/BinaryConcatDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/BinaryConcatDescriptor.java
index 1e676c9..2747260 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/BinaryConcatDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/BinaryConcatDescriptor.java
@@ -30,10 +30,11 @@ import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicD
 import org.apache.asterix.runtime.evaluators.common.AsterixListAccessor;
 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.ByteArrayPointable;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 import org.apache.hyracks.util.encoding.VarLenIntEncoderDecoder;
@@ -54,51 +55,53 @@ public class BinaryConcatDescriptor 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 AbstractCopyEvaluator(output, args) {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+                return new AbstractBinaryScalarEvaluator(ctx, args) {
 
                     private final AsterixListAccessor listAccessor = new AsterixListAccessor();
-                    private final byte SER_BINARY_TYPE = ATypeTag.BINARY.serialize();
                     private final byte[] metaBuffer = new byte[5];
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                        resultStorage.reset();
                         ATypeTag typeTag = evaluateTuple(tuple, 0);
                         if (typeTag != ATypeTag.UNORDEREDLIST && typeTag != ATypeTag.ORDEREDLIST) {
                             throw new AlgebricksException(getIdentifier().getName()
                                     + ": expects input type ORDEREDLIST/UNORDEREDLIST, but got " + typeTag);
                         }
                         try {
-                            listAccessor.reset(storages[0].getByteArray(), 0);
+                            byte[] data = pointables[0].getByteArray();
+                            int offset = pointables[0].getStartOffset();
 
+                            listAccessor.reset(data, offset);
                             int concatLength = 0;
                             for (int i = 0; i < listAccessor.size(); i++) {
                                 int itemOffset = listAccessor.getItemOffset(i);
                                 ATypeTag itemType = listAccessor.getItemType(itemOffset);
                                 if (itemType != ATypeTag.BINARY) {
                                     if (serializeNullIfAnyNull(itemType)) {
+                                        result.set(resultStorage);
                                         return;
                                     }
                                     throw new AlgebricksException(getIdentifier().getName()
                                             + ": expects type STRING/NULL for the list item but got " + itemType);
                                 }
-                                concatLength += ByteArrayPointable.getContentLength(storages[0].getByteArray(),
-                                        itemOffset);
+                                concatLength += ByteArrayPointable.getContentLength(data, itemOffset);
                             }
-                            dataOutput.writeByte(SER_BINARY_TYPE);
+                            dataOutput.writeByte(ATypeTag.SERIALIZED_BINARY_TYPE_TAG);
                             int metaLen = VarLenIntEncoderDecoder.encode(concatLength, metaBuffer, 0);
                             dataOutput.write(metaBuffer, 0, metaLen);
 
                             for (int i = 0; i < listAccessor.size(); i++) {
                                 int itemOffset = listAccessor.getItemOffset(i);
-                                int length = ByteArrayPointable.getContentLength(storages[0].getByteArray(),
-                                        itemOffset);
-                                dataOutput.write(storages[0].getByteArray(),
+                                int length = ByteArrayPointable.getContentLength(data, itemOffset);
+                                dataOutput.write(data,
                                         itemOffset + ByteArrayPointable.getNumberBytesToStoreMeta(length), length);
                             }
                         } catch (HyracksDataException e) {
@@ -108,7 +111,7 @@ public class BinaryConcatDescriptor extends AbstractScalarFunctionDynamicDescrip
                         } catch (AsterixException 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/binary/BinaryLengthDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/BinaryLengthDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/BinaryLengthDescriptor.java
index fc6329d..9e9aab4 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/BinaryLengthDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/BinaryLengthDescriptor.java
@@ -30,11 +30,12 @@ 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.ByteArrayPointable;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -50,13 +51,14 @@ public class BinaryLengthDescriptor extends AbstractScalarFunctionDynamicDescrip
     private static final ATypeTag[] EXPECTED_TAGS = { ATypeTag.BINARY };
 
     @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 AbstractCopyEvaluator(output, args) {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+                return new AbstractBinaryScalarEvaluator(ctx, args) {
 
                     private AMutableInt64 result = new AMutableInt64(0);
                     @SuppressWarnings("unchecked")
@@ -64,20 +66,24 @@ public class BinaryLengthDescriptor extends AbstractScalarFunctionDynamicDescrip
                             .getSerializerDeserializer(BuiltinType.AINT64);
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                    public void evaluate(IFrameTupleReference tuple, IPointable resultPointable)
+                            throws AlgebricksException {
+                        resultStorage.reset();
                         ATypeTag tag = evaluateTuple(tuple, 0);
                         try {
                             if (serializeNullIfAnyNull(tag)) {
+                                resultPointable.set(resultStorage);
                                 return;
                             }
                             checkTypeMachingThrowsIfNot(getIdentifier().getName(), EXPECTED_TAGS, tag);
-                            int len = ByteArrayPointable.getContentLength(storages[0].getByteArray(), 1);
+                            int len = ByteArrayPointable.getContentLength(pointables[0].getByteArray(),
+                                    pointables[0].getStartOffset() + 1);
                             result.setValue(len);
                             intSerde.serialize(result, dataOutput);
                         } catch (HyracksDataException e) {
                             throw new AlgebricksException(e);
                         }
-
+                        resultPointable.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/binary/FindBinaryDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/FindBinaryDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/FindBinaryDescriptor.java
index 4a30847..c7b4843 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/FindBinaryDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/FindBinaryDescriptor.java
@@ -30,11 +30,12 @@ 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.ByteArrayPointable;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
@@ -55,13 +56,14 @@ public class FindBinaryDescriptor extends AbstractScalarFunctionDynamicDescripto
     private static final ATypeTag[] EXPECTED_INPUT_TAG = { ATypeTag.BINARY, ATypeTag.BINARY };
 
     @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 AbstractFindBinaryCopyEvaluator(output, args, getIdentifier().getName()) {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+                return new AbstractFindBinaryCopyEvaluator(ctx, args, getIdentifier().getName()) {
                     @Override
                     protected int getFromOffset(IFrameTupleReference tuple) throws AlgebricksException {
                         return 0;
@@ -71,11 +73,11 @@ public class FindBinaryDescriptor extends AbstractScalarFunctionDynamicDescripto
         };
     }
 
-    static abstract class AbstractFindBinaryCopyEvaluator extends AbstractCopyEvaluator {
+    static abstract class AbstractFindBinaryCopyEvaluator extends AbstractBinaryScalarEvaluator {
 
-        public AbstractFindBinaryCopyEvaluator(IDataOutputProvider output,
-                ICopyEvaluatorFactory[] copyEvaluatorFactories, String functionName) throws AlgebricksException {
-            super(output, copyEvaluatorFactories);
+        public AbstractFindBinaryCopyEvaluator(IHyracksTaskContext context,
+                IScalarEvaluatorFactory[] copyEvaluatorFactories, String functionName) throws AlgebricksException {
+            super(context, copyEvaluatorFactories);
             this.functionName = functionName;
         }
 
@@ -89,19 +91,23 @@ public class FindBinaryDescriptor extends AbstractScalarFunctionDynamicDescripto
                 .getSerializerDeserializer(BuiltinType.AINT64);
 
         @Override
-        public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+        public void evaluate(IFrameTupleReference tuple, IPointable resultPointable) throws AlgebricksException {
+            resultStorage.reset();
             ATypeTag textTag = evaluateTuple(tuple, 0);
             ATypeTag wordTag = evaluateTuple(tuple, 1);
             int fromOffset = getFromOffset(tuple);
 
             try {
                 if (serializeNullIfAnyNull(textTag, wordTag)) {
+                    resultPointable.set(resultStorage);
                     return;
                 }
                 checkTypeMachingThrowsIfNot(functionName, EXPECTED_INPUT_TAG, textTag, wordTag);
 
-                textPtr.set(storages[0].getByteArray(), 1, storages[0].getLength() - 1);
-                wordPtr.set(storages[1].getByteArray(), 1, storages[1].getLength() - 1);
+                textPtr.set(pointables[0].getByteArray(), pointables[0].getStartOffset() + 1,
+                        pointables[0].getLength() - 1);
+                wordPtr.set(pointables[1].getByteArray(), pointables[0].getStartOffset() + 1,
+                        pointables[1].getLength() - 1);
                 result.setValue(1 + indexOf(textPtr.getByteArray(), textPtr.getContentStartOffset(),
                         textPtr.getContentLength(), wordPtr.getByteArray(), wordPtr.getContentStartOffset(),
                         wordPtr.getContentLength(), fromOffset));
@@ -109,6 +115,7 @@ public class FindBinaryDescriptor extends AbstractScalarFunctionDynamicDescripto
             } catch (HyracksDataException e) {
                 throw new AlgebricksException(e);
             }
+            resultPointable.set(resultStorage);
         }
 
         protected abstract int getFromOffset(IFrameTupleReference tuple) throws AlgebricksException;
@@ -133,14 +140,18 @@ public class FindBinaryDescriptor extends AbstractScalarFunctionDynamicDescripto
         for (int i = sourceOffset + fromIndex; i <= max; i++) {
             /* Look for first character. */
             if (source[i] != first) {
-                while (++i <= max && source[i] != first);
+                while (++i <= max && source[i] != first) {
+                    ;
+                }
             }
 
             /* Found first character, now look at the rest of v2 */
             if (i <= max) {
                 int j = i + 1;
                 int end = j + targetCount - 1;
-                for (int k = targetOffset + 1; j < end && source[j] == target[k]; j++, k++);
+                for (int k = targetOffset + 1; j < end && source[j] == target[k]; j++, k++) {
+                    ;
+                }
 
                 if (j == end) {
                     /* Found whole string. */

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/FindBinaryFromDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/FindBinaryFromDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/FindBinaryFromDescriptor.java
index 12f4486..6b8ee38 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/FindBinaryFromDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/FindBinaryFromDescriptor.java
@@ -26,10 +26,10 @@ import org.apache.asterix.om.types.hierachy.ATypeHierarchy;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
 import org.apache.hyracks.api.exceptions.HyracksDataException;
-import org.apache.hyracks.data.std.api.IDataOutputProvider;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
 public class FindBinaryFromDescriptor extends AbstractScalarFunctionDynamicDescriptor {
@@ -48,24 +48,25 @@ public class FindBinaryFromDescriptor extends AbstractScalarFunctionDynamicDescr
     }
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
-        return new ICopyEvaluatorFactory() {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
+            throws AlgebricksException {
+        return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
-                return new FindBinaryDescriptor.AbstractFindBinaryCopyEvaluator(output, args,
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+                return new FindBinaryDescriptor.AbstractFindBinaryCopyEvaluator(ctx, args,
                         getIdentifier().getName()) {
                     @Override
                     protected int getFromOffset(IFrameTupleReference tuple) throws AlgebricksException {
                         evaluateTuple(tuple, 2);
                         int getFrom = 0;
                         try {
-                            getFrom = ATypeHierarchy.getIntegerValue(storages[2].getByteArray(), 0);
+                            getFrom = ATypeHierarchy.getIntegerValue(pointables[2].getByteArray(),
+                                    pointables[2].getStartOffset());
                         } catch (HyracksDataException e) {
                             throw new AlgebricksException(e);
                         }
-
                         return getFrom;
                     }
                 };

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/ParseBinaryDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/ParseBinaryDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/ParseBinaryDescriptor.java
index 8adb21c..a067557 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/ParseBinaryDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/ParseBinaryDescriptor.java
@@ -30,11 +30,12 @@ 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.UTF8StringPointable;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 import org.apache.hyracks.util.bytes.Base64Parser;
@@ -60,13 +61,14 @@ public class ParseBinaryDescriptor extends AbstractScalarFunctionDynamicDescript
     }
 
     @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 AbstractCopyEvaluator(output, args) {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+                return new AbstractBinaryScalarEvaluator(ctx, args) {
 
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ABinary> binarySerde = AqlSerializerDeserializerProvider.INSTANCE
@@ -80,18 +82,22 @@ public class ParseBinaryDescriptor extends AbstractScalarFunctionDynamicDescript
                     private final Base64Parser base64Parser = new Base64Parser();
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                        resultStorage.reset();
                         ATypeTag binaryTag = evaluateTuple(tuple, 0);
                         ATypeTag formatTag = evaluateTuple(tuple, 1);
 
                         try {
                             if (serializeNullIfAnyNull(binaryTag, formatTag)) {
+                                result.set(resultStorage);
                                 return;
                             }
                             checkTypeMachingThrowsIfNot(getIdentifier().getName(), EXPECTED_INPUT_TAGS, binaryTag,
                                     formatTag);
-                            stringPointable.set(storages[0].getByteArray(), 1, storages[0].getLength());
-                            formatPointable.set(storages[1].getByteArray(), 1, storages[1].getLength());
+                            stringPointable.set(pointables[0].getByteArray(), pointables[0].getStartOffset() + 1,
+                                    pointables[0].getLength());
+                            formatPointable.set(pointables[1].getByteArray(), pointables[1].getStartOffset() + 1,
+                                    pointables[1].getLength());
                             if (HEX_FORMAT.ignoreCaseCompareTo(formatPointable) == 0) {
                                 hexParser.generateByteArrayFromHexString(stringPointable.getByteArray(),
                                         stringPointable.getCharStartOffset(), stringPointable.getUTF8Length());
@@ -110,6 +116,7 @@ public class ParseBinaryDescriptor extends AbstractScalarFunctionDynamicDescript
                         } catch (HyracksDataException e) {
                             e.printStackTrace();
                         }
+                        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/binary/PrintBinaryDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/PrintBinaryDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/PrintBinaryDescriptor.java
index 37b414b..92b9ec1 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/PrintBinaryDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/PrintBinaryDescriptor.java
@@ -31,10 +31,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.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.ByteArrayPointable;
 import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
@@ -60,13 +61,14 @@ public class PrintBinaryDescriptor extends AbstractScalarFunctionDynamicDescript
     public final static ATypeTag[] EXPECTED_INPUT_TAGS = { ATypeTag.BINARY, ATypeTag.STRING };
 
     @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 AbstractCopyEvaluator(output, args) {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+                return new AbstractBinaryScalarEvaluator(ctx, args) {
 
                     private StringBuilder stringBuilder = new StringBuilder();
                     private final ByteArrayPointable byteArrayPtr = new ByteArrayPointable();
@@ -74,19 +76,23 @@ public class PrintBinaryDescriptor extends AbstractScalarFunctionDynamicDescript
                     private final UTF8StringWriter writer = new UTF8StringWriter();
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                        resultStorage.reset();
                         ATypeTag arg0Tag = evaluateTuple(tuple, 0);
                         ATypeTag arg1Tag = evaluateTuple(tuple, 1);
 
                         try {
                             if (serializeNullIfAnyNull(arg0Tag, arg1Tag)) {
+                                result.set(resultStorage);
                                 return;
                             }
                             checkTypeMachingThrowsIfNot(getIdentifier().getName(), EXPECTED_INPUT_TAGS, arg0Tag,
                                     arg1Tag);
 
-                            byteArrayPtr.set(storages[0].getByteArray(), 1, storages[0].getLength());
-                            formatPointable.set(storages[1].getByteArray(), 1, storages[1].getLength());
+                            byteArrayPtr.set(pointables[0].getByteArray(), pointables[0].getStartOffset() + 1,
+                                    pointables[0].getLength());
+                            formatPointable.set(pointables[1].getByteArray(), pointables[1].getStartOffset() + 1,
+                                    pointables[1].getLength());
 
                             int lengthBinary = byteArrayPtr.getContentLength();
                             stringBuilder.setLength(0);
@@ -107,6 +113,7 @@ public class PrintBinaryDescriptor extends AbstractScalarFunctionDynamicDescript
                         } 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/binary/SubBinaryFromDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/SubBinaryFromDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/SubBinaryFromDescriptor.java
index b99a15b..4d435ab 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/SubBinaryFromDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/SubBinaryFromDescriptor.java
@@ -25,9 +25,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.accessors.IFrameTupleReference;
 
 public class SubBinaryFromDescriptor extends AbstractScalarFunctionDynamicDescriptor {
@@ -45,13 +45,14 @@ public class SubBinaryFromDescriptor extends AbstractScalarFunctionDynamicDescri
     }
 
     @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 SubBinaryFromToDescriptor.AbstractSubBinaryCopyEvaluator(output, args,
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+                return new SubBinaryFromToDescriptor.AbstractSubBinaryCopyEvaluator(ctx, args,
                         getIdentifier().getName()) {
                     @Override
                     protected int getSubLength(IFrameTupleReference tuple) throws AlgebricksException {

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/SubBinaryFromToDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/SubBinaryFromToDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/SubBinaryFromToDescriptor.java
index 34e527e..20fdeed 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/SubBinaryFromToDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/SubBinaryFromToDescriptor.java
@@ -29,10 +29,11 @@ import org.apache.asterix.om.types.hierachy.ATypeHierarchy;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
 import org.apache.hyracks.api.exceptions.HyracksDataException;
-import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.data.std.api.IPointable;
 import org.apache.hyracks.data.std.primitive.ByteArrayPointable;
 import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 import org.apache.hyracks.util.encoding.VarLenIntEncoderDecoder;
@@ -52,19 +53,21 @@ public class SubBinaryFromToDescriptor extends AbstractScalarFunctionDynamicDesc
     }
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
-        return new ICopyEvaluatorFactory() {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
+            throws AlgebricksException {
+        return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
-                return new AbstractSubBinaryCopyEvaluator(output, args, getIdentifier().getName()) {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+                return new AbstractSubBinaryCopyEvaluator(ctx, args, getIdentifier().getName()) {
                     @Override
                     protected int getSubLength(IFrameTupleReference tuple) throws AlgebricksException {
                         evaluateTuple(tuple, 2);
                         int subLength = 0;
                         try {
-                            subLength = ATypeHierarchy.getIntegerValue(storages[2].getByteArray(), 0);
+                            subLength = ATypeHierarchy.getIntegerValue(pointables[2].getByteArray(),
+                                    pointables[2].getStartOffset());
                         } catch (HyracksDataException e) {
                             throw new AlgebricksException(e);
                         }
@@ -76,10 +79,10 @@ public class SubBinaryFromToDescriptor extends AbstractScalarFunctionDynamicDesc
         };
     }
 
-    static abstract class AbstractSubBinaryCopyEvaluator extends AbstractCopyEvaluator {
-        public AbstractSubBinaryCopyEvaluator(IDataOutputProvider output,
-                ICopyEvaluatorFactory[] copyEvaluatorFactories, String functionName) throws AlgebricksException {
-            super(output, copyEvaluatorFactories);
+    static abstract class AbstractSubBinaryCopyEvaluator extends AbstractBinaryScalarEvaluator {
+        public AbstractSubBinaryCopyEvaluator(IHyracksTaskContext context,
+                IScalarEvaluatorFactory[] copyEvaluatorFactories, String functionName) throws AlgebricksException {
+            super(context, copyEvaluatorFactories);
             this.functionName = functionName;
         }
 
@@ -90,24 +93,27 @@ public class SubBinaryFromToDescriptor extends AbstractScalarFunctionDynamicDesc
         static final ATypeTag[] EXPECTED_INPUT_TAGS = { ATypeTag.BINARY, ATypeTag.INT32 };
 
         @Override
-        public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-
+        public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+            resultStorage.reset();
             ATypeTag argTag0 = evaluateTuple(tuple, 0);
             ATypeTag argTag1 = evaluateTuple(tuple, 1);
 
             try {
                 if (serializeNullIfAnyNull(argTag0, argTag1)) {
+                    result.set(resultStorage);
                     return;
                 }
                 checkTypeMachingThrowsIfNot(functionName, EXPECTED_INPUT_TAGS, argTag0, argTag1);
 
-                byteArrayPointable.set(storages[0].getByteArray(), 1, storages[0].getLength() - 1);
-                byte[] startBytes = storages[1].getByteArray();
+                byteArrayPointable.set(pointables[0].getByteArray(), pointables[0].getStartOffset() + 1,
+                        pointables[0].getLength() - 1);
+                byte[] startBytes = pointables[1].getByteArray();
+                int offset = pointables[1].getStartOffset();
 
                 int subStart = 0;
 
                 // strange SQL index convention
-                subStart = ATypeHierarchy.getIntegerValue(startBytes, 0) - 1;
+                subStart = ATypeHierarchy.getIntegerValue(startBytes, offset) - 1;
 
                 int totalLength = byteArrayPointable.getContentLength();
                 int subLength = getSubLength(tuple);
@@ -133,6 +139,7 @@ public class SubBinaryFromToDescriptor extends AbstractScalarFunctionDynamicDesc
             } catch (IOException e) {
                 throw new AlgebricksException(e);
             }
+            result.set(resultStorage);
         }
 
         protected abstract int getSubLength(IFrameTupleReference tuple) throws AlgebricksException;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0ae30836/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/FieldAccessByIndexDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/FieldAccessByIndexDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/FieldAccessByIndexDescriptor.java
index 03e4490..212d6d3 100644
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/FieldAccessByIndexDescriptor.java
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/FieldAccessByIndexDescriptor.java
@@ -24,7 +24,7 @@ import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
 import org.apache.asterix.om.types.ARecordType;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 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 FieldAccessByIndexDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
@@ -47,7 +47,7 @@ public class FieldAccessByIndexDescriptor extends AbstractScalarFunctionDynamicD
     }
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(ICopyEvaluatorFactory[] args) {
+    public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) {
         return new FieldAccessByIndexEvalFactory(args[0], args[1], recType);
     }
 


Mime
View raw message