updated functions with type-checking.

git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_stabilization_func_type_check@1394 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-app/src/test/resources/runtimets/queries/constructor/point_01.aql b/asterix-app/src/test/resources/runtimets/queries/constructor/point_01.aql
index 09c770c..aeac860 100644
--- a/asterix-app/src/test/resources/runtimets/queries/constructor/point_01.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/constructor/point_01.aql
@@ -8,4 +8,4 @@
 let $c2 := point3d("5e2, -10E+5, +10.5e-10d")
 let $c3 := point("5.10E-10d, -10E5")
 let $c4 := point3d("0.5e+2d, -10.0E+5d, +10.05e-10")
-return {"point1": $c1,"point3d1": $c2,"point2": $c3, "point3d2": $c4}
\ No newline at end of file
+return {"point1": $c1,"point3d1": $c2,"point2": $c3, "point3d2": $c4 }
\ No newline at end of file
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/CreateMBREvalFactory.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/CreateMBREvalFactory.java
index e20212c..d6dbc08 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/CreateMBREvalFactory.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/CreateMBREvalFactory.java
@@ -27,6 +27,8 @@
 
     private static final long serialVersionUID = 1L;
 
+    private static final byte SER_INT32_TYPE_TAG = ATypeTag.INT32.serialize();
+
     private ICopyEvaluatorFactory recordEvalFactory;
     private ICopyEvaluatorFactory dimensionEvalFactory;
     private ICopyEvaluatorFactory coordinateEvalFactory;
@@ -61,6 +63,12 @@
                 outInput2.reset();
                 eval2.evaluate(tuple);
 
+                // type-check: (int32, int32, double)
+                if (outInput1.getByteArray()[0] != SER_INT32_TYPE_TAG
+                        || outInput2.getByteArray()[0] != SER_INT32_TYPE_TAG) {
+                    throw new AlgebricksException("Expects Types: (Point/Line/Polygon/Circle/Rectangle/Null, Int32, Int32).");
+                }
+
                 try {
 
                     int dimension = AInt32SerializerDeserializer.getInt(outInput1.getByteArray(), 1);
@@ -204,9 +212,9 @@
                                         double x = ADoubleSerializerDeserializer.getDouble(outInput0.getByteArray(),
                                                 ACircleSerializerDeserializer
                                                         .getCenterPointCoordinateOffset(Coordinate.X));
-                                        double radius = ADoubleSerializerDeserializer.getDouble(outInput0.getByteArray(),
-                                                ACircleSerializerDeserializer
-                                                        .getCenterPointCoordinateOffset(Coordinate.X));
+                                        double radius = ADoubleSerializerDeserializer.getDouble(outInput0
+                                                .getByteArray(), ACircleSerializerDeserializer
+                                                .getCenterPointCoordinateOffset(Coordinate.X));
 
                                         value = x - radius;
                                     }
@@ -215,9 +223,9 @@
                                         double y = ADoubleSerializerDeserializer.getDouble(outInput0.getByteArray(),
                                                 ACircleSerializerDeserializer
                                                         .getCenterPointCoordinateOffset(Coordinate.Y));
-                                        double radius = ADoubleSerializerDeserializer.getDouble(outInput0.getByteArray(),
-                                                ACircleSerializerDeserializer
-                                                        .getCenterPointCoordinateOffset(Coordinate.Y));
+                                        double radius = ADoubleSerializerDeserializer.getDouble(outInput0
+                                                .getByteArray(), ACircleSerializerDeserializer
+                                                .getCenterPointCoordinateOffset(Coordinate.Y));
 
                                         value = y - radius;
                                     }
@@ -226,9 +234,9 @@
                                         double x = ADoubleSerializerDeserializer.getDouble(outInput0.getByteArray(),
                                                 ACircleSerializerDeserializer
                                                         .getCenterPointCoordinateOffset(Coordinate.X));
-                                        double radius = ADoubleSerializerDeserializer.getDouble(outInput0.getByteArray(),
-                                                ACircleSerializerDeserializer
-                                                        .getCenterPointCoordinateOffset(Coordinate.X));
+                                        double radius = ADoubleSerializerDeserializer.getDouble(outInput0
+                                                .getByteArray(), ACircleSerializerDeserializer
+                                                .getCenterPointCoordinateOffset(Coordinate.X));
 
                                         value = x + radius;
                                     }
@@ -237,9 +245,9 @@
                                         double y = ADoubleSerializerDeserializer.getDouble(outInput0.getByteArray(),
                                                 ACircleSerializerDeserializer
                                                         .getCenterPointCoordinateOffset(Coordinate.Y));
-                                        double radius = ADoubleSerializerDeserializer.getDouble(outInput0.getByteArray(),
-                                                ACircleSerializerDeserializer
-                                                        .getCenterPointCoordinateOffset(Coordinate.Y));
+                                        double radius = ADoubleSerializerDeserializer.getDouble(outInput0
+                                                .getByteArray(), ACircleSerializerDeserializer
+                                                .getCenterPointCoordinateOffset(Coordinate.Y));
 
                                         value = y + radius;
                                     }
