asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From buyin...@apache.org
Subject [10/22] asterixdb git commit: Unify runtime type exceptions by using error code and message template.
Date Tue, 01 Nov 2016 03:08:19 GMT
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericTruncDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericTruncDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericTruncDescriptor.java
index 6900027..cd7251e 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericTruncDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/NumericTruncDescriptor.java
@@ -39,15 +39,13 @@ 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.runtime.exceptions.TypeMismatchException;
 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;
-import org.apache.hyracks.algebricks.common.exceptions.NotImplementedException;
 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;
@@ -80,7 +78,7 @@ public class NumericTruncDescriptor extends AbstractScalarFunctionDynamicDescrip
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
                 return new NumericTruncEvaluator(args, ctx);
             }
         };
@@ -102,12 +100,12 @@ public class NumericTruncDescriptor extends AbstractScalarFunctionDynamicDescrip
         @SuppressWarnings("rawtypes")
         private ISerializerDeserializer serde;
 
-        NumericTruncEvaluator(IScalarEvaluatorFactory[] args, IHyracksTaskContext ctx) throws AlgebricksException {
+        NumericTruncEvaluator(IScalarEvaluatorFactory[] args, IHyracksTaskContext ctx) throws HyracksDataException {
             eval = args[0].createScalarEvaluator(ctx);
             precision = args[1].createScalarEvaluator(ctx);
         }
 
-        private int getPrecision() throws AlgebricksException {
+        private int getPrecision() throws HyracksDataException {
             byte[] bytes = argPrecision.getByteArray();
             int offset = argPrecision.getStartOffset();
 
@@ -120,72 +118,70 @@ public class NumericTruncDescriptor extends AbstractScalarFunctionDynamicDescrip
             } else if (bytes[offset] == ATypeTag.SERIALIZED_INT64_TYPE_TAG) {
                 return (int) AInt64SerializerDeserializer.getLong(bytes, offset + 1);
             } else {
-                throw new AlgebricksException(NumericTruncDescriptor.this.getIdentifier().getName()
-                        + ": the precision argument should be an INT8/INT16/INT32/INT64.");
+                throw new TypeMismatchException(getIdentifier(), 1, bytes[offset],
+                        ATypeTag.SERIALIZED_INT8_TYPE_TAG, ATypeTag.SERIALIZED_INT16_TYPE_TAG,
+                        ATypeTag.SERIALIZED_INT32_TYPE_TAG, ATypeTag.SERIALIZED_INT64_TYPE_TAG);
             }
         }
 
         @SuppressWarnings("unchecked")
         @Override
-        public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+        public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
             resultStorage.reset();
             eval.evaluate(tuple, argValue);
             precision.evaluate(tuple, argPrecision);
             byte[] data = argValue.getByteArray();
             int offset = argValue.getStartOffset();
 
-            try {
-                if (data[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) {
-                    serde = AqlSerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT8);
-                    byte val = AInt8SerializerDeserializer.getByte(data, offset + 1);
-                    aInt8.setValue(val);
-                    serde.serialize(aInt8, out);
-                } else if (data[offset] == ATypeTag.SERIALIZED_INT16_TYPE_TAG) {
-                    serde = AqlSerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT16);
-                    short val = AInt16SerializerDeserializer.getShort(data, offset + 1);
-                    aInt16.setValue(val);
-                    serde.serialize(aInt16, out);
-                } else if (data[offset] == ATypeTag.SERIALIZED_INT32_TYPE_TAG) {
-                    serde = AqlSerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT32);
-                    int val = AInt32SerializerDeserializer.getInt(data, offset + 1);
-                    aInt32.setValue(val);
-                    serde.serialize(aInt32, out);
-                } else if (data[offset] == ATypeTag.SERIALIZED_INT64_TYPE_TAG) {
-                    serde = AqlSerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
-                    long val = AInt64SerializerDeserializer.getLong(data, offset + 1);
-                    aInt64.setValue(val);
-                    serde.serialize(aInt64, out);
-                } else if (data[offset] == ATypeTag.SERIALIZED_FLOAT_TYPE_TAG) {
-                    serde = AqlSerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AFLOAT);
-                    float val = AFloatSerializerDeserializer.getFloat(data, offset + 1);
-                    if (Float.isNaN(val) || Float.isInfinite(val) || Float.compare(val, -0.0F) == 0
-                            || Float.compare(val, 0.0F) == 0) {
-                        aFloat.setValue(val);
-                        serde.serialize(aFloat, out);
-                    } else {
-                        BigDecimal r = new BigDecimal(Float.toString(val));
-                        aFloat.setValue(r.setScale(getPrecision(), BigDecimal.ROUND_DOWN).floatValue());
-                        serde.serialize(aFloat, out);
-                    }
-                } else if (data[offset] == ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) {
-                    serde = AqlSerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE);
-                    double val = ADoubleSerializerDeserializer.getDouble(data, offset + 1);
-                    if (Double.isNaN(val) || Double.isInfinite(val) || Double.compare(val, -0.0D) == 0
-                            || Double.compare(val, 0.0D) == 0) {
-                        aDouble.setValue(val);
-                        serde.serialize(aDouble, out);
-                    } else {
-                        BigDecimal r = new BigDecimal(Double.toString(val));
-                        aDouble.setValue(r.setScale(getPrecision(), BigDecimal.ROUND_DOWN).doubleValue());
-                        serde.serialize(aDouble, out);
-                    }
+            if (data[offset] == ATypeTag.SERIALIZED_INT8_TYPE_TAG) {
+                serde = AqlSerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT8);
+                byte val = AInt8SerializerDeserializer.getByte(data, offset + 1);
+                aInt8.setValue(val);
+                serde.serialize(aInt8, out);
+            } else if (data[offset] == ATypeTag.SERIALIZED_INT16_TYPE_TAG) {
+                serde = AqlSerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT16);
+                short val = AInt16SerializerDeserializer.getShort(data, offset + 1);
+                aInt16.setValue(val);
+                serde.serialize(aInt16, out);
+            } else if (data[offset] == ATypeTag.SERIALIZED_INT32_TYPE_TAG) {
+                serde = AqlSerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT32);
+                int val = AInt32SerializerDeserializer.getInt(data, offset + 1);
+                aInt32.setValue(val);
+                serde.serialize(aInt32, out);
+            } else if (data[offset] == ATypeTag.SERIALIZED_INT64_TYPE_TAG) {
+                serde = AqlSerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
+                long val = AInt64SerializerDeserializer.getLong(data, offset + 1);
+                aInt64.setValue(val);
+                serde.serialize(aInt64, out);
+            } else if (data[offset] == ATypeTag.SERIALIZED_FLOAT_TYPE_TAG) {
+                serde = AqlSerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AFLOAT);
+                float val = AFloatSerializerDeserializer.getFloat(data, offset + 1);
+                if (Float.isNaN(val) || Float.isInfinite(val) || Float.compare(val, -0.0F) == 0
+                        || Float.compare(val, 0.0F) == 0) {
+                    aFloat.setValue(val);
+                    serde.serialize(aFloat, out);
                 } else {
-                    throw new NotImplementedException(
-                            NumericTruncDescriptor.this.getIdentifier().getName() + ": not implemented for "
-                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(data[offset]));
+                    BigDecimal r = new BigDecimal(Float.toString(val));
+                    aFloat.setValue(r.setScale(getPrecision(), BigDecimal.ROUND_DOWN).floatValue());
+                    serde.serialize(aFloat, out);
                 }
