You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by bu...@apache.org on 2016/12/07 09:32:09 UTC

[2/2] asterixdb git commit: Cleanup type exceptions and error messages in the compiler.

Cleanup type exceptions and error messages in the compiler.

Change-Id: I2bdb21251e53ac552e85ba30b8105f534bf9f4f3
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1371
Reviewed-by: Till Westmann <ti...@apache.org>
Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>


Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/165121ba
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/165121ba
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/165121ba

Branch: refs/heads/master
Commit: 165121bab633f78b800ed1fe2e92170c3e9ac921
Parents: 1170755
Author: Yingyi Bu <yi...@couchbase.com>
Authored: Tue Dec 6 23:18:39 2016 -0800
Committer: Yingyi Bu <bu...@gmail.com>
Committed: Wed Dec 7 01:31:12 2016 -0800

----------------------------------------------------------------------
 .../translator/TranslationException.java        |   7 -
 .../apache/asterix/runtime/ExceptionTest.java   |   8 +-
 .../src/test/resources/runtimets/testsuite.xml  |   2 +-
 .../resources/runtimets/testsuite_sqlpp.xml     |  10 +-
 .../common/exceptions/AsterixException.java     |   3 -
 .../common/exceptions/CompilationException.java |  38 ++++++
 .../asterix/common/exceptions/ErrorCode.java    |  42 ++++--
 .../asterix/metadata/MetadataException.java     |   4 -
 asterixdb/asterix-om/pom.xml                    |   6 +
 .../asterix/om/exceptions/ExceptionUtil.java    |  65 ++++++++++
 .../exceptions/IncompatibleTypeException.java   |  40 ++++++
 .../exceptions/InvalidExpressionException.java  |  48 +++++++
 .../om/exceptions/TypeMismatchException.java    |  47 +++++++
 .../UnsupportedItemTypeException.java           |  40 ++++++
 .../om/exceptions/UnsupportedTypeException.java |  40 ++++++
 .../base/AbstractResultTypeComputer.java        |   9 +-
 .../om/typecomputer/base/TypeCastUtils.java     |   9 +-
 .../impl/AbstractStringTypeComputer.java        |   9 +-
 .../impl/BooleanFunctionTypeComputer.java       |   5 +-
 .../impl/ClosedRecordConstructorResultType.java |   6 +-
 .../impl/CollectionMemberResultType.java        |  11 +-
 .../impl/FieldAccessByIndexResultType.java      |  12 +-
 .../impl/FieldAccessByNameResultType.java       |  14 +-
 .../impl/FieldAccessNestedResultType.java       |  22 ++--
 .../impl/InjectFailureTypeComputer.java         |  42 +++---
 .../impl/MinMaxAggTypeComputer.java             |   7 +-
 .../impl/NonTaggedGetItemResultType.java        |  11 +-
 .../impl/NumericAddSubMulDivTypeComputer.java   |  35 ++---
 .../impl/NumericAggTypeComputer.java            |  13 +-
 ...NumericDoubleOutputFunctionTypeComputer.java |   7 +-
 .../NumericInt8OutputFunctionTypeComputer.java  |   7 +-
 .../impl/NumericRound2TypeComputer.java         |  11 +-
 .../impl/NumericUnaryFunctionTypeComputer.java  |   8 +-
 .../impl/RecordAddFieldsTypeComputer.java       |  10 +-
 .../impl/RecordMergeTypeComputer.java           |  63 +++++----
 .../impl/RecordPairsTypeComputer.java           |   7 +-
 .../impl/RecordRemoveFieldsTypeComputer.java    |  48 +++----
 .../ScalarVersionOfAggregateResultType.java     |   6 +-
 .../impl/StringIntToStringTypeComputer.java     |   8 +-
 .../impl/SubsetCollectionTypeComputer.java      |  25 ++--
 .../impl/SubstringTypeComputer.java             |   8 +-
 .../typecomputer/impl/SwitchCaseComputer.java   |  11 +-
 .../impl/UnaryBinaryInt64TypeComputer.java      |  11 +-
 .../impl/UnaryMinusTypeComputer.java            |   8 +-
 .../impl/UnaryStringInt64TypeComputer.java      |  11 +-
 .../asterix/om/typecomputer/ExceptionTest.java  | 129 +++++++++++++++++++
 .../om/typecomputer/TypeComputerTest.java       |   4 +
 .../records/RecordAddFieldsDescriptor.java      |   2 +-
 .../records/RecordMergeDescriptor.java          |   2 +-
 .../common/exceptions/AlgebricksException.java  |  74 ++++++++++-
 .../api/exceptions/HyracksDataException.java    |  49 ++-----
 .../hyracks/api/util/ErrorMessageUtil.java      |  67 ++++++++++
 52 files changed, 882 insertions(+), 299 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/TranslationException.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/TranslationException.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/TranslationException.java