@@ -284,13 +292,13 @@
                                 }
                                 break;
                             case NULL: {
-                            	out.writeByte(ATypeTag.NULL.serialize());
-                            	return;
+                                out.writeByte(ATypeTag.NULL.serialize());
+                                return;
                             }
                             default:
                                 throw new NotImplementedException(
-									"create-mbr is only implemented for POINT, LINE, POLYGON, CIRCLE and RECTANGLE. Encountered type: "
-											+ tag + ".");
+                                        "create-mbr is only implemented for POINT, LINE, POLYGON, CIRCLE and RECTANGLE. Encountered type: "
+                                                + tag + ".");
 
                         }
                     } else {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractBinaryStringBoolEval.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractBinaryStringBoolEval.java
index 03a0ba8..fb3bf0f 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractBinaryStringBoolEval.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractBinaryStringBoolEval.java
@@ -2,8 +2,6 @@
 
 import java.io.DataOutput;
 import java.util.Arrays;
-import java.util.logging.Level;
-import java.util.logging.Logger;
 
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import edu.uci.ics.asterix.om.base.ABoolean;
@@ -21,7 +19,11 @@
 public abstract class AbstractBinaryStringBoolEval implements ICopyEvaluator {
 
     private DataOutput dout;
+
+    // allowed input types
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+    private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
+
     private ArrayBackedValueStorage array0 = new ArrayBackedValueStorage();
     private ArrayBackedValueStorage array1 = new ArrayBackedValueStorage();
     private ICopyEvaluator evalLeft;
@@ -47,15 +49,16 @@
 
         try {
             if (array0.getByteArray()[0] == SER_NULL_TYPE_TAG && array1.getByteArray()[0] == SER_NULL_TYPE_TAG) {
-                try {
-                    boolSerde.serialize(ABoolean.TRUE, dout);
-                } catch (HyracksDataException ex) {
-                    Logger.getLogger(AbstractBinaryStringBoolEval.class.getName()).log(Level.SEVERE, null, ex);
-                }
+                boolSerde.serialize(ABoolean.TRUE, dout);
                 return;
-            } else if (array0.getByteArray()[0] == SER_NULL_TYPE_TAG || array1.getByteArray()[0] == SER_NULL_TYPE_TAG) {
+            } else if ((array0.getByteArray()[0] == SER_NULL_TYPE_TAG && array1.getByteArray()[0] == SER_STRING_TYPE_TAG)
+                    || (array0.getByteArray()[0] == SER_STRING_TYPE_TAG && array1.getByteArray()[0] == SER_NULL_TYPE_TAG)) {
                 boolSerde.serialize(ABoolean.FALSE, dout);
                 return;
+            } else if (array0.getByteArray()[0] != SER_STRING_TYPE_TAG
+                    || array1.getByteArray()[0] != SER_STRING_TYPE_TAG) {
+                throw new AlgebricksException("Expects String or NULL Type (got " + array0.getByteArray()[0] + " and "
+                        + array1.getByteArray()[0] + ")!");
             }
         } catch (HyracksDataException e) {
             throw new AlgebricksException(e);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractNumericArithmeticEval.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractNumericArithmeticEval.java
index f585965..ce6a905 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractNumericArithmeticEval.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractNumericArithmeticEval.java
@@ -130,7 +130,7 @@
                                     default: {
                                         throw new NotImplementedException(i == 0 ? "Left"
                                                 : "Right"
-                                                        + " Operand of Division can not be "
+                                                        + " Operand can not be "
                                                         + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut
                                                                 .getByteArray()[0]));
                                     }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractQuadStringStringEval.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractQuadStringStringEval.java
index 37a9d20..271cc09 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractQuadStringStringEval.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractQuadStringStringEval.java
@@ -5,7 +5,6 @@
 package edu.uci.ics.asterix.runtime.evaluators.functions;
 
 import java.io.DataOutput;
-import java.io.IOException;
 import java.util.Arrays;
 import java.util.regex.Pattern;
 
@@ -74,18 +73,18 @@
                 nullSerde.serialize(ANull.NULL, dout);
                 return;
             } else if (array0.getByteArray()[0] == SER_STRING_TYPE_TAG) {
-                if (array0.getByteArray()[1] == SER_NULL_TYPE_TAG) {
-                    dout.write(array0.getByteArray(), array0.getStartOffset(), array0.getLength());
-                    return;
+                if ((array1.getByteArray()[0] != SER_STRING_TYPE_TAG && array1.getByteArray()[0] != SER_NULL_TYPE_TAG)
+                        || (array2.getByteArray()[0] != SER_STRING_TYPE_TAG && array2.getByteArray()[0] != SER_NULL_TYPE_TAG)
+                        || (array3.getByteArray()[0] != SER_STRING_TYPE_TAG && array3.getByteArray()[0] != SER_NULL_TYPE_TAG)) {
+                    throw new AlgebricksException("Expects String or NULL Type (but got " + array1.getByteArray()[0]
+                            + ", " + array2.getByteArray()[0] + ", " + array3.getByteArray()[0] + ".");
                 }
 
             } else {
-                throw new AlgebricksException("Expects String Type.");
+                throw new AlgebricksException("Expects String or NULL Type.");
             }
         } catch (HyracksDataException e) {
             throw new AlgebricksException(e);
-        } catch (IOException e) {
-            throw new AlgebricksException(e.getMessage());
         }
 
         byte[] b0 = array0.getByteArray();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractStringContainsEval.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractStringContainsEval.java
index eed3a24..872e841 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractStringContainsEval.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractStringContainsEval.java
@@ -4,6 +4,7 @@
 
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import edu.uci.ics.asterix.om.base.ABoolean;
+import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
@@ -17,6 +18,10 @@
 
     private DataOutput dout;
 
+    // allowed input types
+    private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+    private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
+
     private ArrayBackedValueStorage array0 = new ArrayBackedValueStorage();
     private ArrayBackedValueStorage array1 = new ArrayBackedValueStorage();
     private ICopyEvaluator evalString;
@@ -39,6 +44,28 @@
         evalPattern.evaluate(tuple);
         array0.reset();
         evalString.evaluate(tuple);
+
+        try {
+            if (array1.getByteArray()[0] == SER_NULL_TYPE_TAG) {
+                if (array0.getByteArray()[0] == SER_NULL_TYPE_TAG || array0.getByteArray()[0] == SER_STRING_TYPE_TAG) {
+                    boolSerde.serialize(ABoolean.TRUE, dout);
+                    return;
+                }
+            } else if (array0.getByteArray()[0] == SER_NULL_TYPE_TAG) {
+                if (array1.getByteArray()[0] == SER_STRING_TYPE_TAG) {
+                    boolSerde.serialize(ABoolean.FALSE, dout);
+                    return;
+                }
+
+            }
+
+            if (array0.getByteArray()[0] != SER_STRING_TYPE_TAG || array1.getByteArray()[0] != SER_STRING_TYPE_TAG) {
+                throw new AlgebricksException("Expects String or NULL Type.");
+            }
+        } catch (HyracksDataException e) {
+            throw new AlgebricksException(e);
+        }
+
         byte[] b1 = array0.getByteArray();
         byte[] b2 = array1.getByteArray();
         ABoolean res = findMatch(b1, b2) ? ABoolean.TRUE : ABoolean.FALSE;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractTripleStringBoolEval.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractTripleStringBoolEval.java
index a0c963b..dba46aa 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractTripleStringBoolEval.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractTripleStringBoolEval.java
@@ -24,6 +24,7 @@
 
     private DataOutput dout;
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+    private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
     private ArrayBackedValueStorage array0 = new ArrayBackedValueStorage();
     private ArrayBackedValueStorage array1 = new ArrayBackedValueStorage();
     private ArrayBackedValueStorage array2 = new ArrayBackedValueStorage();
@@ -53,13 +54,20 @@
         eval2.evaluate(tuple);
 
         try {
-            if (array0.getByteArray()[0] == SER_NULL_TYPE_TAG && array1.getByteArray()[0] == SER_NULL_TYPE_TAG) {
-                boolSerde.serialize(ABoolean.TRUE, dout);
-                return;
-            } else if (array0.getByteArray()[0] == SER_NULL_TYPE_TAG || array1.getByteArray()[0] == SER_NULL_TYPE_TAG) {
+            if ((array0.getByteArray()[0] == SER_NULL_TYPE_TAG && array1.getByteArray()[0] == SER_STRING_TYPE_TAG)
+                    || (array1.getByteArray()[0] == SER_NULL_TYPE_TAG && array0.getByteArray()[0] == SER_STRING_TYPE_TAG)) {
                 boolSerde.serialize(ABoolean.FALSE, dout);
                 return;
+            } else if (array0.getByteArray()[0] == SER_NULL_TYPE_TAG && array1.getByteArray()[0] == SER_NULL_TYPE_TAG) {
+                boolSerde.serialize(ABoolean.TRUE, dout);
+                return;
             }
+
+            if (array0.getByteArray()[0] != SER_STRING_TYPE_TAG || array1.getByteArray()[0] != SER_STRING_TYPE_TAG) {
+                throw new AlgebricksException(
+                        "Expects String or NULL Type for the first argument and String Type for the second argument.");
+            }
+
         } catch (HyracksDataException e) {
             throw new AlgebricksException(e);
         }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractTripleStringStringEval.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractTripleStringStringEval.java
index e38fe8a..9307d0e 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractTripleStringStringEval.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractTripleStringStringEval.java
@@ -1,7 +1,6 @@
 package edu.uci.ics.asterix.runtime.evaluators.functions;
 
 import java.io.DataOutput;
-import java.io.IOException;
 import java.util.Arrays;
 import java.util.regex.Pattern;
 
@@ -61,22 +60,21 @@
         eval2.evaluate(tuple);
 
         try {
+            // type-check: (string?, string, string)
+
             if (array0.getByteArray()[0] == SER_NULL_TYPE_TAG) {
-                nullSerde.serialize(ANull.NULL, dout);
-                return;
-            } else if (array0.getByteArray()[0] == SER_STRING_TYPE_TAG) {
-                if (array0.getByteArray()[1] == SER_NULL_TYPE_TAG) {
-                    dout.write(array0.getByteArray(), array0.getStartOffset(), array0.getLength());
+                if (array1.getByteArray()[0] == SER_STRING_TYPE_TAG && array2.getByteArray()[0] == SER_STRING_TYPE_TAG) {
+                    nullSerde.serialize(ANull.NULL, dout);
                     return;
                 }
+            }
 
-            } else {
+            if (array0.getByteArray()[0] != SER_STRING_TYPE_TAG || array1.getByteArray()[0] != SER_STRING_TYPE_TAG
+                    || array2.getByteArray()[0] != SER_STRING_TYPE_TAG) {
                 throw new AlgebricksException("Expects String Type.");
             }
         } catch (HyracksDataException e) {
             throw new AlgebricksException(e);
-        } catch (IOException e) {
-            throw new AlgebricksException(e.getMessage());
         }
 
         byte[] b0 = array0.getByteArray();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AndDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AndDescriptor.java
index b2fc6da..a090dc2 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AndDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AndDescriptor.java
@@ -93,5 +93,4 @@
             }
         };
     }