-            } catch (HyracksDataException e) {
-                throw new AlgebricksException(e);
+            } else if (data[offset] == ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) {
+                serde = AqlSerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE);
+                double val = ADoubleSerializerDeserializer.getDouble(data, offset + 1);
+                if (Double.isNaN(val) || Double.isInfinite(val) || Double.compare(val, -0.0D) == 0
+                        || Double.compare(val, 0.0D) == 0) {
+                    aDouble.setValue(val);
+                    serde.serialize(aDouble, out);
+                } else {
+                    BigDecimal r = new BigDecimal(Double.toString(val));
+                    aDouble.setValue(r.setScale(getPrecision(), BigDecimal.ROUND_DOWN).doubleValue());
+                    serde.serialize(aDouble, out);
+                }
+            } else {
+                throw new TypeMismatchException(getIdentifier(), 0, data[offset],
+                        ATypeTag.SERIALIZED_INT8_TYPE_TAG, ATypeTag.SERIALIZED_INT16_TYPE_TAG,
+                        ATypeTag.SERIALIZED_INT32_TYPE_TAG, ATypeTag.SERIALIZED_INT64_TYPE_TAG,
+                        ATypeTag.SERIALIZED_FLOAT_TYPE_TAG, ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
             }
             result.set(resultStorage);
         }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/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 43b72c0..1478962 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
@@ -22,11 +22,11 @@ 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.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;
 
 public class NumericUnaryMinusDescriptor extends AbstractScalarFunctionDynamicDescriptor {
@@ -50,7 +50,7 @@ public class NumericUnaryMinusDescriptor extends AbstractScalarFunctionDynamicDe
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
                 return new NumericUnaryMinusEvaluator(ctx, args[0]);
             }
         };
