asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From buyin...@apache.org
Subject [08/22] incubator-asterixdb git commit: ASTERIXDB-1228: Add MISSING into the data model.
Date Tue, 24 May 2016 01:31:26 GMT
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/535d86b5/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NotNullDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NotNullDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NotNullDescriptor.java
deleted file mode 100644
index 45fc04c..0000000
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NotNullDescriptor.java
+++ /dev/null
@@ -1,85 +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;
-
-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.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.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;
-
-/**
- * This runtime function checks if the input is null.
- * If the input is not null, just return it directly;
- * Otherwise, throw a runtime exception.
- */
-public class NotNullDescriptor extends AbstractScalarFunctionDynamicDescriptor {
-
-    private static final long serialVersionUID = 1L;
-    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
-        @Override
-        public IFunctionDescriptor createFunctionDescriptor() {
-            return new NotNullDescriptor();
-        }
-    };
-
-    @Override
-    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
-        return new IScalarEvaluatorFactory() {
-            private static final long serialVersionUID = 1L;
-
-            @Override
-            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, IPointable result) throws AlgebricksException {
-                        eval.evaluate(tuple, inputArg);
-                        byte[] data = inputArg.getByteArray();
-                        int offset = inputArg.getStartOffset();
-
-                        if (data[offset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
-                            throw new AlgebricksException(errorMessage);
-                        }
-                        result.set(inputArg);
-                    }
-                };
-            }
-        };
-    }
-
-    @Override
-    public FunctionIdentifier getIdentifier() {
-        return AsterixBuiltinFunctions.NOT_NULL;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/535d86b5/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericAbsDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericAbsDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericAbsDescriptor.java
index 47c78d6..373547e 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericAbsDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericAbsDescriptor.java
@@ -38,7 +38,6 @@ import org.apache.asterix.om.base.AMutableInt16;
 import org.apache.asterix.om.base.AMutableInt32;
 import org.apache.asterix.om.base.AMutableInt64;
 import org.apache.asterix.om.base.AMutableInt8;
-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;
@@ -105,11 +104,7 @@ public class NumericAbsDescriptor extends AbstractScalarFunctionDynamicDescripto
                         int offset = argPtr.getStartOffset();
 
                         try {
-                            if (data[offset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
-                                serde = AqlSerializerDeserializerProvider.INSTANCE
-                                        .getSerializerDeserializer(BuiltinType.ANULL);
-                                serde.serialize(ANull.NULL, out);
-                            } else if (data[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) {
+                            if (data[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) {
                                 serde = AqlSerializerDeserializerProvider.INSTANCE
                                         .getSerializerDeserializer(BuiltinType.AINT8);
                                 byte val = AInt8SerializerDeserializer.getByte(data, offset + 1);

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/535d86b5/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericFloorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericFloorDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericFloorDescriptor.java
index 0c6aae9..336bf15 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericFloorDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericFloorDescriptor.java
@@ -38,7 +38,6 @@ import org.apache.asterix.om.base.AMutableInt16;
 import org.apache.asterix.om.base.AMutableInt32;
 import org.apache.asterix.om.base.AMutableInt64;
 import org.apache.asterix.om.base.AMutableInt8;
-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;
@@ -105,11 +104,7 @@ public class NumericFloorDescriptor extends AbstractScalarFunctionDynamicDescrip
                         int offset = argPtr.getStartOffset();
 
                         try {
-                            if (data[offset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
-                                serde = AqlSerializerDeserializerProvider.INSTANCE
-                                        .getSerializerDeserializer(BuiltinType.ANULL);
-                                serde.serialize(ANull.NULL, out);
-                            } else if (data[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) {
+                            if (data[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) {
                                 serde = AqlSerializerDeserializerProvider.INSTANCE
                                         .getSerializerDeserializer(BuiltinType.AINT8);
                                 byte val = AInt8SerializerDeserializer.getByte(data, offset + 1);

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/535d86b5/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericModuloDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericModuloDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericModuloDescriptor.java
index 1bc936c..d40cb70 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericModuloDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericModuloDescriptor.java
@@ -33,7 +33,6 @@ import org.apache.asterix.om.base.AMutableInt16;
 import org.apache.asterix.om.base.AMutableInt32;
 import org.apache.asterix.om.base.AMutableInt64;
 import org.apache.asterix.om.base.AMutableInt8;
-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;
@@ -84,8 +83,8 @@ public class NumericModuloDescriptor extends AbstractScalarFunctionDynamicDescri
                 return new IScalarEvaluator() {
                     private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
                     private DataOutput out = resultStorage.getDataOutput();
-                    // one temp. buffer re-used by both children
-                    private IPointable argPtr = new VoidPointable();
+                    private IPointable leftPtr = new VoidPointable();
+                    private IPointable rightPtr = new VoidPointable();
                     private IScalarEvaluator evalLeft = args[0].createScalarEvaluator(ctx);
                     private IScalarEvaluator evalRight = args[1].createScalarEvaluator(ctx);
                     private double[] operands = new double[args.length];
@@ -107,12 +106,10 @@ public class NumericModuloDescriptor extends AbstractScalarFunctionDynamicDescri
 
                         try {
                             resultStorage.reset();
+                            evalLeft.evaluate(tuple, leftPtr);
+                            evalRight.evaluate(tuple, rightPtr);
                             for (int i = 0; i < args.length; i++) {
-                                if (i == 0) {
-                                    evalLeft.evaluate(tuple, argPtr);
-                                } else {
-                                    evalRight.evaluate(tuple, argPtr);
-                                }
+                                IPointable argPtr = i == 0 ? leftPtr : rightPtr;
                                 byte[] data = argPtr.getByteArray();
                                 int offset = argPtr.getStartOffset();
                                 typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(data[offset]);
@@ -147,13 +144,6 @@ public class NumericModuloDescriptor extends AbstractScalarFunctionDynamicDescri
                                         operands[i] = ADoubleSerializerDeserializer.getDouble(data, offset + 1);
                                         break;
                                     }
-                                    case NULL: {
-                                        serde = AqlSerializerDeserializerProvider.INSTANCE
-                                                .getSerializerDeserializer(BuiltinType.ANULL);
-                                        serde.serialize(ANull.NULL, out);
-                                        result.set(resultStorage);
-                                        return;
-                                    }
                                     default: {
                                         throw new NotImplementedException(AsterixBuiltinFunctions.NUMERIC_MOD.getName()
                                                 + (i == 0 ? ": left" : ": right") + " operand can not be "

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/535d86b5/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundDescriptor.java
index b05ff65..773ba27 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundDescriptor.java
@@ -38,7 +38,6 @@ import org.apache.asterix.om.base.AMutableInt16;
 import org.apache.asterix.om.base.AMutableInt32;
 import org.apache.asterix.om.base.AMutableInt64;
 import org.apache.asterix.om.base.AMutableInt8;
-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;
@@ -105,11 +104,7 @@ public class NumericRoundDescriptor extends AbstractScalarFunctionDynamicDescrip
                         int offset = argPtr.getStartOffset();
 
                         try {
-                            if (data[offset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
-                                serde = AqlSerializerDeserializerProvider.INSTANCE
-                                        .getSerializerDeserializer(BuiltinType.ANULL);
-                                serde.serialize(ANull.NULL, out);
-                            } else if (data[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) {
+                            if (data[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) {
                                 serde = AqlSerializerDeserializerProvider.INSTANCE
                                         .getSerializerDeserializer(BuiltinType.AINT8);
                                 byte val = AInt8SerializerDeserializer.getByte(data, offset + 1);

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/535d86b5/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundHalfToEven2Descriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundHalfToEven2Descriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundHalfToEven2Descriptor.java
index a1acb14..d39478d 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundHalfToEven2Descriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundHalfToEven2Descriptor.java
@@ -39,7 +39,6 @@ import org.apache.asterix.om.base.AMutableInt16;
 import org.apache.asterix.om.base.AMutableInt32;
 import org.apache.asterix.om.base.AMutableInt64;
 import org.apache.asterix.om.base.AMutableInt8;
-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;
@@ -87,7 +86,8 @@ public class NumericRoundHalfToEven2Descriptor extends AbstractScalarFunctionDyn
 
                     private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
                     private DataOutput out = resultStorage.getDataOutput();
-                    private IPointable argPtr = new VoidPointable();
+                    private IPointable argValue = new VoidPointable();
+                    private IPointable argPrecision = new VoidPointable();
                     private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
                     private IScalarEvaluator precision = args[1].createScalarEvaluator(ctx);
                     private AMutableDouble aDouble = new AMutableDouble(0);
@@ -99,11 +99,9 @@ public class NumericRoundHalfToEven2Descriptor extends AbstractScalarFunctionDyn
                     @SuppressWarnings("rawtypes")
                     private ISerializerDeserializer serde;
 
-                    private int getPrecision(IFrameTupleReference tuple) throws AlgebricksException {
-                        resultStorage.reset();
-                        precision.evaluate(tuple, argPtr);
-                        byte[] bytes = argPtr.getByteArray();
-                        int offset = argPtr.getStartOffset();
+                    private int getPrecision() throws AlgebricksException {
+                        byte[] bytes = argPrecision.getByteArray();
+                        int offset = argPrecision.getStartOffset();
 
                         if (bytes[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) {
                             return AInt8SerializerDeserializer.getByte(bytes, offset + 1);
@@ -123,16 +121,13 @@ public class NumericRoundHalfToEven2Descriptor extends AbstractScalarFunctionDyn
                     @Override
                     public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
                         resultStorage.reset();
-                        eval.evaluate(tuple, argPtr);
-                        byte[] data = argPtr.getByteArray();
-                        int offset = argPtr.getStartOffset();
+                        eval.evaluate(tuple, argValue);
+                        precision.evaluate(tuple, argPrecision);
+                        byte[] data = argValue.getByteArray();
+                        int offset = argValue.getStartOffset();
 
                         try {
-                            if (data[offset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
-                                serde = AqlSerializerDeserializerProvider.INSTANCE
-                                        .getSerializerDeserializer(BuiltinType.ANULL);
-                                serde.serialize(ANull.NULL, out);
-                            } else if (data[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) {
+                            if (data[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) {
                                 serde = AqlSerializerDeserializerProvider.INSTANCE
                                         .getSerializerDeserializer(BuiltinType.AINT8);
                                 byte val = AInt8SerializerDeserializer.getByte(data, offset + 1);
@@ -166,7 +161,7 @@ public class NumericRoundHalfToEven2Descriptor extends AbstractScalarFunctionDyn
                                 } else {
                                     BigDecimal r = new BigDecimal(Float.toString(val));
                                     aFloat.setValue(
-                                            r.setScale(getPrecision(tuple), BigDecimal.ROUND_HALF_EVEN).floatValue());
+                                            r.setScale(getPrecision(), BigDecimal.ROUND_HALF_EVEN).floatValue());
                                     serde.serialize(aFloat, out);
                                 }
                             } else if (data[offset] == ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) {
@@ -179,7 +174,7 @@ public class NumericRoundHalfToEven2Descriptor extends AbstractScalarFunctionDyn
                                 } else {
                                     BigDecimal r = new BigDecimal(Double.toString(val));
                                     aDouble.setValue(
-                                            r.setScale(getPrecision(tuple), BigDecimal.ROUND_HALF_EVEN).doubleValue());
+                                            r.setScale(getPrecision(), BigDecimal.ROUND_HALF_EVEN).doubleValue());
                                     serde.serialize(aDouble, out);
                                 }
                             } else {

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/535d86b5/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundHalfToEvenDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundHalfToEvenDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundHalfToEvenDescriptor.java
index 0d18b24..575035e 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundHalfToEvenDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericRoundHalfToEvenDescriptor.java
@@ -38,7 +38,6 @@ import org.apache.asterix.om.base.AMutableInt16;
 import org.apache.asterix.om.base.AMutableInt32;
 import org.apache.asterix.om.base.AMutableInt64;
 import org.apache.asterix.om.base.AMutableInt8;
-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;
@@ -105,13 +104,7 @@ public class NumericRoundHalfToEvenDescriptor extends AbstractScalarFunctionDyna
                         int offset = argPtr.getStartOffset();
 
                         try {
-                            if (data[offset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
-                                serde = AqlSerializerDeserializerProvider.INSTANCE
-                                        .getSerializerDeserializer(BuiltinType.ANULL);
-                                serde.serialize(ANull.NULL, out);
-                                result.set(resultStorage);
-                                return;
-                            } else if (data[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) {
+                            if (data[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) {
                                 serde = AqlSerializerDeserializerProvider.INSTANCE
                                         .getSerializerDeserializer(BuiltinType.AINT8);
                                 byte val = AInt8SerializerDeserializer.getByte(data, offset + 1);

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/535d86b5/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericSubtractDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericSubtractDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericSubtractDescriptor.java
index b850f91..4355be0 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericSubtractDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericSubtractDescriptor.java
@@ -33,7 +33,6 @@ import org.apache.asterix.om.base.AMutableInt16;
 import org.apache.asterix.om.base.AMutableInt32;
 import org.apache.asterix.om.base.AMutableInt64;
 import org.apache.asterix.om.base.AMutableInt8;
-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;
@@ -143,13 +142,6 @@ public class NumericSubtractDescriptor extends AbstractScalarFunctionDynamicDesc
                                         operands[i] = ADoubleSerializerDeserializer.getDouble(data, offset + 1);
                                         break;
                                     }
-                                    case NULL: {
-                                        serde = AqlSerializerDeserializerProvider.INSTANCE
-                                                .getSerializerDeserializer(BuiltinType.ANULL);
-                                        serde.serialize(ANull.NULL, out);
-                                        result.set(resultStorage);
-                                        return;
-                                    }
                                     default: {
                                         throw new NotImplementedException(AsterixBuiltinFunctions.NUMERIC_SUBTRACT
                                                 .getName() + (i == 0 ? ": left" : ": right") + " operand can not be "

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/535d86b5/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericUnaryMinusDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericUnaryMinusDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericUnaryMinusDescriptor.java
index 50e657d..422ab49 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericUnaryMinusDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericUnaryMinusDescriptor.java
@@ -33,7 +33,6 @@ import org.apache.asterix.om.base.AMutableInt16;
 import org.apache.asterix.om.base.AMutableInt32;
 import org.apache.asterix.om.base.AMutableInt64;
 import org.apache.asterix.om.base.AMutableInt8;
-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;
@@ -96,11 +95,7 @@ public class NumericUnaryMinusDescriptor extends AbstractScalarFunctionDynamicDe
                         int offset = argPtr.getStartOffset();
 
                         try {
-                            if (data[offset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
-                                serde = AqlSerializerDeserializerProvider.INSTANCE
-                                        .getSerializerDeserializer(BuiltinType.ANULL);
-                                serde.serialize(ANull.NULL, out);
-                            } else if (data[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) {
+                            if (data[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) {
                                 serde = AqlSerializerDeserializerProvider.INSTANCE
                                         .getSerializerDeserializer(BuiltinType.AINT8);
                                 aInt8.setValue((byte) -AInt8SerializerDeserializer.getByte(data, offset + 1));

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/535d86b5/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/OrDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/OrDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/OrDescriptor.java
index cbf4dcc..a98f4bb 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/OrDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/OrDescriptor.java
@@ -23,6 +23,7 @@ import java.io.DataOutput;
 import org.apache.asterix.dataflow.data.nontagged.serde.ABooleanSerializerDeserializer;
 import org.apache.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import org.apache.asterix.om.base.ABoolean;
+import org.apache.asterix.om.base.AMissing;
 import org.apache.asterix.om.base.ANull;
 import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
@@ -80,6 +81,9 @@ public class OrDescriptor extends AbstractScalarFunctionDynamicDescriptor {
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
+                    @SuppressWarnings("unchecked")
+                    private ISerializerDeserializer<AMissing> missingSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.AMISSING);
 
                     @Override
                     public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
@@ -88,29 +92,37 @@ public class OrDescriptor extends AbstractScalarFunctionDynamicDescriptor {
                             int n = args.length;
                             boolean res = false;
                             boolean metNull = false;
+                            boolean metMissing = false;
                             for (int i = 0; i < n; i++) {
                                 evals[i].evaluate(tuple, argPtr);
                                 byte[] data = argPtr.getByteArray();
                                 int offset = argPtr.getStartOffset();
+                                if (data[offset] == ATypeTag.SERIALIZED_MISSING_TYPE_TAG) {
+                                    metMissing = true;
+                                    continue;
+                                }
                                 if (data[offset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
                                     metNull = true;
                                     continue;
                                 }
                                 boolean argResult = ABooleanSerializerDeserializer.getBoolean(data, offset + 1);
                                 if (argResult == true) {
-                                    res = true;
-                                    break;
+                                    // anything OR TRUE = TRUE
+                                    booleanSerde.serialize(ABoolean.TRUE, output);
+                                    result.set(resultStorage);
+                                    return;
                                 }
+                                res |= argResult;
                             }
                             if (metNull) {
-                                if (!res) {
-                                    ABoolean aResult = ABoolean.FALSE;
-                                    booleanSerde.serialize(aResult, output);
-                                } else {
-                                    nullSerde.serialize(ANull.NULL, output);
-                                }
+                                // NULL OR FALSE = NULL
+                                // NULL OR MISSING = NULL
+                                nullSerde.serialize(ANull.NULL, output);
+                            } else if (metMissing) {
+                                // MISSING OR FALSE = MISSING
+                                missingSerde.serialize(AMissing.MISSING, output);
                             } else {
-                                ABoolean aResult = res ? (ABoolean.TRUE) : (ABoolean.FALSE);
+                                ABoolean aResult = res ? ABoolean.TRUE : ABoolean.FALSE;
                                 booleanSerde.serialize(aResult, output);
                             }
                             result.set(resultStorage);

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/535d86b5/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/PrefixLenJaccardDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/PrefixLenJaccardDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/PrefixLenJaccardDescriptor.java
index 9a7017a..c9e5807 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/PrefixLenJaccardDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/PrefixLenJaccardDescriptor.java
@@ -70,7 +70,8 @@ public class PrefixLenJaccardDescriptor extends AbstractScalarFunctionDynamicDes
 
                     private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
                     private final DataOutput out = resultStorage.getDataOutput();
-                    private final IPointable inputVal = new VoidPointable();
+                    private final IPointable lenPtr = new VoidPointable();
+                    private final IPointable thresholdPtr = new VoidPointable();
                     private final IScalarEvaluator evalLen = args[0].createScalarEvaluator(ctx);
                     private final IScalarEvaluator evalThreshold = args[1].createScalarEvaluator(ctx);
 
@@ -86,19 +87,20 @@ public class PrefixLenJaccardDescriptor extends AbstractScalarFunctionDynamicDes
                     @Override
                     public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
                         resultStorage.reset();
+                        evalLen.evaluate(tuple, lenPtr);
+                        evalThreshold.evaluate(tuple, thresholdPtr);
+
                         // length
-                        evalLen.evaluate(tuple, inputVal);
                         int length = 0;
                         try {
-                            length = ATypeHierarchy.getIntegerValue(inputVal.getByteArray(), inputVal.getStartOffset());
+                            length = ATypeHierarchy.getIntegerValue(lenPtr.getByteArray(), lenPtr.getStartOffset());
                         } catch (HyracksDataException e1) {
                             throw new AlgebricksException(e1);
                         }
 
                         // similarity threshold
-                        evalThreshold.evaluate(tuple, inputVal);
-                        byte[] data = inputVal.getByteArray();
-                        int offset = inputVal.getStartOffset();
+                        byte[] data = thresholdPtr.getByteArray();
+                        int offset = thresholdPtr.getStartOffset();
                         if (data[offset] != ATypeTag.SERIALIZED_FLOAT_TYPE_TAG) {
                             throw new AlgebricksException(AsterixBuiltinFunctions.PREFIX_LEN_JACCARD.getName()
                                     + ": expects type FLOAT the first argument but got "

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/535d86b5/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/RegExpDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/RegExpDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/RegExpDescriptor.java
index a0829fd..7b9ca73 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/RegExpDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/RegExpDescriptor.java
@@ -27,7 +27,6 @@ import java.util.regex.Pattern;
 import org.apache.asterix.formats.nontagged.AqlBinaryComparatorFactoryProvider;
 import org.apache.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import org.apache.asterix.om.base.ABoolean;
-import org.apache.asterix.om.base.ANull;
 import org.apache.asterix.om.base.AString;
 import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
@@ -100,9 +99,6 @@ public class RegExpDescriptor extends AbstractScalarFunctionDynamicDescriptor {
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ABoolean> booleanSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ABOOLEAN);
-                    @SuppressWarnings("unchecked")
-                    private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
-                            .getSerializerDeserializer(BuiltinType.ANULL);
                     private Matcher matcher;
                     private Pattern pattern;
 
@@ -112,15 +108,11 @@ public class RegExpDescriptor extends AbstractScalarFunctionDynamicDescriptor {
                         // evaluate the pattern first
                         try {
                             evalPattern.evaluate(tuple, array0);
+                            evalString.evaluate(tuple, array0);
+
                             byte[] patternBytes = array0.getByteArray();
                             int patternOffset = array0.getStartOffset();
                             int patternLen = array0.getLength();
-
-                            if (patternBytes[patternOffset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
-                                nullSerde.serialize(ANull.NULL, dout);
-                                result.set(resultStorage);
-                                return;
-                            }
                             if (patternBytes[patternOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                                 throw new AlgebricksException(AsterixBuiltinFunctions.REG_EXP.getName()
                                         + ": expects type STRING/NULL for the first input argument but got "
@@ -148,15 +140,9 @@ public class RegExpDescriptor extends AbstractScalarFunctionDynamicDescriptor {
                                 pattern = Pattern.compile(strPattern.getStringValue());
 
                             }
-                            evalString.evaluate(tuple, array0);
                             byte[] data = array0.getByteArray();
                             int offset = array0.getStartOffset();
                             int len = array0.getLength();
-                            if (data[offset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
-                                nullSerde.serialize(ANull.NULL, dout);
-                                result.set(resultStorage);
-                                return;
-                            }
                             if (data[offset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                                 throw new AlgebricksException(AsterixBuiltinFunctions.REG_EXP.getName()
                                         + ": expects type STRING/NULL for the second input argument but got "

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/535d86b5/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SpatialAreaDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SpatialAreaDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SpatialAreaDescriptor.java
index 5d8f514..e31ad90 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SpatialAreaDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SpatialAreaDescriptor.java
@@ -26,13 +26,10 @@ import org.apache.asterix.dataflow.data.nontagged.serde.ACircleSerializerDeseria
 import org.apache.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
 import org.apache.asterix.dataflow.data.nontagged.serde.AInt16SerializerDeserializer;
 import org.apache.asterix.dataflow.data.nontagged.serde.ARectangleSerializerDeserializer;
-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.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.asterix.runtime.evaluators.common.SpatialUtils;
@@ -42,7 +39,6 @@ import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 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;
@@ -74,10 +70,6 @@ public class SpatialAreaDescriptor extends AbstractScalarFunctionDynamicDescript
                     private final IPointable argPtr = new VoidPointable();
                     private final IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
 
-                    @SuppressWarnings("unchecked")
-                    private final ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
-                            .getSerializerDeserializer(BuiltinType.ANULL);
-
                     @Override
                     public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
                         resultStorage.reset();
@@ -126,9 +118,6 @@ public class SpatialAreaDescriptor extends AbstractScalarFunctionDynamicDescript
                                     out.writeByte(ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
                                     out.writeDouble(area);
                                     break;
-                                case NULL:
-                                    nullSerde.serialize(ANull.NULL, out);
-                                    break;
                                 default:
                                     throw new NotImplementedException(AsterixBuiltinFunctions.SPATIAL_AREA.getName()
                                             + ": does not support the type: " + tag

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/535d86b5/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SpatialCellDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SpatialCellDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SpatialCellDescriptor.java
index cb6d194..2208d6f 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SpatialCellDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SpatialCellDescriptor.java
@@ -27,7 +27,6 @@ import org.apache.asterix.dataflow.data.nontagged.serde.APointSerializerDeserial
 import org.apache.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import org.apache.asterix.om.base.AMutablePoint;
 import org.apache.asterix.om.base.AMutableRectangle;
-import org.apache.asterix.om.base.ANull;
 import org.apache.asterix.om.base.ARectangle;
 import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
@@ -81,9 +80,6 @@ public class SpatialCellDescriptor extends AbstractScalarFunctionDynamicDescript
                     private final AMutablePoint[] aPoint = { new AMutablePoint(0, 0), new AMutablePoint(0, 0) };
 
                     @SuppressWarnings("unchecked")
-                    private final ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
-                            .getSerializerDeserializer(BuiltinType.ANULL);
-                    @SuppressWarnings("unchecked")
                     private final ISerializerDeserializer<ARectangle> rectangleSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ARECTANGLE);
 
@@ -130,9 +126,6 @@ public class SpatialCellDescriptor extends AbstractScalarFunctionDynamicDescript
                                 aPoint[1].setValue(x + xInc, y + yInc);
                                 aRectangle.setValue(aPoint[0], aPoint[1]);
                                 rectangleSerde.serialize(aRectangle, out);
-                            } else if (tag0 == ATypeTag.NULL || tag1 == ATypeTag.NULL || tag2 == ATypeTag.NULL
-                                    || tag3 == ATypeTag.NULL) {
-                                nullSerde.serialize(ANull.NULL, out);
                             } else {
                                 throw new AlgebricksException(AsterixBuiltinFunctions.SPATIAL_CELL.getName()
                                         + ": expects input type: (POINT, POINT, DOUBLE, DOUBLE) but got ("

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/535d86b5/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SpatialDistanceDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SpatialDistanceDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SpatialDistanceDescriptor.java
index d7f260e..5c969b1 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SpatialDistanceDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SpatialDistanceDescriptor.java
@@ -24,13 +24,10 @@ import java.io.IOException;
 import org.apache.asterix.dataflow.data.nontagged.Coordinate;
 import org.apache.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
 import org.apache.asterix.dataflow.data.nontagged.serde.APointSerializerDeserializer;
-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.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
@@ -39,7 +36,6 @@ import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 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;
@@ -73,10 +69,6 @@ public class SpatialDistanceDescriptor extends AbstractScalarFunctionDynamicDesc
                     private final IScalarEvaluator eval0 = args[0].createScalarEvaluator(ctx);
                     private final IScalarEvaluator eval1 = args[1].createScalarEvaluator(ctx);
 
-                    @SuppressWarnings("unchecked")
-                    private final ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
-                            .getSerializerDeserializer(BuiltinType.ANULL);
-
                     @Override
                     public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
                         resultStorage.reset();
@@ -91,7 +83,7 @@ public class SpatialDistanceDescriptor extends AbstractScalarFunctionDynamicDesc
 
                             ATypeTag tag0 = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes0[offset0]);
                             ATypeTag tag1 = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes1[offset1]);
-                            double distance = 0.0;
+                            double distance;
                             if (tag0 == ATypeTag.POINT) {
                                 if (tag1 == ATypeTag.POINT) {
                                     double x1 = ADoubleSerializerDeserializer.getDouble(bytes0,
@@ -108,8 +100,6 @@ public class SpatialDistanceDescriptor extends AbstractScalarFunctionDynamicDesc
                                             + ": does not support the type: " + tag1
                                             + "; it is only implemented for POINT.");
                                 }
-                            } else if (tag0 == ATypeTag.NULL || tag1 == ATypeTag.NULL) {
-                                nullSerde.serialize(ANull.NULL, out);
                             } else {
                                 throw new NotImplementedException(AsterixBuiltinFunctions.SPATIAL_DISTANCE.getName()
                                         + ": does not support the type: " + tag1

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/535d86b5/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SpatialIntersectDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SpatialIntersectDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SpatialIntersectDescriptor.java
index 626fe80..03ec9a6 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SpatialIntersectDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SpatialIntersectDescriptor.java
@@ -450,7 +450,7 @@ public class SpatialIntersectDescriptor extends AbstractScalarFunctionDynamicDes
 
                     private boolean triangleTriangleIntersection(DoubleArray trianglesX0, DoubleArray trianglesY0,
                             int triangleId0, DoubleArray trianglesX1, DoubleArray trianglesY1, int triangleId1)
-                                    throws HyracksDataException { // separating axis theorem
+                            throws HyracksDataException { // separating axis theorem
 
                         for (int side = 0; side < 3; side++) {
                             spatialUtils.findNormals(trianglesX0, trianglesY0, triangleId0, side);
@@ -830,9 +830,6 @@ public class SpatialIntersectDescriptor extends AbstractScalarFunctionDynamicDes
                                         case RECTANGLE:
                                             res = pointInRectangle(bytes0, offset0, bytes1, offset1);
                                             break;
-                                        case NULL:
-                                            res = false;
-                                            break;
                                         default:
                                             throw new NotImplementedException(AsterixBuiltinFunctions.SPATIAL_INTERSECT
                                                     .getName() + ": does not support the type: " + tag1
@@ -900,9 +897,6 @@ public class SpatialIntersectDescriptor extends AbstractScalarFunctionDynamicDes
                                         case RECTANGLE:
                                             res = lineRectangleIntersection(bytes0, offset0, bytes1, offset1);
                                             break;
-                                        case NULL:
-                                            res = false;
-                                            break;
                                         default:
                                             throw new NotImplementedException(AsterixBuiltinFunctions.SPATIAL_INTERSECT
                                                     .getName() + ": does not support the type: " + tag1
@@ -993,9 +987,6 @@ public class SpatialIntersectDescriptor extends AbstractScalarFunctionDynamicDes
                                         case RECTANGLE:
                                             res = rectanglePolygonIntersection(bytes1, offset1, bytes0, offset0);
                                             break;
-                                        case NULL:
-                                            res = false;
-                                            break;
                                         default:
                                             throw new NotImplementedException(AsterixBuiltinFunctions.SPATIAL_INTERSECT
                                                     .getName() + ": does not support the type: " + tag1
@@ -1019,9 +1010,6 @@ public class SpatialIntersectDescriptor extends AbstractScalarFunctionDynamicDes
                                         case RECTANGLE:
                                             res = rectangleCircleIntersection(bytes1, offset1, bytes0, offset0);
                                             break;
-                                        case NULL:
-                                            res = false;
-                                            break;
                                         default:
                                             throw new NotImplementedException(AsterixBuiltinFunctions.SPATIAL_INTERSECT
                                                     .getName() + ": does not support the type: " + tag1
@@ -1069,18 +1057,12 @@ public class SpatialIntersectDescriptor extends AbstractScalarFunctionDynamicDes
                                                 }
                                             }
                                             break;
-                                        case NULL:
-                                            res = false;
-                                            break;
                                         default:
                                             throw new NotImplementedException(AsterixBuiltinFunctions.SPATIAL_INTERSECT
                                                     .getName() + ": does not support the type: " + tag1
                                                     + "; it is only implemented for POINT, ALINE, POLYGON, and CIRCLE.");
                                     }
                                     break;
-                                case NULL:
-                                    res = false;
-                                    break;
                                 default:
                                     throw new NotImplementedException(AsterixBuiltinFunctions.SPATIAL_INTERSECT
                                             .getName() + ": does not support the type: " + tag1

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/535d86b5/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/Substring2Descriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/Substring2Descriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/Substring2Descriptor.java
index 8abda5f..f0c9fba 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/Substring2Descriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/Substring2Descriptor.java
@@ -63,7 +63,8 @@ public class Substring2Descriptor extends AbstractScalarFunctionDynamicDescripto
 
                     private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
                     private DataOutput out = resultStorage.getDataOutput();
-                    private IPointable argPtr = new VoidPointable();
+                    private IPointable argString = new VoidPointable();
+                    private IPointable argStart = new VoidPointable();
                     private IScalarEvaluator evalString = args[0].createScalarEvaluator(ctx);
                     private IScalarEvaluator evalStart = args[1].createScalarEvaluator(ctx);
                     private final GrowableArray array = new GrowableArray();
@@ -73,22 +74,21 @@ public class Substring2Descriptor extends AbstractScalarFunctionDynamicDescripto
                     @Override
                     public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
                         resultStorage.reset();
-                        evalStart.evaluate(tuple, argPtr);
-                        int start = 0;
-
-                        byte[] bytes = argPtr.getByteArray();
-                        int offset = argPtr.getStartOffset();
+                        evalStart.evaluate(tuple, argStart);
+                        evalString.evaluate(tuple, argString);
 
+                        int start = 0;
+                        byte[] bytes = argStart.getByteArray();
+                        int offset = argStart.getStartOffset();
                         try {
                             start = ATypeHierarchy.getIntegerValue(bytes, offset) - 1;
                         } catch (HyracksDataException e1) {
                             throw new AlgebricksException(e1);
                         }
 
-                        evalString.evaluate(tuple, argPtr);
-                        bytes = argPtr.getByteArray();
-                        offset = argPtr.getStartOffset();
-                        int len = argPtr.getLength();
+                        bytes = argString.getByteArray();
+                        offset = argString.getStartOffset();
+                        int len = argString.getLength();
                         if (bytes[offset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                             throw new AlgebricksException(AsterixBuiltinFunctions.SUBSTRING2.getName()
                                     + ": expects type STRING for the first argument but got "

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/535d86b5/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringAfterDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringAfterDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringAfterDescriptor.java
index 32db2c2..23dbbec 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringAfterDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringAfterDescriptor.java
@@ -81,22 +81,14 @@ public class SubstringAfterDescriptor extends AbstractScalarFunctionDynamicDescr
                         int patternOffset = array1.getStartOffset();
                         int patternLen = array1.getLength();
 
-                        if ((src[srcOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
-                                && src[srcOffset] != ATypeTag.SERIALIZED_NULL_TYPE_TAG)
-                                || (pattern[patternOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
-                                        && pattern[patternOffset] != ATypeTag.SERIALIZED_NULL_TYPE_TAG)) {
+                        if (src[srcOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
+                                || pattern[patternOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                             throw new AlgebricksException(AsterixBuiltinFunctions.SUBSTRING_AFTER.getName()
                                     + ": expects input type (STRING/NULL, STRING/NULL) but got ("
                                     + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(src[srcOffset]) + ", "
                                     + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(pattern[patternOffset]) + ").");
                         }
                         try {
-                            if (src[srcOffset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG
-                                    || pattern[patternOffset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
-                                out.writeByte(ATypeTag.SERIALIZED_NULL_TYPE_TAG);
-                                result.set(resultStorage);
-                                return;
-                            }
                             stringPtr.set(src, srcOffset + 1, srcLen - 1);
                             patternPtr.set(pattern, patternOffset + 1, patternLen - 1);
                             array.reset();

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/535d86b5/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringBeforeDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringBeforeDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringBeforeDescriptor.java
index f418213..65aa34b 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringBeforeDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringBeforeDescriptor.java
@@ -83,10 +83,8 @@ public class SubstringBeforeDescriptor extends AbstractScalarFunctionDynamicDesc
                         int patternOffset = array1.getStartOffset();
                         int patternLen = array1.getLength();
 
-                        if ((src[srcOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
-                                && src[srcOffset] != ATypeTag.SERIALIZED_NULL_TYPE_TAG)
-                                || (pattern[patternOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
-                                        && pattern[patternOffset] != ATypeTag.SERIALIZED_NULL_TYPE_TAG)) {
+                        if (src[srcOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG
+                                || pattern[patternOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                             throw new AlgebricksException(AsterixBuiltinFunctions.SUBSTRING_BEFORE.getName()
                                     + ": expects input type (STRING/NULL, STRING/NULL) but got ("
                                     + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(src[srcOffset]) + ", "
@@ -94,12 +92,6 @@ public class SubstringBeforeDescriptor extends AbstractScalarFunctionDynamicDesc
                         }
 
                         try {
-                            if (src[srcOffset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG
-                                    || pattern[patternOffset] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
-                                out.writeByte(ATypeTag.SERIALIZED_NULL_TYPE_TAG);
-                                result.set(resultStorage);
-                                return;
-                            }
                             stringPtr.set(src, srcOffset + 1, srcLen - 1);
                             patternPtr.set(pattern, patternOffset + 1, patternLen - 1);
                             array.reset();

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/535d86b5/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringDescriptor.java
index 660fbb8..e960b58 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SubstringDescriptor.java
@@ -25,18 +25,15 @@ 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.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.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.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;
@@ -67,7 +64,9 @@ public class SubstringDescriptor extends AbstractScalarFunctionDynamicDescriptor
 
                     private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
                     private final DataOutput out = resultStorage.getDataOutput();
-                    private final IPointable argPtr = new VoidPointable();
+                    private IPointable argString = new VoidPointable();
+                    private IPointable argStart = new VoidPointable();
+                    private IPointable argLen = 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);
@@ -79,81 +78,31 @@ public class SubstringDescriptor extends AbstractScalarFunctionDynamicDescriptor
                     @Override
                     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;
+                        evalString.evaluate(tuple, argString);
+                        evalStart.evaluate(tuple, argStart);
+                        evalLen.evaluate(tuple, argLen);
 
-                        ATypeTag argPtrTypeTag = ATypeTag.VALUE_TYPE_MAPPING[bytes[offset]];
-
-                        switch (argPtrTypeTag) {
-                            case INT64:
-                                start = (int) LongPointable.getLong(bytes, offset + 1) - 1;
-                                break;
-                            case INT32:
-                                start = IntegerPointable.getInteger(bytes, offset + 1) - 1;
-                                break;
-                            case INT8:
-                                start = bytes[offset + 1] - 1;
-                                break;
-                            case INT16:
-                                start = ShortPointable.getShort(bytes, offset + 1) - 1;
-                                break;
-                            case FLOAT:
-                                start = (int) FloatPointable.getFloat(bytes, offset + 1) - 1;
-                                break;
-                            case DOUBLE:
-                                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 "
-                                        + argPtrTypeTag);
+                        int start = 0;
+                        byte[] bytes = argStart.getByteArray();
+                        int offset = argStart.getStartOffset();
+                        try {
+                            start = ATypeHierarchy.getIntegerValue(bytes, offset) - 1;
+                        } catch (HyracksDataException e1) {
+                            throw new AlgebricksException(e1);
                         }
 
-                        evalLen.evaluate(tuple, argPtr);
-                        bytes = argPtr.getByteArray();
-                        offset = argPtr.getStartOffset();
                         int len = 0;
-
-                        argPtrTypeTag = ATypeTag.VALUE_TYPE_MAPPING[bytes[offset]];
-
-                        switch (argPtrTypeTag) {
-                            case INT64:
-                                len = (int) LongPointable.getLong(bytes, offset + 1);
-                                break;
-                            case INT32:
-                                len = IntegerPointable.getInteger(bytes, offset + 1);
-                                break;
-                            case INT8:
-                                len = bytes[offset + 1];
-                                break;
-                            case INT16:
-                                len = ShortPointable.getShort(bytes, offset + 1);
-                                break;
-                            case FLOAT:
-                                len = (int) FloatPointable.getFloat(bytes, offset + 1);
-                                break;
-                            case DOUBLE:
-                                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 "
-                                        + argPtrTypeTag);
-                        }
-
-                        evalString.evaluate(tuple, argPtr);
-                        bytes = argPtr.getByteArray();
-                        offset = argPtr.getStartOffset();
-                        int length = argPtr.getLength();
-                        argPtrTypeTag = ATypeTag.VALUE_TYPE_MAPPING[bytes[offset]];
-
-                        if (argPtrTypeTag != ATypeTag.STRING) {
-                            throw new AlgebricksException(AsterixBuiltinFunctions.SUBSTRING.getName()
-                                    + ": expects type STRING for the first argument but got " + argPtrTypeTag);
+                        bytes = argLen.getByteArray();
+                        offset = argLen.getStartOffset();
+                        try {
+                            len = ATypeHierarchy.getIntegerValue(bytes, offset);
+                        } catch (HyracksDataException e1) {
+                            throw new AlgebricksException(e1);
                         }
 
+                        bytes = argString.getByteArray();
+                        offset = argString.getStartOffset();
+                        int length = argString.getLength();
                         string.set(bytes, offset + 1, length - 1);
                         array.reset();
                         try {

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/535d86b5/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/AbstractBinaryScalarEvaluator.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/AbstractBinaryScalarEvaluator.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/AbstractBinaryScalarEvaluator.java
index e87c4eb..c12df6f 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/AbstractBinaryScalarEvaluator.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/AbstractBinaryScalarEvaluator.java
@@ -21,34 +21,25 @@ 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 {
+    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) {
@@ -57,27 +48,12 @@ public abstract class AbstractBinaryScalarEvaluator implements IScalarEvaluator
         }
     }
 
-    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) {
+    protected String rankToString(int i) {
         String prefix = "";
         if (i >= 10) {
             prefix = String.valueOf(i / 10);
@@ -94,7 +70,7 @@ public abstract class AbstractBinaryScalarEvaluator implements IScalarEvaluator
         }
     }
 
-    public static void checkTypeMachingThrowsIfNot(String title, ATypeTag[] expected, ATypeTag... actual)
+    protected void checkTypeMachingThrowsIfNot(String title, ATypeTag[] expected, ATypeTag... actual)
             throws AlgebricksException {
         for (int i = 0; i < expected.length; i++) {
             if (expected[i] != actual[i]) {

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/535d86b5/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/AbstractFindBinaryEvaluator.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/AbstractFindBinaryEvaluator.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/AbstractFindBinaryEvaluator.java
new file mode 100644
index 0000000..b9acc4d
--- /dev/null
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/binary/AbstractFindBinaryEvaluator.java
@@ -0,0 +1,122 @@
+/*
+ * 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.AInt64;
+import org.apache.asterix.om.base.AMutableInt64;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+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.ByteArrayPointable;
+import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+public abstract class AbstractFindBinaryEvaluator extends AbstractBinaryScalarEvaluator {
+
+    private static final ATypeTag[] EXPECTED_INPUT_TAG = { ATypeTag.BINARY, ATypeTag.BINARY };
+    protected String functionName;
+    protected AMutableInt64 result = new AMutableInt64(-1);
+    protected final ByteArrayPointable textPtr = new ByteArrayPointable();
+    protected final ByteArrayPointable wordPtr = new ByteArrayPointable();
+
+    @SuppressWarnings("unchecked")
+    protected ISerializerDeserializer<AInt64> intSerde = AqlSerializerDeserializerProvider.INSTANCE
+            .getSerializerDeserializer(BuiltinType.AINT64);
+
+    public AbstractFindBinaryEvaluator(IHyracksTaskContext context, IScalarEvaluatorFactory[] copyEvaluatorFactories,
+            String functionName) throws AlgebricksException {
+        super(context, copyEvaluatorFactories);
+        this.functionName = functionName;
+    }
+
+    @Override
+    public void evaluate(IFrameTupleReference tuple, IPointable resultPointable) throws AlgebricksException {
+        resultStorage.reset();
+        for (int i = 0; i < pointables.length; ++i) {
+            evaluators[i].evaluate(tuple, pointables[i]);
+        }
+
+        int fromOffset = getFromOffset(tuple);
+        try {
+            ATypeTag textTag = ATypeTag.VALUE_TYPE_MAPPING[pointables[0].getByteArray()[pointables[0]
+                    .getStartOffset()]];
+            ATypeTag wordTag = ATypeTag.VALUE_TYPE_MAPPING[pointables[1].getByteArray()[pointables[1]
+                    .getStartOffset()]];
+
+            checkTypeMachingThrowsIfNot(functionName, EXPECTED_INPUT_TAG, textTag, wordTag);
+            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(1L + indexOf(textPtr.getByteArray(), textPtr.getContentStartOffset(),
+                    textPtr.getContentLength(), wordPtr.getByteArray(), wordPtr.getContentStartOffset(),
+                    wordPtr.getContentLength(), fromOffset));
+            intSerde.serialize(result, dataOutput);
+        } catch (HyracksDataException e) {
+            throw new AlgebricksException(e);
+        }
+        resultPointable.set(resultStorage);
+    }
+
+    protected abstract int getFromOffset(IFrameTupleReference tuple) throws AlgebricksException;
+
+    // copy from String.indexOf(String)
+    private int indexOf(byte[] source, int sourceOffset, int sourceCount, byte[] target, int targetOffset,
+            int targetCount, int fromIndex) {
+        if (fromIndex >= sourceCount) {
+            return targetCount == 0 ? sourceCount : -1;
+        }
+        int from = fromIndex;
+        if (from < 0) {
+            from = 0;
+        }
+        if (targetCount == 0) {
+            return from;
+        }
+
+        byte first = target[targetOffset];
+        int max = sourceOffset + (sourceCount - targetCount);
+
+        for (int i = sourceOffset + fromIndex; i <= max; i++) {
+            /* Look for first character. */
+            if (source[i] != first) {
+                continue;
+            }
+
+            /* Found first character, now look at the rest of v2 */
+            int j = i + 1;
+            int end = j + targetCount - 1;
+            for (int k = targetOffset + 1; j < end && source[j] == target[k]; j++, k++) {
+                ;
+            }
+            if (j == end) {
+                /* Found whole string. */
+                return i - sourceOffset;
+            }
+        }
+        return -1;
+    }
+
+}


Mime
View raw message