-
 }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/ClosedRecordConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/ClosedRecordConstructorDescriptor.java
index ac6bfe5..cdfd9d3 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/ClosedRecordConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/ClosedRecordConstructorDescriptor.java
@@ -1,6 +1,5 @@
 package edu.uci.ics.asterix.runtime.evaluators.functions;
 
-import edu.uci.ics.asterix.common.functions.FunctionConstants;
 import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CodePointToStringDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CodePointToStringDescriptor.java
index 55fe563..2a1d851 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CodePointToStringDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CodePointToStringDescriptor.java
@@ -6,20 +6,16 @@
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AOrderedListSerializerDeserializer;
-import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import edu.uci.ics.asterix.om.base.ANull;
 import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
 import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.om.types.EnumDeserializer;
 import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
 import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
@@ -36,7 +32,6 @@
             return new CodePointToStringDescriptor();
         }
     };
-    private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     private final static byte SER_ORDEREDLIST_TYPE_TAG = ATypeTag.ORDEREDLIST.serialize();
     private final static byte[] currentUTF8 = new byte[6];
     private final byte stringTypeTag = ATypeTag.STRING.serialize();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateCircleDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateCircleDescriptor.java
index 5cef4da..85c6332 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateCircleDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateCircleDescriptor.java
@@ -13,6 +13,7 @@
 import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