@@ -59,42 +59,42 @@ public class NumericUnaryMinusDescriptor extends AbstractScalarFunctionDynamicDe
     private class NumericUnaryMinusEvaluator extends AbstractUnaryNumericFunctionEval {
 
         NumericUnaryMinusEvaluator(IHyracksTaskContext context, IScalarEvaluatorFactory argEvalFactory)
-                throws AlgebricksException {
+                throws HyracksDataException {
             super(context, argEvalFactory, NumericUnaryMinusDescriptor.this.getIdentifier());
         }
 
         @Override
-        protected void processInt8(byte arg, IPointable resultPointable) throws AlgebricksException {
+        protected void processInt8(byte arg, IPointable resultPointable) throws HyracksDataException {
             aInt8.setValue((byte) -arg);
             serialize(aInt8, int8Serde, resultPointable);
         }
 
         @Override
-        protected void processInt16(short arg, IPointable resultPointable) throws AlgebricksException {
+        protected void processInt16(short arg, IPointable resultPointable) throws HyracksDataException {
             aInt16.setValue((short) -arg);
             serialize(aInt16, int16Serde, resultPointable);
         }
 
         @Override
-        protected void processInt32(int arg, IPointable resultPointable) throws AlgebricksException {
+        protected void processInt32(int arg, IPointable resultPointable) throws HyracksDataException {
             aInt32.setValue(-arg);
             serialize(aInt32, int32Serde, resultPointable);
         }
 
         @Override
-        protected void processInt64(long arg, IPointable resultPointable) throws AlgebricksException {
+        protected void processInt64(long arg, IPointable resultPointable) throws HyracksDataException {
             aInt64.setValue(-arg);
             serialize(aInt64, int64Serde, resultPointable);
         }
 
         @Override
-        protected void processFloat(float arg, IPointable resultPointable) throws AlgebricksException {
+        protected void processFloat(float arg, IPointable resultPointable) throws HyracksDataException {
             aFloat.setValue(-arg);
             serialize(aFloat, floatSerde, resultPointable);
         }
 
         @Override
-        protected void processDouble(double arg, IPointable resultPointable) throws AlgebricksException {
+        protected void processDouble(double arg, IPointable resultPointable) throws HyracksDataException {
             aDouble.setValue(-arg);
             serialize(aDouble, doubleSerde, resultPointable);
         }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/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 a98f4bb..6c1ac38 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
@@ -31,7 +31,7 @@ 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.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.asterix.runtime.exceptions.TypeMismatchException;
 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;
@@ -58,14 +58,12 @@ public class OrDescriptor extends AbstractScalarFunctionDynamicDescriptor {
     }
 
     @Override
-    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
-            throws AlgebricksException {
-
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
                 final IPointable argPtr = new VoidPointable();
                 final IScalarEvaluator[] evals = new IScalarEvaluator[args.length];
                 for (int i = 0; i < evals.length; i++) {
@@ -86,49 +84,49 @@ public class OrDescriptor extends AbstractScalarFunctionDynamicDescriptor {
                             .getSerializerDeserializer(BuiltinType.AMISSING);
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
-                        try {
-                            resultStorage.reset();
-                            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) {
-                                    // anything OR TRUE = TRUE
-                                    booleanSerde.serialize(ABoolean.TRUE, output);
-                                    result.set(resultStorage);
-                                    return;
-                                }
-                                res |= argResult;
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
+                        resultStorage.reset();
+                        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;
                             }
-                            if (metNull) {
-                                // 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;
-                                booleanSerde.serialize(aResult, output);
+                            if (data[offset] != ATypeTag.SERIALIZED_BOOLEAN_TYPE_TAG) {
+                                throw new TypeMismatchException(getIdentifier(), i, data[offset],
+                                        ATypeTag.SERIALIZED_BOOLEAN_TYPE_TAG);
                             }
-                            result.set(resultStorage);
-                        } catch (HyracksDataException hde) {
-                            throw new AlgebricksException(hde);
+                            boolean argResult = ABooleanSerializerDeserializer.getBoolean(data, offset + 1);
+                            if (argResult == true) {
+                                // anything OR TRUE = TRUE
+                                booleanSerde.serialize(ABoolean.TRUE, output);
+                                result.set(resultStorage);
+                                return;
+                            }
+                            res |= argResult;
+                        }
+                        if (metNull) {
+                            // 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;
+                            booleanSerde.serialize(aResult, output);
                         }
+                        result.set(resultStorage);
                     }
                 };
             }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/OrderedListConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/OrderedListConstructorDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/OrderedListConstructorDescriptor.java
index ffb8432..2dd9ef9 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/OrderedListConstructorDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/OrderedListConstructorDescriptor.java
@@ -28,11 +28,11 @@ import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
 import org.apache.asterix.om.types.AOrderedListType;
 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.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;
@@ -83,7 +83,7 @@ public class OrderedListConstructorDescriptor extends AbstractScalarFunctionDyna
         }
 
         @Override
-        public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
+        public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
             final IScalarEvaluator[] argEvals = new IScalarEvaluator[args.length];
             for (int i = 0; i < args.length; i++) {
                 argEvals[i] = args[i].createScalarEvaluator(ctx);
@@ -96,7 +96,7 @@ public class OrderedListConstructorDescriptor extends AbstractScalarFunctionDyna
                 private final OrderedListBuilder builder = new OrderedListBuilder();
 
                 @Override
-                public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                     try {
                         resultStorage.reset();
                         builder.reset(orderedlistType);
@@ -108,11 +108,11 @@ public class OrderedListConstructorDescriptor extends AbstractScalarFunctionDyna
                         builder.write(out, true);
                         result.set(resultStorage);
                     } catch (IOException ioe) {
-                        throw new AlgebricksException(ioe);
+                        throw new HyracksDataException(ioe);
                     }
                 }
 
-                private void writeUntypedItems(IFrameTupleReference tuple) throws AlgebricksException {
+                private void writeUntypedItems(IFrameTupleReference tuple) throws HyracksDataException {
 
                     try {
                         for (int i = 0; i < argEvals.length; i++) {
@@ -121,11 +121,11 @@ public class OrderedListConstructorDescriptor extends AbstractScalarFunctionDyna
                         }
 
                     } catch (IOException ioe) {
-                        throw new AlgebricksException(ioe);
+                        throw new HyracksDataException(ioe);
                     }
                 }
 
-                private void writeTypedItems(IFrameTupleReference tuple) throws AlgebricksException {
+                private void writeTypedItems(IFrameTupleReference tuple) throws HyracksDataException {
 
                     try {
                         for (int i = 0; i < argEvals.length; i++) {
@@ -134,7 +134,7 @@ public class OrderedListConstructorDescriptor extends AbstractScalarFunctionDyna
                         }
 
                     } catch (IOException ioe) {
-                        throw new AlgebricksException(ioe);
+                        throw new HyracksDataException(ioe);
                     }
                 }
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/PointableHelper.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/PointableHelper.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/PointableHelper.java
index 24e66f2..5a293f3 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/PointableHelper.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/PointableHelper.java
@@ -25,7 +25,6 @@ import org.apache.asterix.common.exceptions.AsterixException;
 import org.apache.asterix.om.pointables.base.IVisitablePointable;
 import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.EnumDeserializer;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.api.dataflow.value.IBinaryComparator;
 import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.data.std.accessors.PointableBinaryComparatorFactory;
@@ -112,7 +111,6 @@ public class PointableHelper {
      *            The storage buffer
      * @param writeTag
      *            Specifying whether a tag for the string should also be written
-     * @throws AlgebricksException
      */
     public void serializeString(String str, IMutableValueStorage vs, boolean writeTag) throws AsterixException {
         vs.reset();

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/PrefixLenDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/PrefixLenDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/PrefixLenDescriptor.java
index 8bfcfae..a4ba6dc 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/PrefixLenDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/PrefixLenDescriptor.java
@@ -27,19 +27,19 @@ import org.apache.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import org.apache.asterix.fuzzyjoin.similarity.SimilarityFilters;
 import org.apache.asterix.om.base.AInt32;
 import org.apache.asterix.om.base.AMutableInt32;
+import org.apache.asterix.runtime.exceptions.TypeMismatchException;
 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.SimilarityFiltersCache;
-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.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.IntegerPointable;
 import org.apache.hyracks.data.std.primitive.VoidPointable;
@@ -59,14 +59,12 @@ public class PrefixLenDescriptor extends AbstractScalarFunctionDynamicDescriptor
     };
 
     @Override
-    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
-            throws AlgebricksException {
-
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
 
                 return new IScalarEvaluator() {
 
@@ -86,16 +84,15 @@ public class PrefixLenDescriptor extends AbstractScalarFunctionDynamicDescriptor
                             .getSerializerDeserializer(BuiltinType.AINT32);
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                         resultStorage.reset();
                         // length
                         evalLen.evaluate(tuple, inputVal);
                         byte[] data = inputVal.getByteArray();
                         int offset = inputVal.getStartOffset();
                         if (data[offset] != ATypeTag.SERIALIZED_INT32_TYPE_TAG) {
-                            throw new AlgebricksException(
-                                    FID.getName() + ": expects type Int32 for the first argument, but got "
-                                            + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(data[offset]));
+                            throw new TypeMismatchException(getIdentifier(), 0, data[offset],
+                                    ATypeTag.SERIALIZED_INT32_TYPE_TAG);
                         }
                         int length = IntegerPointable.getInteger(data, offset + 1);
 
@@ -104,9 +101,8 @@ public class PrefixLenDescriptor extends AbstractScalarFunctionDynamicDescriptor
                         data = inputVal.getByteArray();
                         offset = inputVal.getStartOffset();
                         if (data[offset] != ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) {
-                            throw new AlgebricksException(
-                                    FID.getName() + ": expects type DOUBLE for the second argument, but got "
-                                            + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(data[offset]));
+                            throw new TypeMismatchException(getIdentifier(), 1, data[offset],
+                                    ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
                         }
                         float similarityThreshold = (float) ADoubleSerializerDeserializer.getDouble(data, offset + 1);
 
@@ -116,9 +112,8 @@ public class PrefixLenDescriptor extends AbstractScalarFunctionDynamicDescriptor
                         offset = inputVal.getStartOffset();
                         int len = inputVal.getLength();
                         if (data[offset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
-                            throw new AlgebricksException(
-                                    FID.getName() + ": expects type STRING for the third argument, but got "
-                                            + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(data[offset]));
+                            throw new TypeMismatchException(getIdentifier(), 2, data[offset],
+                                    ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                         }
                         SimilarityFilters similarityFilters = similarityFiltersCache.get(similarityThreshold, data,
                                 offset, len);
@@ -129,7 +124,7 @@ public class PrefixLenDescriptor extends AbstractScalarFunctionDynamicDescriptor
                         try {
                             int32Serde.serialize(res, out);
                         } catch (IOException e) {
-                            throw new AlgebricksException(e);
+                            throw new HyracksDataException(e);
                         }
                         result.set(resultStorage);
                     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/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 c9e5807..bb3a522 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
@@ -31,10 +31,9 @@ import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
 import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.BuiltinType;
-import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.asterix.om.types.hierachy.ATypeHierarchy;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.asterix.runtime.exceptions.TypeMismatchException;
 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;
@@ -57,14 +56,12 @@ public class PrefixLenJaccardDescriptor extends AbstractScalarFunctionDynamicDes
     };
 
     @Override
-    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
-            throws AlgebricksException {
-
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
 
                 return new IScalarEvaluator() {
 
@@ -85,26 +82,20 @@ public class PrefixLenJaccardDescriptor extends AbstractScalarFunctionDynamicDes
                             .getSerializerDeserializer(BuiltinType.AINT32);
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                         resultStorage.reset();
                         evalLen.evaluate(tuple, lenPtr);
                         evalThreshold.evaluate(tuple, thresholdPtr);
 
                         // length
-                        int length = 0;
-                        try {
-                            length = ATypeHierarchy.getIntegerValue(lenPtr.getByteArray(), lenPtr.getStartOffset());
-                        } catch (HyracksDataException e1) {
-                            throw new AlgebricksException(e1);
-                        }
-
+                        int length = ATypeHierarchy.getIntegerValue(getIdentifier().getName(), 0, lenPtr.getByteArray(),
+                                lenPtr.getStartOffset());
                         // similarity threshold
                         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 "
-                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(data[offset]));
+                            throw new TypeMismatchException(getIdentifier(), 1, data[offset],
+                                    ATypeTag.SERIALIZED_FLOAT_TYPE_TAG);
                         }
                         float similarityThreshold = AFloatSerializerDeserializer.getFloat(data, offset + 1);
 
@@ -118,7 +109,7 @@ public class PrefixLenJaccardDescriptor extends AbstractScalarFunctionDynamicDes
                         try {
                             int32Serde.serialize(res, out);
                         } catch (IOException e) {
-                            throw new AlgebricksException(e);
+                            throw new HyracksDataException(e);
                         }
                         result.set(resultStorage);
                     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityDescriptor.java
index d1d0a3c..5f29fad 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityDescriptor.java
@@ -33,19 +33,19 @@ import org.apache.asterix.fuzzyjoin.similarity.SimilarityFilters;
 import org.apache.asterix.fuzzyjoin.similarity.SimilarityMetric;
 import org.apache.asterix.om.base.ADouble;
 import org.apache.asterix.om.base.AMutableDouble;
+import org.apache.asterix.runtime.exceptions.TypeMismatchException;
 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.SimilarityFiltersCache;
-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.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.IntegerPointable;
 import org.apache.hyracks.data.std.primitive.VoidPointable;
@@ -65,14 +65,12 @@ public class SimilarityDescriptor extends AbstractScalarFunctionDynamicDescripto
     };
 
     @Override
-    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
-            throws AlgebricksException {
-
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
 
                 return new IScalarEvaluator() {
 
@@ -100,7 +98,7 @@ public class SimilarityDescriptor extends AbstractScalarFunctionDynamicDescripto
                             .getSerializerDeserializer(BuiltinType.ADOUBLE);
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                         resultStorage.reset();
                         // similarity threshold
                         evalThreshold.evaluate(tuple, inputVal);
@@ -108,9 +106,8 @@ public class SimilarityDescriptor extends AbstractScalarFunctionDynamicDescripto
                         int offset = inputVal.getStartOffset();
 
                         if (data[offset] != ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) {
-                            throw new AlgebricksException(
-                                    FID.getName() + ": expects type DOUBLE for the first argument but got "
-                                            + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(data[offset]));
+                            throw new TypeMismatchException(getIdentifier(), 0, data[offset],
+                                    ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
                         }
                         float similarityThreshold = (float) ADoubleSerializerDeserializer.getDouble(data, offset + 1);
 
@@ -120,9 +117,8 @@ public class SimilarityDescriptor extends AbstractScalarFunctionDynamicDescripto
                         offset = inputVal.getStartOffset();
                         int len = inputVal.getLength();
                         if (data[offset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
-                            throw new AlgebricksException(
-                                    FID.getName() + ": expects type STRING for the second argument but got "
-                                            + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(data[offset]));
+                            throw new TypeMismatchException(getIdentifier(), 1, data[offset],
+                                    ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
                         }
                         SimilarityFilters similarityFilters = similarityFiltersCache.get(similarityThreshold, data,
                                 offset, len);
@@ -131,9 +127,8 @@ public class SimilarityDescriptor extends AbstractScalarFunctionDynamicDescripto
                         data = inputVal.getByteArray();
                         offset = inputVal.getStartOffset();
                         if (data[offset] != ATypeTag.SERIALIZED_INT32_TYPE_TAG) {
-                            throw new AlgebricksException(
-                                    FID.getName() + ": expects type INT32 for the thrid argument but got "
-                                            + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(data[offset]));
+                            throw new TypeMismatchException(getIdentifier(), 2, data[offset],
+                                    ATypeTag.SERIALIZED_INT32_TYPE_TAG);
                         }
                         int length1 = IntegerPointable.getInteger(data, offset + 1);
 
@@ -141,9 +136,8 @@ public class SimilarityDescriptor extends AbstractScalarFunctionDynamicDescripto
                         data = inputVal.getByteArray();
                         offset = inputVal.getStartOffset();
                         if (data[offset] != ATypeTag.SERIALIZED_INT32_TYPE_TAG) {
-                            throw new AlgebricksException(
-                                    FID.getName() + ": expects type INT32 for the fourth argument but got "
-                                            + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(data[offset]));
+                            throw new TypeMismatchException(getIdentifier(), 3, data[offset],
+                                    ATypeTag.SERIALIZED_INT32_TYPE_TAG);
                         }
                         int length2 = IntegerPointable.getInteger(data, offset + 1);
 
@@ -163,8 +157,9 @@ public class SimilarityDescriptor extends AbstractScalarFunctionDynamicDescripto
 
                             if (serList[offset] != ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG
                                     && serList[offset] != ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG) {
-                                throw new AlgebricksException(FID.getName() + ": not defined for values of type"
-                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serList[offset]));
+                                throw new TypeMismatchException(getIdentifier(), 4, data[offset],
+                                        ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG,
+                                        ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG);
                             }
 
                             int lengthTokens1;
@@ -177,7 +172,7 @@ public class SimilarityDescriptor extends AbstractScalarFunctionDynamicDescripto
                                         itemOffset = AOrderedListSerializerDeserializer.getItemOffset(serList, offset,
                                                 i);
                                     } catch (AsterixException e) {
-                                        throw new AlgebricksException(e);
+                                        throw new HyracksDataException(e);
                                     }
                                     tokens1.add(IntegerPointable.getInteger(serList, itemOffset));
                                 }
@@ -190,7 +185,7 @@ public class SimilarityDescriptor extends AbstractScalarFunctionDynamicDescripto
                                         itemOffset = AUnorderedListSerializerDeserializer.getItemOffset(serList, offset,
                                                 i);
                                     } catch (AsterixException e) {
-                                        throw new AlgebricksException(e);
+                                        throw new HyracksDataException(e);
                                     }
                                     tokens1.add(IntegerPointable.getInteger(serList, itemOffset));
                                 }
@@ -208,8 +203,9 @@ public class SimilarityDescriptor extends AbstractScalarFunctionDynamicDescripto
 
                             if (serList[offset] != ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG
                                     && serList[offset] != ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG) {
-                                throw new AlgebricksException(FID.getName() + ": not defined for values of type"
-                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serList[offset]));
+                                throw new TypeMismatchException(getIdentifier(), 5, data[offset],
+                                        ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG,
+                                        ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG);
                             }
 
                             int lengthTokens2;
@@ -222,7 +218,7 @@ public class SimilarityDescriptor extends AbstractScalarFunctionDynamicDescripto
                                         itemOffset = AOrderedListSerializerDeserializer.getItemOffset(serList, offset,
                                                 i);
                                     } catch (AsterixException e) {
-                                        throw new AlgebricksException(e);
+                                        throw new HyracksDataException(e);
                                     }
                                     tokens2.add(IntegerPointable.getInteger(serList, itemOffset));
                                 }
@@ -235,7 +231,7 @@ public class SimilarityDescriptor extends AbstractScalarFunctionDynamicDescripto
                                         itemOffset = AUnorderedListSerializerDeserializer.getItemOffset(serList, offset,
                                                 i);
                                     } catch (AsterixException e) {
-                                        throw new AlgebricksException(e);
+                                        throw new HyracksDataException(e);
                                     }
                                     tokens2.add(IntegerPointable.getInteger(serList, itemOffset));
                                 }
@@ -276,7 +272,7 @@ public class SimilarityDescriptor extends AbstractScalarFunctionDynamicDescripto
                         try {
                             doubleSerde.serialize(res, out);
                         } catch (IOException e) {
-                            throw new AlgebricksException(e);
+                            throw new HyracksDataException(e);
                         }
                         result.set(resultStorage);
                     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardCheckDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardCheckDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardCheckDescriptor.java
index 29a6f6f..fabe832 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardCheckDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardCheckDescriptor.java
@@ -23,11 +23,11 @@ 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.asterix.runtime.evaluators.common.SimilarityJaccardCheckEvaluator;
-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;
 
 public class SimilarityJaccardCheckDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
@@ -40,13 +40,12 @@ public class SimilarityJaccardCheckDescriptor extends AbstractScalarFunctionDyna
     };
 
     @Override
-    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
-            throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
                 return new SimilarityJaccardCheckEvaluator(args, ctx);
             }
         };

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardDescriptor.java
index 6c3847a..e81143d 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardDescriptor.java
@@ -23,11 +23,11 @@ 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.asterix.runtime.evaluators.common.SimilarityJaccardEvaluator;
-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;
 
 public class SimilarityJaccardDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
@@ -40,13 +40,12 @@ public class SimilarityJaccardDescriptor extends AbstractScalarFunctionDynamicDe
     };
 
     @Override
-    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
-            throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
                 return new SimilarityJaccardEvaluator(args, ctx);
             }
         };

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardPrefixCheckDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardPrefixCheckDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardPrefixCheckDescriptor.java
index e28a784..97999ef 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardPrefixCheckDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardPrefixCheckDescriptor.java
@@ -32,12 +32,12 @@ import org.apache.asterix.om.types.AOrderedListType;
 import org.apache.asterix.om.types.BuiltinType;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.asterix.runtime.evaluators.common.SimilarityJaccardPrefixEvaluator;
-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.dataflow.value.ISerializerDeserializer;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 
 public class SimilarityJaccardPrefixCheckDescriptor extends AbstractScalarFunctionDynamicDescriptor {
@@ -52,13 +52,12 @@ public class SimilarityJaccardPrefixCheckDescriptor extends AbstractScalarFuncti
     };
 
     @Override
-    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
-            throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
                 return new SimilarityJaccardPrefixCheckEvaluator(args, ctx);
             }
         };