index 93586fc..53b78bb 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/TranslationException.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/TranslationException.java
@@ -21,15 +21,8 @@ package org.apache.asterix.translator;
 import org.apache.asterix.common.exceptions.AsterixException;
 
 public class TranslationException extends AsterixException {
-    /**
-     *
-     */
     private static final long serialVersionUID = 685960054131778068L;
 
-    public TranslationException() {
-        super();
-    }
-
     public TranslationException(String msg) {
         super(msg);
     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-app/src/test/java/org/apache/asterix/runtime/ExceptionTest.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/runtime/ExceptionTest.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/runtime/ExceptionTest.java
index 6a1d6e2..95c351b 100644
--- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/runtime/ExceptionTest.java
+++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/runtime/ExceptionTest.java
@@ -71,10 +71,14 @@ public class ExceptionTest {
             try {
                 evaluator.evaluate(null, resultPointable);
             } catch (Throwable e) {
-                if (e.getMessage() == null) {
+                String msg = e.getMessage();
+                if (msg == null) {
                     continue;
                 }
-                if (e.getMessage().startsWith("ASX")) {
+                if (msg.startsWith("ASX")) {
+                    // Verifies the error code.
+                    int errorCode = Integer.parseInt(msg.substring(3, 7));
+                    Assert.assertTrue(errorCode >= 0 && errorCode < 1000);
                     continue;
                 } else {
                     // Any root-level data exceptions thrown from runtime functions should have an error code.

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
index cbf715d..67e9909 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -1760,7 +1760,7 @@
     <test-case FilePath="dml">
       <compilation-unit name="insert-with-autogenerated-pk_adm_02">
         <output-dir compare="Text">insert-with-autogenerated-pk_adm_02</output-dir>
-        <expected-error>Duplicate field id encountered</expected-error>
+        <expected-error>Duplicate field name &quot;id&quot;</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="dml">

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
index 15c856d..57be018 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -1698,7 +1698,7 @@
     <test-case FilePath="dml">
       <compilation-unit name="insert-with-autogenerated-pk_adm_02">
         <output-dir compare="Text">insert-with-autogenerated-pk_adm_02</output-dir>
-        <expected-error>Duplicate field id encountered</expected-error>
+        <expected-error>Duplicate field name &quot;id&quot;</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="dml">
@@ -2434,7 +2434,7 @@
     <test-case FilePath="global-aggregate">
       <compilation-unit name="q05_error">
         <output-dir compare="Text">q01</output-dir>
-        <expected-error>The first argument of a field access should be a RECORD, but it is [ FacebookUserType: open</expected-error>
+        <expected-error>Type mismatch: function field-access-by-name expects its 1st input parameter to be type record, but the actual input type is orderedlist</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="global-aggregate">
@@ -2525,7 +2525,7 @@
     <test-case FilePath="group-by">
       <compilation-unit name="sugar-01-negative">
         <output-dir compare="Text">core-01</output-dir>
-        <expected-error>The first argument of a field access should be a RECORD, but it is [ EmpType</expected-error>
+        <expected-error>Type mismatch: function field-access-by-name expects its 1st input parameter to be type record, but the actual input type is orderedlist</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="group-by">
@@ -3141,7 +3141,7 @@
     <test-case FilePath="misc">
       <compilation-unit name="query-ASTERIXDB-1577">
         <output-dir compare="Text">query-ASTERIXDB-1577</output-dir>
-        <expected-error>The first argument of a field access should be a RECORD, but it is</expected-error>
+        <expected-error>Type mismatch: function field-access-by-name expects its 1st input parameter to be type record, but the actual input type is orderedlist</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="misc">
@@ -5820,7 +5820,7 @@
     <test-case FilePath="subquery">
       <compilation-unit name="query-ASTERIXDB-1574">
         <output-dir compare="Text">query-ASTERIXDB-1574</output-dir>
-        <expected-error>Unnest or index access expects the input to be a collection, but it was of type</expected-error>
+        <expected-error>Type mismatch: function scan-collection expects its 1st input parameter to be type unorderedlist or orderedlist, but the actual input type is record</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="subquery">

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/AsterixException.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/AsterixException.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/AsterixException.java
index afccede..53bb969 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/AsterixException.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/AsterixException.java
@@ -23,9 +23,6 @@ import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 public class AsterixException extends AlgebricksException {
     private static final long serialVersionUID = 1L;
 
-    public AsterixException() {
-    }
-
     public AsterixException(String message) {
         super(message);
     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/CompilationException.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/CompilationException.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/CompilationException.java
new file mode 100644
index 0000000..07d5068
--- /dev/null
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/CompilationException.java
@@ -0,0 +1,38 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one
+ *  * or more contributor license agreements.  See the NOTICE file
+ *  * distributed with this work for additional information
+ *  * regarding copyright ownership.  The ASF licenses this file
+ *  * to you under the Apache License, Version 2.0 (the
+ *  * "License"); you may not use this file except in compliance
+ *  * with the License.  You may obtain a copy of the License at
+ *  *
+ *  *   http://www.apache.org/licenses/LICENSE-2.0
+ *  *
+ *  * Unless required by applicable law or agreed to in writing,
+ *  * software distributed under the License is distributed on an
+ *  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  * KIND, either express or implied.  See the License for the
+ *  * specific language governing permissions and limitations
+ *  * under the License.
+ *
+ */
+
+package org.apache.asterix.common.exceptions;
+
+import java.io.Serializable;
+
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+
+public class CompilationException extends AlgebricksException {
+
+    public CompilationException(int errorCode, Serializable... params) {
+        super(ErrorCode.ASTERIX, errorCode, ErrorCode.getErrorMessage(errorCode), params);
+    }
+
+    public CompilationException(int errorCode, Throwable cause, Serializable... params) {
+        super(ErrorCode.ASTERIX, errorCode, ErrorCode.getErrorMessage(errorCode), params);
+        addSuppressed(cause);
+    }
+}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
index b182e35..743d5fb 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
@@ -47,10 +47,17 @@ public class ErrorCode {
     public static final int ERROR_NEGATIVE_VALUE = 10;
     public static final int ERROR_OUT_OF_BOUND = 11;
     public static final int ERROR_COERCION = 12;
-    public static final int ERROR_DUPLICATE_FIELD = 13;
+    public static final int ERROR_DUPLICATE_FIELD_NAME = 13;
 
     // Compilation errors
     public static final int ERROR_PARSE_ERROR = 1001;
+    public static final int ERROR_COMPILATION_TYPE_MISMATCH = 1002;
+    public static final int ERROR_COMPILATION_TYPE_INCOMPATIBLE = 1003;
+    public static final int ERROR_COMPILATION_TYPE_UNSUPPORTED = 1004;
+    public static final int ERROR_COMPILATION_TYPE_ITEM = 1005;
+    public static final int ERROR_COMPILATION_INVALID_EXPRESSION = 1006;
+    public static final int ERROR_COMPILATION_INVALID_PARAMETER_NUMBER = 1007;
+    public static final int ERROR_COMPILATION_DUPLICATE_FIELD_NAME = 1008;
 
     private static final String ERROR_MESSAGE_ID_CONFLICT = "Two Extensions share the same Id: %1$s";
     private static final String ERROR_MESSAGE_COMPONENT_CONFLICT = "Extension Conflict between %1$s and %2$s both "
@@ -63,20 +70,24 @@ public class ErrorCode {
             + " cannot process input type %2$s";
     private static final String ERROR_MESSAGE_TYPE_ITEM = "Invalid item type: function %1$s"
             + " cannot process item type %2$s in an input array (or multiset)";
-    public static final String ERROR_MESSAGE_INVALID_FORMAT = "Invalid format for %1$s in %2$s";
-    public static final String ERROR_MESSAGE_OVERFLOW = "Overflow happend in %1$s";
-    public static final String ERROR_MESSAGE_UNDERFLOW = "Underflow happend in %1$s";
-    public static final String ERROR_MESSAGE_INJECTED_FAILURE = "Injected failure in %1$s";
-    public static final String ERROR_MESSAGE_NEGATIVE_VALUE = "Invalid value: function %1$s expects"
+    private static final String ERROR_MESSAGE_INVALID_FORMAT = "Invalid format for %1$s in %2$s";
+    private static final String ERROR_MESSAGE_OVERFLOW = "Overflow happend in %1$s";
+    private static final String ERROR_MESSAGE_UNDERFLOW = "Underflow happend in %1$s";
+    private static final String ERROR_MESSAGE_INJECTED_FAILURE = "Injected failure in %1$s";
+    private static final String ERROR_MESSAGE_NEGATIVE_VALUE = "Invalid value: function %1$s expects"
             + " its %2$s input parameter to be a non-negative value, but gets %3$s";
-    public static final String ERROR_MESSAGE_OUT_OF_BOUND = "Index out of bound in %1$s: %2$s";
-    public static final String ERROR_MESSAGE_COERCION = "Invalid implicit scalar to collection coercion in %1$s";
-    public static final String ERROR_MESSAGE_DUPLICATE_FIELD = "Get duplicate fields in %1$s";
+    private static final String ERROR_MESSAGE_OUT_OF_BOUND = "Index out of bound in %1$s: %2$s";
+    private static final String ERROR_MESSAGE_COERCION = "Invalid implicit scalar to collection coercion in %1$s";
+    private static final String ERROR_MESSAGE_DUPLICATE_FIELD = "Duplicate field name \"%1$s\"";
+    private static final String ERROR_MESSAGE_INVALID_EXPRESSION = "Invalid expression: function %1$s expects"
+            + " its %2$s input parameter to be a %3$s expression, but the actual expression is %4$s";
+    private static final String ERROR_MESSAGE_INVALID_PARAMETER_NUMBER = "Invalid parameter number: function %1$s "
+            + "cannot take %2$s parameters";
 
     private static Map<Integer, String> errorMessageMap = new HashMap<>();
 
     static {
-        // compilation errors
+        // runtime errors
         errorMessageMap.put(ERROR_TYPE_MISMATCH, ERROR_MESSAGE_TYPE_MISMATCH);
         errorMessageMap.put(ERROR_TYPE_INCOMPATIBLE, ERROR_MESSAGE_TYPE_INCOMPATIBLE);
         errorMessageMap.put(ERROR_TYPE_ITEM, ERROR_MESSAGE_TYPE_ITEM);
@@ -88,7 +99,16 @@ public class ErrorCode {
         errorMessageMap.put(ERROR_NEGATIVE_VALUE, ERROR_MESSAGE_NEGATIVE_VALUE);
         errorMessageMap.put(ERROR_OUT_OF_BOUND, ERROR_MESSAGE_OUT_OF_BOUND);
         errorMessageMap.put(ERROR_COERCION, ERROR_MESSAGE_COERCION);
-        errorMessageMap.put(ERROR_DUPLICATE_FIELD, ERROR_MESSAGE_DUPLICATE_FIELD);
+        errorMessageMap.put(ERROR_DUPLICATE_FIELD_NAME, ERROR_MESSAGE_DUPLICATE_FIELD);
+
+        // compilation errors
+        errorMessageMap.put(ERROR_COMPILATION_TYPE_MISMATCH, ERROR_MESSAGE_TYPE_MISMATCH);
+        errorMessageMap.put(ERROR_COMPILATION_TYPE_INCOMPATIBLE, ERROR_MESSAGE_TYPE_INCOMPATIBLE);
+        errorMessageMap.put(ERROR_COMPILATION_TYPE_ITEM, ERROR_MESSAGE_TYPE_ITEM);
+        errorMessageMap.put(ERROR_COMPILATION_TYPE_UNSUPPORTED, ERROR_MESSAGE_TYPE_UNSUPPORTED);
+        errorMessageMap.put(ERROR_COMPILATION_INVALID_EXPRESSION, ERROR_MESSAGE_INVALID_EXPRESSION);
+        errorMessageMap.put(ERROR_COMPILATION_INVALID_PARAMETER_NUMBER, ERROR_MESSAGE_INVALID_PARAMETER_NUMBER);
+        errorMessageMap.put(ERROR_COMPILATION_DUPLICATE_FIELD_NAME, ERROR_MESSAGE_DUPLICATE_FIELD);
 
         // lifecycle management errors
         errorMessageMap.put(ERROR_EXTENSION_ID_CONFLICT, ERROR_MESSAGE_ID_CONFLICT);

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/MetadataException.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/MetadataException.java b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/MetadataException.java
index 413226e..84c908f 100644
--- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/MetadataException.java
+++ b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/MetadataException.java
@@ -24,10 +24,6 @@ import org.apache.asterix.common.exceptions.AsterixException;
 public class MetadataException extends AsterixException {
     private static final long serialVersionUID = 1L;
 
-    public MetadataException() {
-        super();
-    }
-
     public MetadataException(String message) {
         super(message);
     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-om/pom.xml
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/pom.xml b/asterixdb/asterix-om/pom.xml
index 72bf65e..eb3310f 100644
--- a/asterixdb/asterix-om/pom.xml
+++ b/asterixdb/asterix-om/pom.xml
@@ -80,5 +80,11 @@
       <version>1.10.19</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>com.e-movimento.tinytools</groupId>
+      <artifactId>privilegedaccessor</artifactId>
+      <version>1.2.2</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 </project>

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/ExceptionUtil.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/ExceptionUtil.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/ExceptionUtil.java
new file mode 100644
index 0000000..9ecdd94
--- /dev/null
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/ExceptionUtil.java
@@ -0,0 +1,65 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one
+ *  * or more contributor license agreements.  See the NOTICE file
+ *  * distributed with this work for additional information
+ *  * regarding copyright ownership.  The ASF licenses this file
+ *  * to you under the Apache License, Version 2.0 (the
+ *  * "License"); you may not use this file except in compliance
+ *  * with the License.  You may obtain a copy of the License at
+ *  *
+ *  *   http://www.apache.org/licenses/LICENSE-2.0
+ *  *
+ *  * Unless required by applicable law or agreed to in writing,
+ *  * software distributed under the License is distributed on an
+ *  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  * KIND, either express or implied.  See the License for the
+ *  * specific language governing permissions and limitations
+ *  * under the License.
+ *
+ */
+
+package org.apache.asterix.om.exceptions;
+
+public class ExceptionUtil {
+
+    private ExceptionUtil() {
+    }
+
+    static String toExpectedTypeString(Object... expectedItems) {
+        StringBuilder expectedTypes = new StringBuilder();
+        int numCandidateTypes = expectedItems.length;
+        for (int index = 0; index < numCandidateTypes; ++index) {
+            if (index > 0) {
+                if (index == numCandidateTypes - 1) {
+                    expectedTypes.append(" or ");
+                } else {
+                    expectedTypes.append(", ");
+                }
+            }
+            expectedTypes.append(expectedItems[index]);
+        }
+        return expectedTypes.toString();
+    }
+
+    static String indexToPosition(int index) {
+        int i = index + 1;
+        switch (i % 100) {
+            case 11:
+            case 12:
+            case 13:
+                return i + "th";
+            default:
+                switch (i % 10) {
+                    case 1:
+                        return i + "st";
+                    case 2:
+                        return i + "nd";
+                    case 3:
+                        return i + "rd";
+                    default:
+                        return i + "th";
+                }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/IncompatibleTypeException.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/IncompatibleTypeException.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/IncompatibleTypeException.java
new file mode 100644
index 0000000..728cd0c
--- /dev/null
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/IncompatibleTypeException.java
@@ -0,0 +1,40 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one
+ *  * or more contributor license agreements.  See the NOTICE file
+ *  * distributed with this work for additional information
+ *  * regarding copyright ownership.  The ASF licenses this file
+ *  * to you under the Apache License, Version 2.0 (the
+ *  * "License"); you may not use this file except in compliance
+ *  * with the License.  You may obtain a copy of the License at
+ *  *
+ *  *   http://www.apache.org/licenses/LICENSE-2.0
+ *  *
+ *  * Unless required by applicable law or agreed to in writing,
+ *  * software distributed under the License is distributed on an
+ *  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  * KIND, either express or implied.  See the License for the
+ *  * specific language governing permissions and limitations
+ *  * under the License.
+ *
+ */
+
+package org.apache.asterix.om.exceptions;
+
+import org.apache.asterix.common.exceptions.CompilationException;
+import org.apache.asterix.common.exceptions.ErrorCode;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+
+public class IncompatibleTypeException extends CompilationException {
+
+    // Incompatible input parameters, e.g., "1.0" > 1.0
+    public IncompatibleTypeException(FunctionIdentifier fid, ATypeTag typeTagLeft, ATypeTag typeTagRight) {
+        super(ErrorCode.ERROR_COMPILATION_TYPE_INCOMPATIBLE, fid.getName(), typeTagLeft, typeTagRight);
+    }
+
+    // Incompatible input parameters, e.g., "1.0" > 1.0
+    public IncompatibleTypeException(String functionName, ATypeTag typeTagLeft, ATypeTag typeTagRight) {
+        super(ErrorCode.ERROR_COMPILATION_TYPE_INCOMPATIBLE, functionName, typeTagLeft, typeTagRight);
+    }
+}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/InvalidExpressionException.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/InvalidExpressionException.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/InvalidExpressionException.java
new file mode 100644
index 0000000..a4b3a32
--- /dev/null
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/InvalidExpressionException.java
@@ -0,0 +1,48 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one
+ *  * or more contributor license agreements.  See the NOTICE file
+ *  * distributed with this work for additional information
+ *  * regarding copyright ownership.  The ASF licenses this file
+ *  * to you under the Apache License, Version 2.0 (the
+ *  * "License"); you may not use this file except in compliance
+ *  * with the License.  You may obtain a copy of the License at
+ *  *
+ *  *   http://www.apache.org/licenses/LICENSE-2.0
+ *  *
+ *  * Unless required by applicable law or agreed to in writing,
+ *  * software distributed under the License is distributed on an
+ *  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  * KIND, either express or implied.  See the License for the
+ *  * specific language governing permissions and limitations
+ *  * under the License.
+ *
+ */
+
+package org.apache.asterix.om.exceptions;
+
+import static org.apache.asterix.om.exceptions.ExceptionUtil.indexToPosition;
+import static org.apache.asterix.om.exceptions.ExceptionUtil.toExpectedTypeString;
+
+import org.apache.asterix.common.exceptions.CompilationException;
+import org.apache.asterix.common.exceptions.ErrorCode;
+import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import org.apache.hyracks.algebricks.core.algebra.base.LogicalExpressionTag;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+
+public class InvalidExpressionException extends CompilationException {
+
+    public InvalidExpressionException(FunctionIdentifier fid, int index, ILogicalExpression actualExpr,
+            LogicalExpressionTag... exprKinds) {
+        super(ErrorCode.ERROR_COMPILATION_TYPE_INCOMPATIBLE, fid.getName(), indexToPosition(index),
+                actualExpr.toString(),
+                toExpectedTypeString(exprKinds));
+    }
+
+    public InvalidExpressionException(String functionName, int index, ILogicalExpression actualExpr,
+            LogicalExpressionTag... exprKinds) {
+        super(ErrorCode.ERROR_COMPILATION_TYPE_INCOMPATIBLE, functionName, indexToPosition(index),
+                actualExpr.toString(),
+                toExpectedTypeString(exprKinds));
+    }
+}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/TypeMismatchException.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/TypeMismatchException.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/TypeMismatchException.java
new file mode 100644
index 0000000..c0ab958
--- /dev/null
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/TypeMismatchException.java
@@ -0,0 +1,47 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one
+ *  * or more contributor license agreements.  See the NOTICE file
+ *  * distributed with this work for additional information
+ *  * regarding copyright ownership.  The ASF licenses this file
+ *  * to you under the Apache License, Version 2.0 (the
+ *  * "License"); you may not use this file except in compliance
+ *  * with the License.  You may obtain a copy of the License at
+ *  *
+ *  *   http://www.apache.org/licenses/LICENSE-2.0
+ *  *
+ *  * Unless required by applicable law or agreed to in writing,
+ *  * software distributed under the License is distributed on an
+ *  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  * KIND, either express or implied.  See the License for the
+ *  * specific language governing permissions and limitations
+ *  * under the License.
+ *
+ */
+
+package org.apache.asterix.om.exceptions;
+
+import static org.apache.asterix.om.exceptions.ExceptionUtil.indexToPosition;
+import static org.apache.asterix.om.exceptions.ExceptionUtil.toExpectedTypeString;
+
+import org.apache.asterix.common.exceptions.CompilationException;
+import org.apache.asterix.common.exceptions.ErrorCode;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+
+public class TypeMismatchException extends CompilationException {
+
+    // Parameter type mistmatch.
+    public TypeMismatchException(FunctionIdentifier fid, Integer i, ATypeTag actualTypeTag,
+            ATypeTag... expectedTypeTags) {
+        super(ErrorCode.ERROR_COMPILATION_TYPE_MISMATCH, fid.getName(), indexToPosition(i),
+                toExpectedTypeString(expectedTypeTags), actualTypeTag);
+    }
+
+    // Parameter type mistmatch.
+    public TypeMismatchException(String functionName, Integer i, ATypeTag actualTypeTag, ATypeTag... expectedTypeTags) {
+        super(ErrorCode.ERROR_COMPILATION_TYPE_MISMATCH, functionName, indexToPosition(i),
+                toExpectedTypeString(expectedTypeTags), actualTypeTag);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/UnsupportedItemTypeException.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/UnsupportedItemTypeException.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/UnsupportedItemTypeException.java
new file mode 100644
index 0000000..d1288aa
--- /dev/null
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/UnsupportedItemTypeException.java
@@ -0,0 +1,40 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one
+ *  * or more contributor license agreements.  See the NOTICE file
+ *  * distributed with this work for additional information
+ *  * regarding copyright ownership.  The ASF licenses this file
+ *  * to you under the Apache License, Version 2.0 (the
+ *  * "License"); you may not use this file except in compliance
+ *  * with the License.  You may obtain a copy of the License at
+ *  *
+ *  *   http://www.apache.org/licenses/LICENSE-2.0
+ *  *
+ *  * Unless required by applicable law or agreed to in writing,
+ *  * software distributed under the License is distributed on an
+ *  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  * KIND, either express or implied.  See the License for the
+ *  * specific language governing permissions and limitations
+ *  * under the License.
+ *
+ */
+
+package org.apache.asterix.om.exceptions;
+
+import org.apache.asterix.common.exceptions.CompilationException;
+import org.apache.asterix.common.exceptions.ErrorCode;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+
+public class UnsupportedItemTypeException extends CompilationException {
+
+    // Unsupported item type.
+    public UnsupportedItemTypeException(FunctionIdentifier fid, ATypeTag itemTypeTag) {
+        super(ErrorCode.ERROR_COMPILATION_TYPE_ITEM, fid.getName(), itemTypeTag);
+    }
+
+    // Unsupported item type.
+    public UnsupportedItemTypeException(String functionName, ATypeTag itemTypeTag) {
+        super(ErrorCode.ERROR_COMPILATION_TYPE_ITEM, functionName, itemTypeTag);
+    }
+}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/UnsupportedTypeException.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/UnsupportedTypeException.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/UnsupportedTypeException.java
new file mode 100644
index 0000000..42e234f
--- /dev/null
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/UnsupportedTypeException.java
@@ -0,0 +1,40 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one
+ *  * or more contributor license agreements.  See the NOTICE file
+ *  * distributed with this work for additional information
+ *  * regarding copyright ownership.  The ASF licenses this file
+ *  * to you under the Apache License, Version 2.0 (the
+ *  * "License"); you may not use this file except in compliance
+ *  * with the License.  You may obtain a copy of the License at
+ *  *
+ *  *   http://www.apache.org/licenses/LICENSE-2.0
+ *  *
+ *  * Unless required by applicable law or agreed to in writing,
+ *  * software distributed under the License is distributed on an
+ *  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  * KIND, either express or implied.  See the License for the
+ *  * specific language governing permissions and limitations
+ *  * under the License.
+ *
+ */
+
+package org.apache.asterix.om.exceptions;
+
+import org.apache.asterix.common.exceptions.CompilationException;
+import org.apache.asterix.common.exceptions.ErrorCode;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+
+public class UnsupportedTypeException extends CompilationException {
+
+    // Unsupported input type.
+    public UnsupportedTypeException(FunctionIdentifier fid, ATypeTag actualTypeTag) {
+        super(ErrorCode.ERROR_COMPILATION_TYPE_UNSUPPORTED, fid.getName(), actualTypeTag);
+    }
+
+    // Unsupported input type.
+    public UnsupportedTypeException(String funcName, ATypeTag actualTypeTag) {
+        super(ErrorCode.ERROR_COMPILATION_TYPE_UNSUPPORTED, funcName, actualTypeTag);
+    }
+}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/base/AbstractResultTypeComputer.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/base/AbstractResultTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/base/AbstractResultTypeComputer.java
index fb83091..f33db4b 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/base/AbstractResultTypeComputer.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/base/AbstractResultTypeComputer.java
@@ -22,6 +22,7 @@ import org.apache.asterix.om.typecomputer.impl.TypeComputeUtils;
 import org.apache.asterix.om.types.IAType;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
 import org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
 import org.apache.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
 
@@ -36,20 +37,24 @@ public abstract class AbstractResultTypeComputer implements IResultTypeComputer
     @Override
     public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
             IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
-        return TypeComputeUtils.resolveResultType(expression, env, (index, type) -> checkArgType(index, type),
+        AbstractFunctionCallExpression functionCallExpression = (AbstractFunctionCallExpression) expression;
+        String funcName = functionCallExpression.getFunctionIdentifier().getName();
+        return TypeComputeUtils.resolveResultType(expression, env, (index, type) -> checkArgType(funcName, index, type),
                 this::getResultType, true);
     }
 
     /**
      * Checks whether an input type violates the requirement.
      *
+     * @param funcName
+     *            the function name.
      * @param argIndex,
      *            the index of the argument to consider.
      * @param type,
      *            the type of the input argument.
      * @throws AlgebricksException
      */
-    protected void checkArgType(int argIndex, IAType type) throws AlgebricksException {
+    protected void checkArgType(String funcName, int argIndex, IAType type) throws AlgebricksException {
 
     }
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/base/TypeCastUtils.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/base/TypeCastUtils.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/base/TypeCastUtils.java
index 91990f2..8c40903 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/base/TypeCastUtils.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/base/TypeCastUtils.java
@@ -19,6 +19,7 @@
 
 package org.apache.asterix.om.typecomputer.base;
 
+import org.apache.asterix.om.exceptions.IncompatibleTypeException;
 import org.apache.asterix.om.typecomputer.impl.TypeComputeUtils;
 import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.IAType;
@@ -39,9 +40,11 @@ public class TypeCastUtils {
             opaqueParameters = new Object[2];
             opaqueParameters[0] = requiredType;
             opaqueParameters[1] = inputType;
-            if (!ATypeHierarchy.isCompatible(requiredType.getTypeTag(),
-                            TypeComputeUtils.getActualType(inputType).getTypeTag())) {
-                throw new AlgebricksException(inputType + " can't be casted to " + requiredType);
+            ATypeTag requiredTypeTag = requiredType.getTypeTag();
+            ATypeTag actualTypeTag = TypeComputeUtils.getActualType(inputType).getTypeTag();
+            if (!ATypeHierarchy.isCompatible(requiredTypeTag, actualTypeTag)) {
+                String funcName = expr.getFunctionIdentifier().getName();
+                throw new IncompatibleTypeException(funcName, actualTypeTag, requiredTypeTag);
             }
             expr.setOpaqueParameters(opaqueParameters);
             changed = true;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/AbstractStringTypeComputer.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/AbstractStringTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/AbstractStringTypeComputer.java
index ee53964..27f364a 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/AbstractStringTypeComputer.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/AbstractStringTypeComputer.java
@@ -18,6 +18,7 @@
  */
 package org.apache.asterix.om.typecomputer.impl;
 
+import org.apache.asterix.om.exceptions.TypeMismatchException;
 import org.apache.asterix.om.typecomputer.base.AbstractResultTypeComputer;
 import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.IAType;
@@ -27,10 +28,10 @@ import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
 abstract public class AbstractStringTypeComputer extends AbstractResultTypeComputer {
 
     @Override
-    protected void checkArgType(int argIndex, IAType type) throws AlgebricksException {
-        if (type.getTypeTag() != ATypeTag.STRING) {
-            throw new AlgebricksException("The input type for input argument " + argIndex + "(" + type.getDisplayName()
-                    + ")" + " is not expected.");
+    protected void checkArgType(String funcName, int argIndex, IAType type) throws AlgebricksException {
+        ATypeTag actualTypeTag = type.getTypeTag();
+        if (actualTypeTag != ATypeTag.STRING) {
+            throw new TypeMismatchException(funcName, argIndex, actualTypeTag, ATypeTag.STRING);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/BooleanFunctionTypeComputer.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/BooleanFunctionTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/BooleanFunctionTypeComputer.java
index 6364d57..80ac8ef 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/BooleanFunctionTypeComputer.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/BooleanFunctionTypeComputer.java
@@ -24,6 +24,7 @@ import org.apache.asterix.om.types.BuiltinType;
 import org.apache.asterix.om.types.IAType;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
 import org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
 import org.apache.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
 
@@ -37,8 +38,10 @@ public class BooleanFunctionTypeComputer extends AbstractResultTypeComputer {
     @Override
     public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
             IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
+        AbstractFunctionCallExpression functionCallExpression = (AbstractFunctionCallExpression) expression;
+        String funcName = functionCallExpression.getFunctionIdentifier().getName();
         // Boolean type computer doesn't follow the null/missing-in/out semantics.
-        return TypeComputeUtils.resolveResultType(expression, env, (index, type) -> checkArgType(index, type),
+        return TypeComputeUtils.resolveResultType(expression, env, (index, type) -> checkArgType(funcName, index, type),
                 this::getResultType, false);
     }
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ClosedRecordConstructorResultType.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ClosedRecordConstructorResultType.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ClosedRecordConstructorResultType.java
index e337ea8..0e351e2 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ClosedRecordConstructorResultType.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ClosedRecordConstructorResultType.java
@@ -21,6 +21,7 @@ package org.apache.asterix.om.typecomputer.impl;
 
 import java.util.Iterator;
 
+import org.apache.asterix.om.exceptions.InvalidExpressionException;
 import org.apache.asterix.om.typecomputer.base.IResultTypeComputer;
 import org.apache.asterix.om.typecomputer.base.TypeCastUtils;
 import org.apache.asterix.om.types.ARecordType;
@@ -31,6 +32,7 @@ import org.apache.asterix.om.util.ConstantExpressionUtil;
 import org.apache.commons.lang3.mutable.Mutable;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import org.apache.hyracks.algebricks.core.algebra.base.LogicalExpressionTag;
 import org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
 import org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
 import org.apache.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
@@ -43,6 +45,7 @@ public class ClosedRecordConstructorResultType implements IResultTypeComputer {
     public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
             IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
         AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expression;
+        String funcName = f.getFunctionIdentifier().getName();
 
         /**
          * if type has been top-down propagated, use the enforced type
@@ -68,8 +71,7 @@ public class ClosedRecordConstructorResultType implements IResultTypeComputer {
             fieldTypes[i] = e2Type;
             fieldNames[i] = ConstantExpressionUtil.getStringConstant(e1);
             if (fieldNames[i] == null) {
-                throw new AlgebricksException(
-                        "Field name " + i + "(" + e1 + ") in call to closed-record-constructor is not a constant.");
+                throw new InvalidExpressionException(funcName, 2 * i, e1, LogicalExpressionTag.CONSTANT);
             }
             i++;
         }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/CollectionMemberResultType.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/CollectionMemberResultType.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/CollectionMemberResultType.java
index bfeaac1..1792f68 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/CollectionMemberResultType.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/CollectionMemberResultType.java
@@ -18,6 +18,7 @@
  */
 package org.apache.asterix.om.typecomputer.impl;
 
+import org.apache.asterix.om.exceptions.TypeMismatchException;
 import org.apache.asterix.om.typecomputer.base.AbstractResultTypeComputer;
 import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.AbstractCollectionType;
@@ -27,19 +28,17 @@ import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
 
 public class CollectionMemberResultType extends AbstractResultTypeComputer {
-
     public static final CollectionMemberResultType INSTANCE = new CollectionMemberResultType();
 
     protected CollectionMemberResultType() {
-
     }
 
     @Override
-    protected void checkArgType(int argIndex, IAType type) throws AlgebricksException {
+    protected void checkArgType(String funcName, int argIndex, IAType type) throws AlgebricksException {
+        ATypeTag actualTypeTag = type.getTypeTag();
         if (type.getTypeTag() != ATypeTag.UNORDEREDLIST && type.getTypeTag() != ATypeTag.ORDEREDLIST) {
-            throw new AlgebricksException(
-                    "Unnest or index access expects the input to be a collection, but it was of type "
-                    + type);
+            throw new TypeMismatchException(funcName, argIndex, actualTypeTag, ATypeTag.UNORDEREDLIST,
+                    ATypeTag.ORDEREDLIST);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/FieldAccessByIndexResultType.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/FieldAccessByIndexResultType.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/FieldAccessByIndexResultType.java
index f46c102..0c9d538 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/FieldAccessByIndexResultType.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/FieldAccessByIndexResultType.java
@@ -18,6 +18,7 @@
  */
 package org.apache.asterix.om.typecomputer.impl;
 
+import org.apache.asterix.om.exceptions.TypeMismatchException;
 import org.apache.asterix.om.typecomputer.base.AbstractResultTypeComputer;
 import org.apache.asterix.om.types.ARecordType;
 import org.apache.asterix.om.types.ATypeTag;
@@ -36,12 +37,13 @@ public class FieldAccessByIndexResultType extends AbstractResultTypeComputer {
     }
 
     @Override
-    protected void checkArgType(int argIndex, IAType type) throws AlgebricksException {
-        if (argIndex == 0 && type.getTypeTag() != ATypeTag.RECORD) {
-            throw new AlgebricksException("The first argument should be a RECORD, but it is " + type + ".");
+    protected void checkArgType(String funcName, int argIndex, IAType type) throws AlgebricksException {
+        ATypeTag actualTypeTag = type.getTypeTag();
+        if (argIndex == 0 && actualTypeTag != ATypeTag.RECORD) {
+            throw new TypeMismatchException(funcName, argIndex, actualTypeTag, ATypeTag.RECORD);
         }
-        if (argIndex == 1 && type.getTypeTag() != ATypeTag.INT32) {
-            throw new AlgebricksException("The second argument should be an INT32, but it is found " + type + ".");
+        if (argIndex == 1 && actualTypeTag != ATypeTag.INT32) {
+            throw new TypeMismatchException(funcName, argIndex, actualTypeTag, ATypeTag.INT32);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/FieldAccessByNameResultType.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/FieldAccessByNameResultType.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/FieldAccessByNameResultType.java
index 3e5af3c..deb667c 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/FieldAccessByNameResultType.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/FieldAccessByNameResultType.java
@@ -18,6 +18,7 @@
  */
 package org.apache.asterix.om.typecomputer.impl;
 
+import org.apache.asterix.om.exceptions.TypeMismatchException;
 import org.apache.asterix.om.typecomputer.base.AbstractResultTypeComputer;
 import org.apache.asterix.om.types.ARecordType;
 import org.apache.asterix.om.types.ATypeTag;
@@ -36,14 +37,13 @@ public class FieldAccessByNameResultType extends AbstractResultTypeComputer {
     }
 
     @Override
-    protected void checkArgType(int argIndex, IAType type) throws AlgebricksException {
-        if (argIndex == 0 && type.getTypeTag() != ATypeTag.RECORD) {
-            throw new AlgebricksException("The first argument of a field access should be a RECORD, but it is " + type
-                    + ".");
+    protected void checkArgType(String funcName, int argIndex, IAType type) throws AlgebricksException {
+        ATypeTag actualTypeTag = type.getTypeTag();
+        if (argIndex == 0 && actualTypeTag != ATypeTag.RECORD) {
+            throw new TypeMismatchException(funcName, argIndex, actualTypeTag, ATypeTag.RECORD);
         }
-        if (argIndex == 1 && type.getTypeTag() != ATypeTag.STRING) {
-            throw new AlgebricksException("The second argument of a field access should be an STRING, but it is "
-                    + type + ".");
+        if (argIndex == 1 && actualTypeTag != ATypeTag.STRING) {
+            throw new TypeMismatchException(funcName, argIndex, actualTypeTag, ATypeTag.STRING);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/FieldAccessNestedResultType.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/FieldAccessNestedResultType.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/FieldAccessNestedResultType.java
index 5f5abd1..03a6dc7 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/FieldAccessNestedResultType.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/FieldAccessNestedResultType.java
@@ -25,6 +25,8 @@ import org.apache.asterix.om.base.AOrderedList;
 import org.apache.asterix.om.base.AString;
 import org.apache.asterix.om.base.IAObject;
 import org.apache.asterix.om.constants.AsterixConstantValue;
+import org.apache.asterix.om.exceptions.TypeMismatchException;
+import org.apache.asterix.om.exceptions.UnsupportedItemTypeException;
 import org.apache.asterix.om.typecomputer.base.AbstractResultTypeComputer;
 import org.apache.asterix.om.types.AOrderedListType;
 import org.apache.asterix.om.types.ARecordType;
@@ -44,30 +46,30 @@ public class FieldAccessNestedResultType extends AbstractResultTypeComputer {
     }
 
     @Override
-    protected void checkArgType(int argIndex, IAType type) throws AlgebricksException {
-        if (argIndex == 0 && type.getTypeTag() != ATypeTag.RECORD) {
-            throw new AlgebricksException("The first argument should be a RECORD, but it is " + type + ".");
+    protected void checkArgType(String funcName, int argIndex, IAType type) throws AlgebricksException {
+        ATypeTag actualTypeTag = type.getTypeTag();
+        if (argIndex == 0 && actualTypeTag != ATypeTag.RECORD) {
+            throw new TypeMismatchException(funcName, argIndex, actualTypeTag, ATypeTag.RECORD);
         }
         if (argIndex == 1) {
-            switch (type.getTypeTag()) {
+            switch (actualTypeTag) {
                 case STRING:
                     break;
                 case ORDEREDLIST:
-                    checkOrderedList(type);
+                    checkOrderedList(funcName, type);
                     break;
                 default:
-                    throw new AlgebricksException(
-                            "The second argument should be STRING or ORDEREDLIST, but it is found " + type + ".");
+                    throw new TypeMismatchException(funcName, argIndex, actualTypeTag, ATypeTag.STRING,
+                            ATypeTag.ORDEREDLIST);
             }
         }
     }
 
-    private void checkOrderedList(IAType type) throws AlgebricksException {
+    private void checkOrderedList(String funcName, IAType type) throws AlgebricksException {
         AOrderedListType listType = (AOrderedListType) type;
         ATypeTag itemTypeTag = listType.getItemType().getTypeTag();
         if (itemTypeTag != ATypeTag.STRING && itemTypeTag != ATypeTag.ANY) {
-            throw new AlgebricksException(
-                    "The second argument should be a valid path, but it is found " + type + ".");
+            throw new UnsupportedItemTypeException(funcName, itemTypeTag);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/InjectFailureTypeComputer.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/InjectFailureTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/InjectFailureTypeComputer.java
index 5d14716..df050be 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/InjectFailureTypeComputer.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/InjectFailureTypeComputer.java
@@ -18,40 +18,32 @@
  */
 package org.apache.asterix.om.typecomputer.impl;
 
-import org.apache.asterix.om.typecomputer.base.IResultTypeComputer;
+import org.apache.asterix.om.exceptions.TypeMismatchException;
+import org.apache.asterix.om.typecomputer.base.AbstractResultTypeComputer;
 import org.apache.asterix.om.types.ATypeTag;
-import org.apache.asterix.om.types.AUnionType;
+import org.apache.asterix.om.types.BuiltinType;
 import org.apache.asterix.om.types.IAType;
-import org.apache.asterix.om.util.NonTaggedFormatUtil;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
-import org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
-import org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
-import org.apache.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
 
-public class InjectFailureTypeComputer implements IResultTypeComputer {
+public class InjectFailureTypeComputer extends AbstractResultTypeComputer {
 
-    private static final String errMsg1 = "inject-failure should have at least 2 parameters ";
-    private static final String errMsg2 = "failure condition expression should have the return type Boolean";
+    public static final InjectFailureTypeComputer INSTANCE = new InjectFailureTypeComputer();
 
-    public static IResultTypeComputer INSTANCE = new InjectFailureTypeComputer();
+    protected InjectFailureTypeComputer() {
+    }
 
     @Override
-    public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
-            IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
-        AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expression;
-        if (fce.getArguments().size() < 2)
-            throw new AlgebricksException(errMsg1);
-
-        IAType t0 = (IAType) env.getType(fce.getArguments().get(0).getValue());
-        IAType t1 = (IAType) env.getType(fce.getArguments().get(0).getValue());
-        ATypeTag tag1 = t1.getTypeTag();
-        if (NonTaggedFormatUtil.isOptional(t1))
-            tag1 = ((AUnionType) t1).getActualType().getTypeTag();
-
-        if (tag1 != ATypeTag.BOOLEAN)
-            throw new AlgebricksException(errMsg2);
+    protected void checkArgType(String funcName, int argIndex, IAType type) throws AlgebricksException {
+        ATypeTag actualTypeTag = type.getTypeTag();
+        if (actualTypeTag != ATypeTag.BOOLEAN) {
+            throw new TypeMismatchException(funcName, argIndex, actualTypeTag, ATypeTag.BOOLEAN);
+        }
+    }
 
-        return t0;
+    @Override
+    protected IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes) throws AlgebricksException {
+        return BuiltinType.ABOOLEAN;
     }
+
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/MinMaxAggTypeComputer.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/MinMaxAggTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/MinMaxAggTypeComputer.java
index 90613b6..0c0c2f9 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/MinMaxAggTypeComputer.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/MinMaxAggTypeComputer.java
@@ -18,16 +18,15 @@
  */
 package org.apache.asterix.om.typecomputer.impl;
 
+import org.apache.asterix.om.exceptions.UnsupportedTypeException;
 import org.apache.asterix.om.typecomputer.base.AbstractResultTypeComputer;
 import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.AUnionType;
 import org.apache.asterix.om.types.IAType;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
-import org.apache.hyracks.algebricks.common.exceptions.NotImplementedException;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
 
 public class MinMaxAggTypeComputer extends AbstractResultTypeComputer {
-    private static final String ERR_MSG = "Aggregator is not implemented for ";
 
     public static final MinMaxAggTypeComputer INSTANCE = new MinMaxAggTypeComputer();
 
@@ -35,7 +34,7 @@ public class MinMaxAggTypeComputer extends AbstractResultTypeComputer {
     }
 
     @Override
-    protected void checkArgType(int argIndex, IAType type) throws AlgebricksException {
+    protected void checkArgType(String funcName, int argIndex, IAType type) throws AlgebricksException {
         ATypeTag tag = type.getTypeTag();
         switch (tag) {
             case DOUBLE:
@@ -53,7 +52,7 @@ public class MinMaxAggTypeComputer extends AbstractResultTypeComputer {
             case ANY:
                 return;
             default:
-                throw new NotImplementedException(ERR_MSG + tag);
+                throw new UnsupportedTypeException(funcName, tag);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NonTaggedGetItemResultType.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NonTaggedGetItemResultType.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NonTaggedGetItemResultType.java
index c72d7c8..677507e 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NonTaggedGetItemResultType.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NonTaggedGetItemResultType.java
@@ -18,6 +18,7 @@
  */
 package org.apache.asterix.om.typecomputer.impl;
 
+import org.apache.asterix.om.exceptions.TypeMismatchException;
 import org.apache.asterix.om.typecomputer.base.AbstractResultTypeComputer;
 import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.AUnionType;
@@ -36,16 +37,16 @@ public class NonTaggedGetItemResultType extends AbstractResultTypeComputer {
     }
 
     @Override
-    protected void checkArgType(int argIndex, IAType type) throws AlgebricksException {
+    protected void checkArgType(String funcName, int argIndex, IAType type) throws AlgebricksException {
+        ATypeTag actualTypeTag = type.getTypeTag();
         if (argIndex == 0) {
             if (type.getTypeTag() != ATypeTag.UNORDEREDLIST && type.getTypeTag() != ATypeTag.ORDEREDLIST) {
-                throw new AlgebricksException("The input type for input argument " + argIndex + "("
-                        + type.getDisplayName() + ")" + " is not expected.");
+                throw new TypeMismatchException(funcName, argIndex, actualTypeTag, ATypeTag.STRING,
+                        ATypeTag.ORDEREDLIST);
             }
         } else {
             if (!ATypeHierarchy.isCompatible(type.getTypeTag(), ATypeTag.INT32)) {
-                throw new AlgebricksException("The input type for input argument " + argIndex + "("
-                        + type.getDisplayName() + ")" + " is not expected.");
+                throw new TypeMismatchException(funcName, argIndex, actualTypeTag, ATypeTag.INT32);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericAddSubMulDivTypeComputer.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericAddSubMulDivTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericAddSubMulDivTypeComputer.java
index cabffe5..d4812c0 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericAddSubMulDivTypeComputer.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericAddSubMulDivTypeComputer.java
@@ -18,18 +18,17 @@
  */
 package org.apache.asterix.om.typecomputer.impl;
 
+import org.apache.asterix.om.exceptions.IncompatibleTypeException;
 import org.apache.asterix.om.typecomputer.base.AbstractResultTypeComputer;
 import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.BuiltinType;
 import org.apache.asterix.om.types.IAType;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
-import org.apache.hyracks.algebricks.common.exceptions.NotImplementedException;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
 
 public class NumericAddSubMulDivTypeComputer extends AbstractResultTypeComputer {
 
-    private static final String ERR_MSG = "Arithmetic operations are not implemented for ";
-
     public static final NumericAddSubMulDivTypeComputer INSTANCE = new NumericAddSubMulDivTypeComputer();
 
     private NumericAddSubMulDivTypeComputer() {
@@ -37,6 +36,8 @@ public class NumericAddSubMulDivTypeComputer extends AbstractResultTypeComputer
 
     @Override
     protected IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes) throws AlgebricksException {
+        AbstractFunctionCallExpression functionCallExpression = (AbstractFunctionCallExpression) expr;
+        String funcName = functionCallExpression.getFunctionIdentifier().getName();
         IAType t1 = strippedInputTypes[0];
         IAType t2 = strippedInputTypes[1];
         ATypeTag tag1 = t1.getTypeTag();
@@ -58,7 +59,7 @@ public class NumericAddSubMulDivTypeComputer extends AbstractResultTypeComputer
                         type = BuiltinType.ANY;
                         break;
                     default:
-                        throw new NotImplementedException(ERR_MSG + t2.getTypeName());
+                        throw new IncompatibleTypeException(funcName, tag1, tag2);
                 }
                 break;
             case FLOAT:
@@ -77,7 +78,7 @@ public class NumericAddSubMulDivTypeComputer extends AbstractResultTypeComputer
                         type = BuiltinType.ANY;
                         break;
                     default:
-                        throw new NotImplementedException(ERR_MSG + t2.getTypeName());
+                        throw new IncompatibleTypeException(funcName, tag1, tag2);
                 }
                 break;
             case INT64:
@@ -98,7 +99,7 @@ public class NumericAddSubMulDivTypeComputer extends AbstractResultTypeComputer
                         type = BuiltinType.ANY;
                         break;
                     default:
-                        throw new NotImplementedException(ERR_MSG + t2.getTypeName());
+                        throw new IncompatibleTypeException(funcName, tag1, tag2);
                 }
                 break;
             case INT32:
@@ -121,7 +122,7 @@ public class NumericAddSubMulDivTypeComputer extends AbstractResultTypeComputer
                         type = BuiltinType.ANY;
                         break;
                     default:
-                        throw new NotImplementedException(ERR_MSG + tag2);
+                        throw new IncompatibleTypeException(funcName, tag1, tag2);
                 }
                 break;
             case INT16:
@@ -146,7 +147,7 @@ public class NumericAddSubMulDivTypeComputer extends AbstractResultTypeComputer
                         type = BuiltinType.ANY;
                         break;
                     default:
-                        throw new NotImplementedException(ERR_MSG + tag2);
+                        throw new IncompatibleTypeException(funcName, tag1, tag2);
                 }
                 break;
             case INT8:
@@ -173,7 +174,7 @@ public class NumericAddSubMulDivTypeComputer extends AbstractResultTypeComputer
                         type = BuiltinType.ANY;
                         break;
                     default:
-                        throw new NotImplementedException(ERR_MSG + tag2);
+                        throw new IncompatibleTypeException(funcName, tag1, tag2);
                 }
                 break;
             case ANY:
@@ -188,7 +189,7 @@ public class NumericAddSubMulDivTypeComputer extends AbstractResultTypeComputer
                         type = BuiltinType.ANY;
                         break;
                     default:
-                        throw new NotImplementedException(ERR_MSG + tag2);
+                        throw new IncompatibleTypeException(funcName, tag1, tag2);
                 }
                 break;
             case DATE:
@@ -205,7 +206,7 @@ public class NumericAddSubMulDivTypeComputer extends AbstractResultTypeComputer
                         type = BuiltinType.ANY;
                         break;
                     default:
-                        throw new NotImplementedException(ERR_MSG + tag2);
+                        throw new IncompatibleTypeException(funcName, tag1, tag2);
                 }
                 break;
             case TIME:
@@ -222,7 +223,7 @@ public class NumericAddSubMulDivTypeComputer extends AbstractResultTypeComputer
                         type = BuiltinType.ANY;
                         break;
                     default:
-                        throw new NotImplementedException(ERR_MSG + tag2);
+                        throw new IncompatibleTypeException(funcName, tag1, tag2);
                 }
                 break;
             case DATETIME:
@@ -236,7 +237,7 @@ public class NumericAddSubMulDivTypeComputer extends AbstractResultTypeComputer
                         type = BuiltinType.ADATETIME;
                         break;
                     default:
-                        throw new NotImplementedException(ERR_MSG + tag2);
+                        throw new IncompatibleTypeException(funcName, tag1, tag2);
                 }
                 break;
             case DURATION:
@@ -254,7 +255,7 @@ public class NumericAddSubMulDivTypeComputer extends AbstractResultTypeComputer
                         type = BuiltinType.ANY;
                         break;
                     default:
-                        throw new NotImplementedException(ERR_MSG + tag2);
+                        throw new IncompatibleTypeException(funcName, tag1, tag2);
                 }
                 break;
             case YEARMONTHDURATION:
@@ -275,7 +276,7 @@ public class NumericAddSubMulDivTypeComputer extends AbstractResultTypeComputer
                         type = BuiltinType.ANY;
                         break;
                     default:
-                        throw new NotImplementedException(ERR_MSG + tag2);
+                        throw new IncompatibleTypeException(funcName, tag1, tag2);
                 }
                 break;
             case DAYTIMEDURATION:
@@ -296,11 +297,11 @@ public class NumericAddSubMulDivTypeComputer extends AbstractResultTypeComputer
                         type = BuiltinType.ANY;
                         break;
                     default:
-                        throw new NotImplementedException(ERR_MSG + tag2);
+                        throw new IncompatibleTypeException(funcName, tag1, tag2);
                 }
                 break;
             default:
-                throw new NotImplementedException(ERR_MSG + tag1);
+                throw new IncompatibleTypeException(funcName, tag1, tag2);
         }
         return type;
     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericAggTypeComputer.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericAggTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericAggTypeComputer.java
index 81df5a1..57b11b4 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericAggTypeComputer.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericAggTypeComputer.java
@@ -18,25 +18,22 @@
  */
 package org.apache.asterix.om.typecomputer.impl;
 
+import org.apache.asterix.om.exceptions.UnsupportedTypeException;
 import org.apache.asterix.om.typecomputer.base.AbstractResultTypeComputer;
 import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.AUnionType;
 import org.apache.asterix.om.types.IAType;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
-import org.apache.hyracks.algebricks.common.exceptions.NotImplementedException;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
 
 public class NumericAggTypeComputer extends AbstractResultTypeComputer {
-
-    private static final String ERR_MSG = "Aggregator is not implemented for ";
-
     public static final NumericAggTypeComputer INSTANCE = new NumericAggTypeComputer();
 
     private NumericAggTypeComputer() {
     }
 
     @Override
-    protected void checkArgType(int argIndex, IAType type) throws AlgebricksException {
+    protected void checkArgType(String funcName, int argIndex, IAType type) throws AlgebricksException {
         ATypeTag tag = type.getTypeTag();
         switch (tag) {
             case DOUBLE:
@@ -48,14 +45,14 @@ public class NumericAggTypeComputer extends AbstractResultTypeComputer {
             case ANY:
                 break;
             default:
-                throw new NotImplementedException(ERR_MSG + type);
+                throw new UnsupportedTypeException(funcName, tag);
         }
     }
 
     @Override
     protected IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes) throws AlgebricksException {
         ATypeTag tag = strippedInputTypes[0].getTypeTag();
-        IAType type;
+        IAType type = null;
         switch (tag) {
             case DOUBLE:
             case FLOAT:
@@ -67,7 +64,7 @@ public class NumericAggTypeComputer extends AbstractResultTypeComputer {
                 type = strippedInputTypes[0];
                 break;
             default:
-                throw new NotImplementedException(ERR_MSG + strippedInputTypes[0]);
+                break;
         }
         return AUnionType.createNullableType(type, "AggResult");
     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericDoubleOutputFunctionTypeComputer.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericDoubleOutputFunctionTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericDoubleOutputFunctionTypeComputer.java
index 910db02..5045187 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericDoubleOutputFunctionTypeComputer.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericDoubleOutputFunctionTypeComputer.java
@@ -19,6 +19,7 @@
 
 package org.apache.asterix.om.typecomputer.impl;
 
+import org.apache.asterix.om.exceptions.TypeMismatchException;
 import org.apache.asterix.om.typecomputer.base.AbstractResultTypeComputer;
 import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.BuiltinType;
@@ -28,7 +29,6 @@ import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
 
 public class NumericDoubleOutputFunctionTypeComputer extends AbstractResultTypeComputer {
 
-    private static final String ERR_MSG = "Arithmetic operations are not implemented for ";
     public static final NumericDoubleOutputFunctionTypeComputer INSTANCE =
             new NumericDoubleOutputFunctionTypeComputer();
 
@@ -36,7 +36,7 @@ public class NumericDoubleOutputFunctionTypeComputer extends AbstractResultTypeC
     }
 
     @Override
-    protected void checkArgType(int argIndex, IAType type) throws AlgebricksException {
+    protected void checkArgType(String funcName, int argIndex, IAType type) throws AlgebricksException {
         ATypeTag tag = type.getTypeTag();
         switch (tag) {
             case INT8:
@@ -47,7 +47,8 @@ public class NumericDoubleOutputFunctionTypeComputer extends AbstractResultTypeC
             case DOUBLE:
                 break;
             default:
-                throw new AlgebricksException(ERR_MSG + type.getDisplayName());
+                throw new TypeMismatchException(funcName, argIndex, tag, ATypeTag.INT8, ATypeTag.INT16, ATypeTag.INT32,
+                        ATypeTag.INT64, ATypeTag.FLOAT, ATypeTag.DOUBLE);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericInt8OutputFunctionTypeComputer.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericInt8OutputFunctionTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericInt8OutputFunctionTypeComputer.java
index 6e32fe0..25ead33 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericInt8OutputFunctionTypeComputer.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericInt8OutputFunctionTypeComputer.java
@@ -19,6 +19,7 @@
 
 package org.apache.asterix.om.typecomputer.impl;
 
+import org.apache.asterix.om.exceptions.TypeMismatchException;
 import org.apache.asterix.om.typecomputer.base.AbstractResultTypeComputer;
 import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.BuiltinType;
@@ -28,14 +29,13 @@ import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
 
 public class NumericInt8OutputFunctionTypeComputer extends AbstractResultTypeComputer {
 
-    private static final String ERR_MSG = "Arithmetic operations are not implemented for ";
     public static final NumericInt8OutputFunctionTypeComputer INSTANCE = new NumericInt8OutputFunctionTypeComputer();
 
     private NumericInt8OutputFunctionTypeComputer() {
     }
 
     @Override
-    protected void checkArgType(int argIndex, IAType type) throws AlgebricksException {
+    protected void checkArgType(String funcName, int argIndex, IAType type) throws AlgebricksException {
         ATypeTag tag = type.getTypeTag();
         switch (tag) {
             case INT8:
@@ -46,7 +46,8 @@ public class NumericInt8OutputFunctionTypeComputer extends AbstractResultTypeCom
             case DOUBLE:
                 break;
             default:
-                throw new AlgebricksException(ERR_MSG + type.getDisplayName());
+                throw new TypeMismatchException(funcName, argIndex, tag, ATypeTag.INT8, ATypeTag.INT16, ATypeTag.INT32,
+                        ATypeTag.INT64, ATypeTag.FLOAT, ATypeTag.DOUBLE);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericRound2TypeComputer.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericRound2TypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericRound2TypeComputer.java
index 2335e46..aa509e7 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericRound2TypeComputer.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericRound2TypeComputer.java
@@ -23,11 +23,11 @@
  */
 package org.apache.asterix.om.typecomputer.impl;
 
+import org.apache.asterix.om.exceptions.TypeMismatchException;
 import org.apache.asterix.om.typecomputer.base.AbstractResultTypeComputer;
 import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.IAType;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
-import org.apache.hyracks.algebricks.common.exceptions.NotImplementedException;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
 
 public class NumericRound2TypeComputer extends AbstractResultTypeComputer {
@@ -39,7 +39,7 @@ public class NumericRound2TypeComputer extends AbstractResultTypeComputer {
     }
 
     @Override
-    protected void checkArgType(int argIndex, IAType type) throws AlgebricksException {
+    protected void checkArgType(String funcName, int argIndex, IAType type) throws AlgebricksException {
         ATypeTag tag = type.getTypeTag();
         if (argIndex == 0) {
             switch (tag) {
@@ -51,8 +51,8 @@ public class NumericRound2TypeComputer extends AbstractResultTypeComputer {
                 case DOUBLE:
                     break;
                 default:
-                    throw new NotImplementedException(
-                            "Arithmetic operations are not implemented for " + type.getDisplayName());
+                    throw new TypeMismatchException(funcName, argIndex, tag, ATypeTag.INT8, ATypeTag.INT16,
+                            ATypeTag.INT32, ATypeTag.INT64, ATypeTag.FLOAT, ATypeTag.DOUBLE);
             }
         }
         if (argIndex == 1) {
@@ -63,7 +63,8 @@ public class NumericRound2TypeComputer extends AbstractResultTypeComputer {
                 case INT64:
                     break;
                 default:
-                    throw new AlgebricksException("Argument $precision cannot be type " + type.getDisplayName());
+                    throw new TypeMismatchException(funcName, argIndex, tag, ATypeTag.INT8, ATypeTag.INT16,
+                            ATypeTag.INT32, ATypeTag.INT64);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/165121ba/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericUnaryFunctionTypeComputer.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericUnaryFunctionTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericUnaryFunctionTypeComputer.java
index 25807ba..bc68e10 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericUnaryFunctionTypeComputer.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/NumericUnaryFunctionTypeComputer.java
@@ -23,6 +23,7 @@
  */
 package org.apache.asterix.om.typecomputer.impl;
 
+import org.apache.asterix.om.exceptions.TypeMismatchException;
 import org.apache.asterix.om.typecomputer.base.AbstractResultTypeComputer;
 import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.IAType;
@@ -30,15 +31,13 @@ import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
 
 public class NumericUnaryFunctionTypeComputer extends AbstractResultTypeComputer {
-
-    private static final String ERR_MSG = "Arithmetic operations are not implemented for ";
     public static final NumericUnaryFunctionTypeComputer INSTANCE = new NumericUnaryFunctionTypeComputer();
 
     private NumericUnaryFunctionTypeComputer() {
     }
 
     @Override
-    protected void checkArgType(int argIndex, IAType type) throws AlgebricksException {
+    protected void checkArgType(String funcName, int argIndex, IAType type) throws AlgebricksException {
         ATypeTag tag = type.getTypeTag();
         switch (tag) {
             case INT8:
@@ -50,7 +49,8 @@ public class NumericUnaryFunctionTypeComputer extends AbstractResultTypeComputer
             case ANY:
                 break;
             default:
-                throw new AlgebricksException(ERR_MSG + type.getDisplayName());
+                throw new TypeMismatchException(funcName, argIndex, tag, ATypeTag.INT8, ATypeTag.INT16, ATypeTag.INT32,
+                        ATypeTag.INT64, ATypeTag.FLOAT, ATypeTag.DOUBLE);
         }
     }