@@ -27,6 +28,10 @@
 public class CreateCircleDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
+    
+    private static final byte SER_DOUBLE_TYPE_TAG = ATypeTag.DOUBLE.serialize();
+    private static final byte SER_POINT_TYPE_TAG = ATypeTag.POINT.serialize();
+    
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new CreateCircleDescriptor();
@@ -61,6 +66,12 @@
                         outInput1.reset();
                         eval1.evaluate(tuple);
 
+                        
+                        // Type check: (point, double)
+                        if(outInput0.getByteArray()[0] != SER_POINT_TYPE_TAG || outInput1.getByteArray()[0] != SER_DOUBLE_TYPE_TAG){
+                            throw new AlgebricksException("Expects Type: (Point, Double).");
+                        }
+                        
                         try {
                             aPoint.setValue(ADoubleSerializerDeserializer.getDouble(outInput0.getByteArray(),
                                     APointSerializerDeserializer.getCoordinateOffset(Coordinate.X)),
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateLineDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateLineDescriptor.java
index 42931b8..f74ae36 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateLineDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateLineDescriptor.java
@@ -13,6 +13,7 @@
 import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
@@ -27,6 +28,10 @@
 public class CreateLineDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
+
+    // allowed input type
+    private static final byte SER_POINT_TYPE_TAG = ATypeTag.POINT.serialize();
+
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new CreateLineDescriptor();
@@ -61,6 +66,12 @@
                         outInput1.reset();
                         eval1.evaluate(tuple);
 
+                        // type-check: (point, point)
+                        if (outInput0.getByteArray()[0] != SER_POINT_TYPE_TAG
+                                || outInput1.getByteArray()[0] != SER_POINT_TYPE_TAG) {
+                            throw new AlgebricksException("Expects Types: (Point, Point).");
+                        }
+
                         try {
                             aPoint[0].setValue(ADoubleSerializerDeserializer.getDouble(outInput0.getByteArray(),
                                     APointSerializerDeserializer.getCoordinateOffset(Coordinate.X)),
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreatePointDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreatePointDescriptor.java
index 6099ab6..61a6283 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreatePointDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreatePointDescriptor.java
@@ -10,6 +10,7 @@
 import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
@@ -24,6 +25,10 @@
 public class CreatePointDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
+
+    // allowed input type
+    private static final byte SER_DOUBLE_TYPE_TAG = ATypeTag.DOUBLE.serialize();
+
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new CreatePointDescriptor();
@@ -57,6 +62,12 @@
                         outInput1.reset();
                         eval1.evaluate(tuple);
 
+                        // type-check: (double, double)
+                        if (outInput0.getByteArray()[0] != SER_DOUBLE_TYPE_TAG
+                                || outInput1.getByteArray()[0] != SER_DOUBLE_TYPE_TAG) {
+                            throw new AlgebricksException("Expects Type: (Double, Double).");
+                        }
+
                         try {
                             aPoint.setValue(ADoubleSerializerDeserializer.getDouble(outInput0.getByteArray(), 1),
                                     ADoubleSerializerDeserializer.getDouble(outInput1.getByteArray(), 1));
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateRectangleDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateRectangleDescriptor.java
index 36a9266..1b13fb0 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateRectangleDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateRectangleDescriptor.java
@@ -13,6 +13,7 @@
 import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
@@ -27,6 +28,10 @@
 public class CreateRectangleDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
+
+    // allowed input type
+    private static final byte SER_POINT_TYPE_TAG = ATypeTag.POINT.serialize();
+
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new CreateRectangleDescriptor();
@@ -60,6 +65,11 @@
                         outInput1.reset();
                         eval1.evaluate(tuple);
 
+                        if (outInput0.getByteArray()[0] != SER_POINT_TYPE_TAG
+                                || outInput1.getByteArray()[0] != SER_POINT_TYPE_TAG) {
+                            throw new AlgebricksException("Expects Types: (Point, Point).");
+                        }
+
                         try {
                             aPoint[0].setValue(ADoubleSerializerDeserializer.getDouble(outInput0.getByteArray(),
                                     APointSerializerDeserializer.getCoordinateOffset(Coordinate.X)),
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FieldAccessByNameDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FieldAccessByNameDescriptor.java
index 3c4e6d8..306d7fd 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FieldAccessByNameDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FieldAccessByNameDescriptor.java
@@ -4,7 +4,6 @@
 import java.io.IOException;
 
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
-import edu.uci.ics.asterix.common.functions.FunctionConstants;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ARecordSerializerDeserializer;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import edu.uci.ics.asterix.om.base.ANull;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/LikeDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/LikeDescriptor.java
index 4344f33..62d83d0 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/LikeDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/LikeDescriptor.java
@@ -39,7 +39,11 @@
 public class LikeDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
+
+    // allowed input types
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+    private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
+
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new LikeDescriptor();
@@ -94,6 +98,9 @@
                                 nullSerde.serialize(ANull.NULL, dout);
                                 return;
                             }
+                            if (array0.getByteArray()[0] != SER_STRING_TYPE_TAG) {
+                                throw new AlgebricksException("Expects Types: String/Null, String/Null");
+                            }
                             boolean newPattern = false;
                             if (first) {
                                 first = false;
@@ -121,6 +128,9 @@
                                 nullSerde.serialize(ANull.NULL, dout);
                                 return;
                             }
+                            if (array0.getByteArray()[0] != SER_STRING_TYPE_TAG) {
+                                throw new AlgebricksException("Expects Types: String/Null, String/Null");
+                            }
                             carSeq.reset(array0, 1);
                             if (newPattern) {
                                 matcher = pattern.matcher(carSeq);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/PrefixLenDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/PrefixLenDescriptor.java
index 019f655..5d0888e 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/PrefixLenDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/PrefixLenDescriptor.java
@@ -10,6 +10,7 @@
 import edu.uci.ics.asterix.om.base.AMutableInt32;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import edu.uci.ics.asterix.runtime.evaluators.common.SimilarityFiltersCache;
@@ -27,6 +28,12 @@
 public class PrefixLenDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
+    
+    // allowed input types
+    private final static byte SER_INT32_TYPE_TAG = ATypeTag.INT32.serialize();
+    private final static byte SER_DOUBLE_TYPE_TAG = ATypeTag.DOUBLE.serialize();
+    private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
+    
     private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "prefix-len@3", 3);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
@@ -64,17 +71,26 @@
                         // length
                         inputVal.reset();
                         evalLen.evaluate(tuple);
+                        if(inputVal.getByteArray()[0] != SER_INT32_TYPE_TAG){
+                            throw new AlgebricksException("Expects Int32 Type for the first argument of PrefixLen.");
+                        }
                         int length = IntegerSerializerDeserializer.getInt(inputVal.getByteArray(), 1);
 
                         // similarity threshold
                         inputVal.reset();
                         evalThreshold.evaluate(tuple);
+                        if(inputVal.getByteArray()[0] != SER_DOUBLE_TYPE_TAG){
+                            throw new AlgebricksException("Expects Double Type for the second argument of PrefixLen.");
+                        }
                         float similarityThreshold = (float) ADoubleSerializerDeserializer.getDouble(
                                 inputVal.getByteArray(), 1);
 
                         // similarity name
                         inputVal.reset();
                         evalSimilarity.evaluate(tuple);
+                        if(inputVal.getByteArray()[0] != SER_STRING_TYPE_TAG){
+                            throw new AlgebricksException("Expects String Type for the third argument of PrefixLen.");
+                        }
                         SimilarityFilters similarityFilters = similarityFiltersCache.get(similarityThreshold,
                                 inputVal.getByteArray());
 
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/PrefixLenJaccardDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/PrefixLenJaccardDescriptor.java
index 4138932..c6da64f 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/PrefixLenJaccardDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/PrefixLenJaccardDescriptor.java
@@ -10,6 +10,7 @@
 import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.BuiltinType;
 import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
 import edu.uci.ics.fuzzyjoin.similarity.SimilarityFiltersJaccard;
@@ -26,6 +27,11 @@
 public class PrefixLenJaccardDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
+
+    // allowed input types
+    private final static byte SER_INT32_TYPE_TAG = ATypeTag.INT32.serialize();
+    private final static byte SER_FLOAT_TYPE_TAG = ATypeTag.FLOAT.serialize();
+
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new PrefixLenJaccardDescriptor();
@@ -62,11 +68,17 @@
                         // length
                         inputVal.reset();
                         evalLen.evaluate(tuple);
+                        if(inputVal.getByteArray()[0] != SER_INT32_TYPE_TAG){
+                            throw new AlgebricksException("Expects Int32 Type for the first argument of PrefixLenJaccard.");
+                        }
                         int length = IntegerSerializerDeserializer.getInt(inputVal.getByteArray(), 1);
 
                         // similarity threshold
                         inputVal.reset();
                         evalThreshold.evaluate(tuple);
+                        if(inputVal.getByteArray()[0] != SER_FLOAT_TYPE_TAG){
+                            throw new AlgebricksException("Expects Float Type for the second argument of PrefixLenJaccard.");
+                        }
                         float similarityThreshold = (float) AFloatSerializerDeserializer.getFloat(
                                 inputVal.getByteArray(), 1);
 
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/RegExpDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/RegExpDescriptor.java
index be01d28..2099a55 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/RegExpDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/RegExpDescriptor.java
@@ -38,7 +38,11 @@
 public class RegExpDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
+    
+    // allowed input types
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+    private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
+    
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new RegExpDescriptor();
@@ -93,6 +97,9 @@
                                 nullSerde.serialize(ANull.NULL, dout);
                                 return;
                             }
+                            if(array0.getByteArray()[0] != SER_STRING_TYPE_TAG) {
+                                throw new AlgebricksException("Expects String/Null Type for RegExp function.");
+                            }
                             boolean newPattern = false;
                             if (first) {
                                 first = false;
@@ -120,6 +127,9 @@
                                 nullSerde.serialize(ANull.NULL, dout);
                                 return;
                             }
+                            if(array0.getByteArray()[0] != SER_STRING_TYPE_TAG) {
+                                throw new AlgebricksException("Expects String/Null Type for RegExp function.");
+                            }
                             carSeq.reset(array0, 1);
                             if (newPattern) {
                                 matcher = pattern.matcher(carSeq);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityDescriptor.java
index a2d9cc7..959b250 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityDescriptor.java
@@ -37,8 +37,12 @@
     private static final long serialVersionUID = 1L;
     private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "similarity@7", 7);
 
+    private final static byte SER_DOUBLE_TYPE_TAG = ATypeTag.DOUBLE.serialize();
+    private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
+    private final static byte SER_INT32_TYPE_TAG = ATypeTag.INT32.serialize();
     private final static byte SER_ORDEREDLIST_TYPE_TAG = ATypeTag.ORDEREDLIST.serialize();
     private final static byte SER_UNORDEREDLIST_TYPE_TAG = ATypeTag.UNORDEREDLIST.serialize();
+    
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new SimilarityDescriptor();
@@ -83,21 +87,33 @@
                         // similarity threshold
                         inputVal.reset();
                         evalThreshold.evaluate(tuple);
+                        if(inputVal.getByteArray()[0] != SER_DOUBLE_TYPE_TAG) {
+                            throw new AlgebricksException("Expects Double Type for the first argument of Similarity Function.");
+                        }
                         float similarityThreshold = (float) ADoubleSerializerDeserializer.getDouble(
                                 inputVal.getByteArray(), 1);
 
                         // similarity name
                         inputVal.reset();
                         evalSimilarity.evaluate(tuple);
+                        if(inputVal.getByteArray()[0] != SER_STRING_TYPE_TAG) {
+                            throw new AlgebricksException("Expects String Type for the second argument of Similarity Function.");
+                        }
                         SimilarityFilters similarityFilters = similarityFiltersCache.get(similarityThreshold,
                                 inputVal.getByteArray());
 
                         inputVal.reset();
                         evalLen1.evaluate(tuple);
+                        if(inputVal.getByteArray()[0] != SER_INT32_TYPE_TAG) {
+                            throw new AlgebricksException("Expects Int32 Type for the third argument of Similarity Function.");
+                        }
                         int length1 = IntegerSerializerDeserializer.getInt(inputVal.getByteArray(), 1);
 
                         inputVal.reset();
                         evalLen2.evaluate(tuple);
+                        if(inputVal.getByteArray()[0] != SER_INT32_TYPE_TAG) {
+                            throw new AlgebricksException("Expects Int32 Type for the fourth argument of Similarity Function.");
+                        }
                         int length2 = IntegerSerializerDeserializer.getInt(inputVal.getByteArray(), 1);
 
                         float sim = 0;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardPrefixDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardPrefixDescriptor.java
index 3c2f981..79a0894 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardPrefixDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardPrefixDescriptor.java
@@ -1,6 +1,5 @@
 package edu.uci.ics.asterix.runtime.evaluators.functions;
 
-import edu.uci.ics.asterix.common.functions.FunctionConstants;
 import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialIntersectDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialIntersectDescriptor.java
index bd3aef5..7b10ed3d8 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialIntersectDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialIntersectDescriptor.java
@@ -36,6 +36,7 @@
 public class SpatialIntersectDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
+    
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new SpatialIntersectDescriptor();
@@ -67,6 +68,7 @@
                     private final DoubleArray trianglesY1 = new DoubleArray();
 
                     private boolean pointOnLine(byte[] bytes0, byte[] bytes1) throws HyracksDataException {
+                        
                         double startX = ADoubleSerializerDeserializer.getDouble(bytes0,
                                 ALineSerializerDeserializer.getStartPointCoordinateOffset(Coordinate.X));
                         double startY = ADoubleSerializerDeserializer.getDouble(bytes0,
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringLowerCaseDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringLowerCaseDescriptor.java
index 6bc79ac..4aaf8aa 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringLowerCaseDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringLowerCaseDescriptor.java
@@ -3,7 +3,6 @@
 import java.io.DataOutput;
 import java.io.IOException;
 
-import edu.uci.ics.asterix.common.functions.FunctionConstants;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import edu.uci.ics.asterix.om.base.ANull;
 import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringReplaceDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringReplaceDescriptor.java
index 32af44e..3350048 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringReplaceDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringReplaceDescriptor.java
@@ -6,7 +6,6 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import edu.uci.ics.asterix.common.functions.FunctionConstants;
 import edu.uci.ics.asterix.common.utils.UTF8CharSequence;
 import edu.uci.ics.asterix.formats.nontagged.AqlBinaryComparatorFactoryProvider;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/Substring2Descriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/Substring2Descriptor.java
index 338c9a9..3d71f50 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/Substring2Descriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/Substring2Descriptor.java
@@ -21,6 +21,11 @@
 public class Substring2Descriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
+    
+    // allowed input types
+    private static final byte SER_INT32_TYPE_TAG = ATypeTag.INT32.serialize();
+    private static final byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
+    
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new Substring2Descriptor();
@@ -46,11 +51,17 @@
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
                         argOut.reset();
                         evalStart.evaluate(tuple);
+                        if(argOut.getByteArray()[0] != SER_INT32_TYPE_TAG){
+                            throw new AlgebricksException("Expects Int32 Type for the first argument of Substring.");
+                        }
                         int start = IntegerSerializerDeserializer.getInt(argOut.getByteArray(), 1) - 1;
                         argOut.reset();
                         evalString.evaluate(tuple);
 
                         byte[] bytes = argOut.getByteArray();
+                        if(bytes[0] != SER_STRING_TYPE_TAG){
+                            throw new AlgebricksException("Expects String Type for the second argument of Substring.");
+                        }
                         int utflen = UTF8StringPointable.getUTFLength(bytes, 1);
                         int sStart = 3;
                         int c = 0;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringAfterDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringAfterDescriptor.java
index 7594dd2..2d45d3c 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringAfterDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringAfterDescriptor.java
@@ -20,6 +20,11 @@
 public class SubstringAfterDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
+
+    // allowed input types
+    private static final byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
+    private static final byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new SubstringAfterDescriptor();
@@ -52,6 +57,12 @@
                         evalPattern.evaluate(tuple);
                         byte[] pattern = array1.getByteArray();
 
+                        if ((src[0] != SER_STRING_TYPE_TAG && src[0] != SER_NULL_TYPE_TAG)
+                                || (pattern[0] != SER_STRING_TYPE_TAG && pattern[0] != SER_NULL_TYPE_TAG)) {
+                            throw new AlgebricksException(
+                                    "Expects Types: (String, String) for substring-after function. ");
+                        }
+
                         int srcLen = UTF8StringPointable.getUTFLength(src, 1);
                         int patternLen = UTF8StringPointable.getUTFLength(pattern, 1);
                         int posSrc = 3;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringBeforeDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringBeforeDescriptor.java
index 2c53756..6c42ed1 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringBeforeDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringBeforeDescriptor.java
@@ -20,6 +20,11 @@
 public class SubstringBeforeDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
+
+    // allowed input types
+    private static final byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
+    private static final byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new SubstringBeforeDescriptor();
@@ -52,6 +57,12 @@
                         evalPattern.evaluate(tuple);
                         byte[] pattern = array1.getByteArray();
 
+                        if ((src[0] != SER_STRING_TYPE_TAG && src[0] != SER_NULL_TYPE_TAG)
+                                || (pattern[0] != SER_STRING_TYPE_TAG && pattern[0] != SER_NULL_TYPE_TAG)) {
+                            throw new AlgebricksException(
+                                    "Expects Types: (String, String) for substring-before function. ");
+                        }
+
                         int srcLen = UTF8StringPointable.getUTFLength(src, 1);
                         int patternLen = UTF8StringPointable.getUTFLength(pattern, 1);
                         int posSrc = 3;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringDescriptor.java
index 480f4a2..681b401 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringDescriptor.java
@@ -21,6 +21,11 @@
 public class SubstringDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
+
+    // allowed input types
+    private static final byte SER_INT32_TYPE_TAG = ATypeTag.INT32.serialize();
+    private static final byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
+
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new SubstringDescriptor();
@@ -47,14 +52,28 @@
                     public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
                         argOut.reset();
                         evalStart.evaluate(tuple);
+                        if (argOut.getByteArray()[0] != SER_INT32_TYPE_TAG) {
+                            throw new AlgebricksException(
+                                    "Expects Types (String, Int32, Int32) for substring function. ");
+                        }
                         int start = IntegerSerializerDeserializer.getInt(argOut.getByteArray(), 1) - 1;
                         argOut.reset();
                         evalLen.evaluate(tuple);
+                        if (argOut.getByteArray()[0] != SER_INT32_TYPE_TAG) {
+                            throw new AlgebricksException(
+                                    "Expects Types (String, Int32, Int32) for substring function. ");
+                        }
                         int len = IntegerSerializerDeserializer.getInt(argOut.getByteArray(), 1);
+
                         argOut.reset();
                         evalString.evaluate(tuple);
 
                         byte[] bytes = argOut.getByteArray();
+
+                        if (bytes[0] != SER_STRING_TYPE_TAG) {
+                            throw new AlgebricksException(
+                                    "Expects Types (String, Int32, Int32) for substring function. ");
+                        }
                         int utflen = UTF8StringPointable.getUTFLength(bytes, 1);
                         int sStart = 3;
                         int c = 0;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DateFromUnixTimeInDaysDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DateFromUnixTimeInDaysDescriptor.java
index 6b78a35..c69207a 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DateFromUnixTimeInDaysDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DateFromUnixTimeInDaysDescriptor.java
@@ -44,6 +44,12 @@
     private final static long serialVersionUID = 1L;
     public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
             "date-from-unix-time-in-days", 1);
+    
+    // allowed input types
+    private static final byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+    private static final byte SER_INT8_TYPE_TAG = ATypeTag.INT8.serialize();
+    private static final byte SER_INT16_TYPE_TAG = ATypeTag.INT16.serialize();
+    private static final byte SER_INT32_TYPE_TAG = ATypeTag.INT32.serialize();
 
     public final static IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
 
@@ -67,12 +73,6 @@
                     private ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
                     private ICopyEvaluator eval = args[0].createEvaluator(argOut);
 
-                    // allowed input types
-                    private byte serNullTypeTag = ATypeTag.NULL.serialize();
-                    private byte serInt8TypeTag = ATypeTag.INT8.serialize();
-                    private byte serInt16TypeTag = ATypeTag.INT16.serialize();
-                    private byte serInt32TypeTag = ATypeTag.INT32.serialize();
-
                     private AMutableDate aDate = new AMutableDate(0);
 
                     // possible returning types
@@ -88,14 +88,14 @@
                         argOut.reset();
                         eval.evaluate(tuple);
                         try {
-                            if (argOut.getByteArray()[0] == serNullTypeTag) {
+                            if (argOut.getByteArray()[0] == SER_NULL_TYPE_TAG) {
                                 nullSerde.serialize(ANull.NULL, out);
                             } else {
-                                if (argOut.getByteArray()[0] == serInt8TypeTag) {
+                                if (argOut.getByteArray()[0] == SER_INT8_TYPE_TAG) {
                                     aDate.setValue(AInt8SerializerDeserializer.getByte(argOut.getByteArray(), 1));
-                                } else if (argOut.getByteArray()[0] == serInt16TypeTag) {
+                                } else if (argOut.getByteArray()[0] == SER_INT16_TYPE_TAG) {
                                     aDate.setValue(AInt16SerializerDeserializer.getShort(argOut.getByteArray(), 1));
-                                } else if (argOut.getByteArray()[0] == serInt32TypeTag) {
+                                } else if (argOut.getByteArray()[0] == SER_INT32_TYPE_TAG) {
                                     aDate.setValue(AInt32SerializerDeserializer.getInt(argOut.getByteArray(), 1));
                                 } else {
                                     throw new AlgebricksException(