@@ -84,14 +83,14 @@ public class SimilarityJaccardPrefixCheckDescriptor extends AbstractScalarFuncti
         private final AOrderedListType listType = new AOrderedListType(BuiltinType.ANY, "list");
 
         public SimilarityJaccardPrefixCheckEvaluator(IScalarEvaluatorFactory[] args, IHyracksTaskContext context)
-                throws AlgebricksException {
+                throws HyracksDataException {
             super(args, context);
             listBuilder = new OrderedListBuilder();
             inputVal = new ArrayBackedValueStorage();
         }
 
         @Override
-        public void writeResult() throws AlgebricksException, IOException {
+        public void writeResult() throws HyracksDataException, IOException {
             listBuilder.reset(listType);
             boolean matches = (sim <= 0) ? false : true;
             float jaccSim = (matches) ? sim : 0.0f;
@@ -104,7 +103,6 @@ public class SimilarityJaccardPrefixCheckDescriptor extends AbstractScalarFuncti
             aFloat.setValue(jaccSim);
             floatSerde.serialize(aFloat, inputVal.getDataOutput());
             listBuilder.addItem(inputVal);
-
             listBuilder.write(out, true);
         }
     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardPrefixDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardPrefixDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardPrefixDescriptor.java
index 144a328..cb479d5 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardPrefixDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardPrefixDescriptor.java
@@ -23,11 +23,11 @@ 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.asterix.runtime.evaluators.common.SimilarityJaccardPrefixEvaluator;
-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;
 
 public class SimilarityJaccardPrefixDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
@@ -40,13 +40,12 @@ public class SimilarityJaccardPrefixDescriptor extends AbstractScalarFunctionDyn
     };
 
     @Override
-    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
-            throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
                 return new SimilarityJaccardPrefixEvaluator(args, ctx);
             }
         };

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardSortedCheckDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardSortedCheckDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardSortedCheckDescriptor.java
index 6e34ffb..9c1cddb 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardSortedCheckDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardSortedCheckDescriptor.java
@@ -23,11 +23,11 @@ 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.asterix.runtime.evaluators.common.SimilarityJaccardSortedCheckEvaluator;
-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;
 
 // Assumes that both arguments are sorted by the same ordering.
 public class SimilarityJaccardSortedCheckDescriptor extends AbstractScalarFunctionDynamicDescriptor {
@@ -41,13 +41,12 @@ public class SimilarityJaccardSortedCheckDescriptor extends AbstractScalarFuncti
     };
 
     @Override
-    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
-            throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
                 return new SimilarityJaccardSortedCheckEvaluator(args, ctx);
             }
         };

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardSortedDescriptor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardSortedDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardSortedDescriptor.java
index 4995e25..47195e2 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardSortedDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/SimilarityJaccardSortedDescriptor.java
@@ -23,11 +23,11 @@ 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.asterix.runtime.evaluators.common.SimilarityJaccardSortedEvaluator;
-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;
 
 // Assumes that both arguments are sorted by the same ordering.
 public class SimilarityJaccardSortedDescriptor extends AbstractScalarFunctionDynamicDescriptor {
@@ -41,13 +41,12 @@ public class SimilarityJaccardSortedDescriptor extends AbstractScalarFunctionDyn
     };
 
     @Override
-    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
-            throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
                 return new SimilarityJaccardSortedEvaluator(args, ctx);
             }
         };

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/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 e31ad90..dec2cdb 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
@@ -33,8 +33,8 @@ import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import org.apache.asterix.runtime.evaluators.common.SpatialUtils;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
-import org.apache.hyracks.algebricks.common.exceptions.NotImplementedException;
+import org.apache.asterix.runtime.exceptions.InvalidDataFormatException;
+import org.apache.asterix.runtime.exceptions.TypeMismatchException;
 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;
@@ -56,13 +56,12 @@ public class SpatialAreaDescriptor extends AbstractScalarFunctionDynamicDescript
     };
 
     @Override
-    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
-            throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
                 return new IScalarEvaluator() {
 
                     private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
@@ -71,7 +70,7 @@ public class SpatialAreaDescriptor extends AbstractScalarFunctionDynamicDescript
                     private final IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                         resultStorage.reset();
                         eval.evaluate(tuple, argPtr);
 
@@ -86,8 +85,8 @@ public class SpatialAreaDescriptor extends AbstractScalarFunctionDynamicDescript
                                     int numOfPoints = AInt16SerializerDeserializer.getShort(bytes, offset + 1);
 
                                     if (numOfPoints < 3) {
-                                        throw new AlgebricksException(AsterixBuiltinFunctions.SPATIAL_AREA.getName()
-                                                + ": polygon must have at least 3 points");
+                                        throw new InvalidDataFormatException(getIdentifier(),
+                                                ATypeTag.SERIALIZED_POLYGON_TYPE_TAG);
                                     }
                                     area = Math.abs(SpatialUtils.polygonArea(bytes, offset, numOfPoints));
                                     out.writeByte(ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
@@ -119,14 +118,12 @@ public class SpatialAreaDescriptor extends AbstractScalarFunctionDynamicDescript
                                     out.writeDouble(area);
                                     break;
                                 default:
-                                    throw new NotImplementedException(AsterixBuiltinFunctions.SPATIAL_AREA.getName()
-                                            + ": does not support the type: " + tag
-                                            + "; it is only implemented for POLYGON, CIRCLE and RECTANGLE.");
+                                    throw new TypeMismatchException(getIdentifier(), 0, bytes[offset],
+                                            ATypeTag.SERIALIZED_POLYGON_TYPE_TAG, ATypeTag.SERIALIZED_CIRCLE_TYPE_TAG,
+                                            ATypeTag.SERIALIZED_RECTANGLE_TYPE_TAG);
                             }
-                        } catch (HyracksDataException hde) {
-                            throw new AlgebricksException(hde);
                         } catch (IOException e) {
-                            throw new AlgebricksException(e);
+                            throw new HyracksDataException(e);
                         }
                         result.set(resultStorage);
                     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/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 2208d6f..1862517 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
@@ -33,14 +33,14 @@ 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;
+import org.apache.asterix.runtime.exceptions.TypeMismatchException;
 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;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
@@ -57,13 +57,12 @@ public class SpatialCellDescriptor extends AbstractScalarFunctionDynamicDescript
     };
 
     @Override
-    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
-            throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
                 return new IScalarEvaluator() {
 
                     private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
@@ -84,7 +83,7 @@ public class SpatialCellDescriptor extends AbstractScalarFunctionDynamicDescript
                             .getSerializerDeserializer(BuiltinType.ARECTANGLE);
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                         resultStorage.reset();
                         eval0.evaluate(tuple, inputArg0);
                         eval1.evaluate(tuple, inputArg1);
@@ -101,12 +100,13 @@ public class SpatialCellDescriptor extends AbstractScalarFunctionDynamicDescript
                         int offset3 = inputArg3.getStartOffset();
 
                         try {
-                            ATypeTag tag0 = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes0[offset0]);
-                            ATypeTag tag1 = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes1[offset1]);
-                            ATypeTag tag2 = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes2[offset2]);
-                            ATypeTag tag3 = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes3[offset3]);
-                            if (tag0 == ATypeTag.POINT && tag1 == ATypeTag.POINT && tag2 == ATypeTag.DOUBLE
-                                    && tag3 == ATypeTag.DOUBLE) {
+                            byte tag0 = bytes0[offset0];
+                            byte tag1 = bytes1[offset1];
+                            byte tag2 = bytes2[offset2];
+                            byte tag3 = bytes3[offset3];
+                            if (tag0 == ATypeTag.SERIALIZED_POINT_TYPE_TAG && tag1 == ATypeTag.SERIALIZED_POINT_TYPE_TAG
+                                    && tag2 == ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG
+                                    && tag3 == ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) {
                                 double xLoc = ADoubleSerializerDeserializer.getDouble(bytes0,
                                         offset0 + APointSerializerDeserializer.getCoordinateOffset(Coordinate.X));
                                 double yLoc = ADoubleSerializerDeserializer.getDouble(bytes0,
@@ -127,16 +127,26 @@ public class SpatialCellDescriptor extends AbstractScalarFunctionDynamicDescript
                                 aRectangle.setValue(aPoint[0], aPoint[1]);
                                 rectangleSerde.serialize(aRectangle, out);
                             } else {
-                                throw new AlgebricksException(AsterixBuiltinFunctions.SPATIAL_CELL.getName()
-                                        + ": expects input type: (POINT, POINT, DOUBLE, DOUBLE) but got ("
-                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes0[offset0]) + ", "
-                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes1[offset1]) + ", "
-                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes2[offset2]) + ", "
-                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes3[offset3]) + ").");
+                                if (tag0 != ATypeTag.SERIALIZED_POINT_TYPE_TAG) {
+                                    throw new TypeMismatchException(getIdentifier(), 0, tag0,
+                                            ATypeTag.SERIALIZED_POINT_TYPE_TAG);
+                                }
+                                if (tag1 != ATypeTag.SERIALIZED_POINT_TYPE_TAG) {
+                                    throw new TypeMismatchException(getIdentifier(), 1, tag1,
+                                            ATypeTag.SERIALIZED_POINT_TYPE_TAG);
+                                }
+                                if (tag2 != ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) {
+                                    throw new TypeMismatchException(getIdentifier(), 2, tag2,
+                                            ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
+                                }
+                                if (tag3 != ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG) {
+                                    throw new TypeMismatchException(getIdentifier(), 3, tag3,
+                                            ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
+                                }
                             }
                             result.set(resultStorage);
                         } catch (IOException e1) {
-                            throw new AlgebricksException(e1);
+                            throw new HyracksDataException(e1);
                         }
                     }
                 };

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/52671a2c/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 5c969b1..0ff1eb1 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,14 +24,12 @@ 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.runtime.exceptions.TypeMismatchException;
 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.EnumDeserializer;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
-import org.apache.hyracks.algebricks.common.exceptions.NotImplementedException;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
@@ -53,13 +51,12 @@ public class SpatialDistanceDescriptor extends AbstractScalarFunctionDynamicDesc
     };
 
     @Override
-    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args)
-            throws AlgebricksException {
+    public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         return new IScalarEvaluatorFactory() {
             private static final long serialVersionUID = 1L;
 
             @Override
-            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws AlgebricksException {
+            public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
                 return new IScalarEvaluator() {
 
                     private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
@@ -70,7 +67,7 @@ public class SpatialDistanceDescriptor extends AbstractScalarFunctionDynamicDesc
                     private final IScalarEvaluator eval1 = args[1].createScalarEvaluator(ctx);
 
                     @Override
-                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws AlgebricksException {
+                    public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                         resultStorage.reset();
                         eval0.evaluate(tuple, inputArg0);
                         eval1.evaluate(tuple, inputArg1);
@@ -81,11 +78,11 @@ public class SpatialDistanceDescriptor extends AbstractScalarFunctionDynamicDesc
                             int offset0 = inputArg0.getStartOffset();
                             int offset1 = inputArg1.getStartOffset();
 
-                            ATypeTag tag0 = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes0[offset0]);
-                            ATypeTag tag1 = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes1[offset1]);
+                            byte tag0 = bytes0[offset0];
+                            byte tag1 = bytes1[offset1];
                             double distance;
-                            if (tag0 == ATypeTag.POINT) {
-                                if (tag1 == ATypeTag.POINT) {
+                            if (tag0 == ATypeTag.SERIALIZED_POINT_TYPE_TAG) {
+                                if (tag1 == ATypeTag.SERIALIZED_POINT_TYPE_TAG) {
                                     double x1 = ADoubleSerializerDeserializer.getDouble(bytes0,
                                             offset0 + APointSerializerDeserializer.getCoordinateOffset(Coordinate.X));
                                     double y1 = ADoubleSerializerDeserializer.getDouble(bytes0,
@@ -96,21 +93,17 @@ public class SpatialDistanceDescriptor extends AbstractScalarFunctionDynamicDesc
                                             offset1 + APointSerializerDeserializer.getCoordinateOffset(Coordinate.Y));
                                     distance = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
                                 } else {
-                                    throw new NotImplementedException(AsterixBuiltinFunctions.SPATIAL_DISTANCE.getName()
-                                            + ": does not support the type: " + tag1
-                                            + "; it is only implemented for POINT.");
+                                    throw new TypeMismatchException(getIdentifier(), 1, bytes1[offset1],
+                                            ATypeTag.SERIALIZED_POINT_TYPE_TAG);
                                 }
                             } else {
-                                throw new NotImplementedException(AsterixBuiltinFunctions.SPATIAL_DISTANCE.getName()
-                                        + ": does not support the type: " + tag1
-                                        + "; it is only implemented for POINT.");
+                                throw new TypeMismatchException(getIdentifier(), 0, bytes0[offset0],
+                                        ATypeTag.SERIALIZED_POINT_TYPE_TAG);
                             }
                             out.writeByte(ATypeTag.SERIALIZED_DOUBLE_TYPE_TAG);
                             out.writeDouble(distance);
-                        } catch (HyracksDataException hde) {
-                            throw new AlgebricksException(hde);
                         } catch (IOException e) {
-                            throw new AlgebricksException(e);
+                            throw new HyracksDataException(e);
                         }
                         result.set(resultStorage);
                     }


Mime
View raw message