Unify runtime type exceptions by using error code and message template.

-- fixed string_join to be able to handle self-described list;
-- fixed the input arity of day_of_week;
-- added tests for exceptions.

RuntimeDataException is a newly added super class for errors in the data in the runtime.
It has the following subclasses:
-- IncompatibleTypeException, e.g., 1 + "2"
-- InvalidDataFormatException, e.g., boolean(1)
-- OverflowException, e.g., int8(1024)
-- TypeMismatchException, e.g., substr(1, 2)
-- UnderflowException, e.g., int8(-1024)
-- UnsupportedItemTypeException, e.g., string_concat(["a", 1, "c"])
-- UnsupportedTypeException, e.g., rectangle("1,2 3,4") + rectangle("2,5 7,8")

All "root-cause" exceptions thrown from runtime functions have an error code.
Going forward, all "root-cause" exceptions thrown from asterixdb
should have an error code.

Change-Id: Ie4fff8f5e64ffb027910a4899c0246b37ed5bce7
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1313
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: abdullah alamoudi <bamousaa@gmail.com>
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
new file mode 100644
index 0000000..6a1d6e2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/runtime/ExceptionTest.java
@@ -0,0 +1,115 @@
+
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.asterix.runtime;
+
+import static org.mockito.Mockito.mock;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import org.apache.asterix.translator.util.FunctionCollection;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.algebricks.runtime.evaluators.ConstantEvalFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.data.std.api.IPointable;
+import org.apache.hyracks.data.std.primitive.VoidPointable;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ExceptionTest {
+
+    @Test
+    public void test() throws Exception {
+        List<IFunctionDescriptorFactory> functions = FunctionCollection.getFunctionDescriptorFactories();
+        int testedFunctions = 0;
+        for (IFunctionDescriptorFactory func : functions) {
+            String className = func.getClass().getName();
+            // We test all generated functions except
+            // record and cast functions, which requires type settings.
+            if (className.contains("Gen") && !className.contains("record") && !className.contains("Cast")) {
+                testFunction(func);
+                ++testedFunctions;
+            }
+        }
+        // 208 is the current number of functions with generated code.
+        Assert.assertTrue(testedFunctions >= 208);
+    }
+
+    private void testFunction(IFunctionDescriptorFactory funcFactory) throws Exception {
+        AbstractScalarFunctionDynamicDescriptor funcDesc = (AbstractScalarFunctionDynamicDescriptor) funcFactory
+                .createFunctionDescriptor();
+        int inputArity = funcDesc.getIdentifier().getArity();
+        Iterator<IScalarEvaluatorFactory[]> argEvalFactoryIterator = getArgCombinations(inputArity);
+        while (argEvalFactoryIterator.hasNext()) {
+            IScalarEvaluatorFactory evalFactory = funcDesc.createEvaluatorFactory(argEvalFactoryIterator.next());
+            IHyracksTaskContext ctx = mock(IHyracksTaskContext.class);
+            IScalarEvaluator evaluator = evalFactory.createScalarEvaluator(ctx);
+            IPointable resultPointable = new VoidPointable();
+            try {
+                evaluator.evaluate(null, resultPointable);
+            } catch (Throwable e) {
+                if (e.getMessage() == null) {
+                    continue;
+                }
+                if (e.getMessage().startsWith("ASX")) {
+                    continue;
+                } else {
+                    // Any root-level data exceptions thrown from runtime functions should have an error code.
+                    Assert.assertTrue(!(e instanceof HyracksDataException) || (e.getCause() != null));
+                }
+            }
+        }
+    }
+
+    private Iterator<IScalarEvaluatorFactory[]> getArgCombinations(final int inputArity) {
+        final int argSize = inputArity >= 0 ? inputArity : 3;
+        final int numCombinations = (int) Math.pow(ATypeTag.values().length, argSize);
+        return new Iterator<IScalarEvaluatorFactory[]>() {
+            private int index = 0;
+
+            @Override
+            public boolean hasNext() {
+                return index < numCombinations;
+            }
+
+            @Override
+            public IScalarEvaluatorFactory[] next() {
+                IScalarEvaluatorFactory[] scalarEvaluatorFactories = new IScalarEvaluatorFactory[argSize];
+                for (int j = 0; j < argSize; ++j) {
+                    int base = (int) Math.pow(ATypeTag.values().length, j);
+                    // Enumerates through all possible type tags.
+                    byte serializedTypeTag = (byte) ((index / base) % ATypeTag.values().length);
+                    scalarEvaluatorFactories[j] = new ConstantEvalFactory(new byte[] { serializedTypeTag });
+                }
+                ++index;
+                return scalarEvaluatorFactories;
+            }
+
+        };
+
+    }
+
+}
diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/runtime/NullMissingTest.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/runtime/NullMissingTest.java
index d30ffd9..7827297 100644
--- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/runtime/NullMissingTest.java
+++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/runtime/NullMissingTest.java
@@ -25,6 +25,7 @@
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
 import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
@@ -43,19 +44,26 @@
     @Test
     public void test() throws Exception {
         List<IFunctionDescriptorFactory> functions = FunctionCollection.getFunctionDescriptorFactories();
+        int testedFunctions = 0;
         for (IFunctionDescriptorFactory func : functions) {
             String className = func.getClass().getName();
             // We test all generated functions except
-            // record functions, which requires type settings (we test them in runtime tests);
-            if (className.contains("generated") && !className.contains("record") && !className.contains("Cast")) {
+            // record and cast functions, which requires type settings (we test them in runtime tests).
+            if (className.contains("Gen") && !className.contains("record") && !className.contains("Cast")) {
                 testFunction(func);
+                ++testedFunctions;
             }
         }
+        // 208 is the current number of functions with generated code.
+        Assert.assertTrue(testedFunctions >= 208);
     }
 
     private void testFunction(IFunctionDescriptorFactory funcFactory) throws Exception {
-        AbstractScalarFunctionDynamicDescriptor funcDesc =
-                (AbstractScalarFunctionDynamicDescriptor) funcFactory.createFunctionDescriptor();
+        IFunctionDescriptor functionDescriptor = funcFactory.createFunctionDescriptor();
+        if (!(functionDescriptor instanceof AbstractScalarFunctionDynamicDescriptor)) {
+            return;
+        }
+        AbstractScalarFunctionDynamicDescriptor funcDesc = (AbstractScalarFunctionDynamicDescriptor) functionDescriptor;
         int inputArity = funcDesc.getIdentifier().getArity();
         Iterator<IScalarEvaluatorFactory[]> argEvalFactoryIterator = getArgCombinations(inputArity);
         int index = 0;
@@ -76,7 +84,8 @@
         }
     }
 
-    private Iterator<IScalarEvaluatorFactory[]> getArgCombinations(int argSize) {
+    private Iterator<IScalarEvaluatorFactory[]> getArgCombinations(int inputArity) {
+        int argSize = inputArity >= 0 ? inputArity : 3;
         final int numCombinations = 1 << argSize;
         return new Iterator<IScalarEvaluatorFactory[]>() {
             private int index = 0;
diff --git a/asterixdb/asterix-app/src/test/resources/metadata/testsuite.xml b/asterixdb/asterix-app/src/test/resources/metadata/testsuite.xml
index 7b0e015..298c458 100644
--- a/asterixdb/asterix-app/src/test/resources/metadata/testsuite.xml
+++ b/asterixdb/asterix-app/src/test/resources/metadata/testsuite.xml
@@ -423,7 +423,7 @@
     <test-case FilePath="exception">
       <compilation-unit name="issue_255_create_dataset_error_2">
         <output-dir compare="Text">none</output-dir>
-        <expected-error>Error: The partitioning key [open-type] cannot be of type RECORD.</expected-error>
+        <expected-error>Error: The partitioning key [open-type] cannot be of type record.</expected-error>
       </compilation-unit>
     </test-case>
     <!-- Feed datasets are not supported anymore
@@ -449,37 +449,37 @@
     <test-case FilePath="exception">
       <compilation-unit name="issue_384_create_index_error_1">
         <output-dir compare="Text">none</output-dir>
-        <expected-error>Error: The field "[loc]" which is of type POINT cannot be indexed using the BTree index.</expected-error>
+        <expected-error>Error: The field "[loc]" which is of type point cannot be indexed using the BTree index.</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="exception">
       <compilation-unit name="issue_384_create_index_error_2">
         <output-dir compare="Text">none</output-dir>
-        <expected-error>Error: The field "[age]" which is of type INT32 cannot be indexed using the RTree index.</expected-error>
+        <expected-error>Error: The field "[age]" which is of type int32 cannot be indexed using the RTree index.</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="exception">
       <compilation-unit name="issue_384_create_index_error_3">
         <output-dir compare="Text">none</output-dir>
-        <expected-error>Error: The field "[loc]" which is of type POINT cannot be indexed using the Length Partitioned Keyword index.</expected-error>
+        <expected-error>Error: The field "[loc]" which is of type point cannot be indexed using the Length Partitioned Keyword index.</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="exception">
       <compilation-unit name="issue_384_create_index_error_4">
         <output-dir compare="Text">none</output-dir>
-        <expected-error>Error: The field "[loc]" which is of type POINT cannot be indexed using the Length Partitioned Keyword index.</expected-error>
+        <expected-error>Error: The field "[loc]" which is of type point cannot be indexed using the Length Partitioned Keyword index.</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="exception">
       <compilation-unit name="issue_384_create_index_error_5">
         <output-dir compare="Text">none</output-dir>
-        <expected-error>Error: The field "[loc]" which is of type POINT cannot be indexed using the Length Partitioned N-Gram index.</expected-error>
+        <expected-error>Error: The field "[loc]" which is of type point cannot be indexed using the Length Partitioned N-Gram index.</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="exception">
       <compilation-unit name="issue_384_create_index_error_6">
         <output-dir compare="Text">none</output-dir>
-        <expected-error>Error: The field "[loc]" which is of type POINT cannot be indexed using the Length Partitioned N-Gram index.</expected-error>
+        <expected-error>Error: The field "[loc]" which is of type point cannot be indexed using the Length Partitioned N-Gram index.</expected-error>
       </compilation-unit>
     </test-case>
   </test-group>
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/comparison/ComparisonQueries.xml b/asterixdb/asterix-app/src/test/resources/runtimets/queries/comparison/ComparisonQueries.xml
index 8493df2..e549a92 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/comparison/ComparisonQueries.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/comparison/ComparisonQueries.xml
@@ -172,43 +172,43 @@
   <test-case FilePath="comparison">
     <compilation-unit name="issue363_inequality_duration">
       <output-dir compare="Text">issue363_inequality_duration</output-dir>
-      <expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: Comparison operations (GT, GE, LT, and LE) for the DURATION type are not defined</expected-error>
+      <expected-error>Unsupported type: comparison operations (&gt;, &gt;=, &lt;, and &lt;=) cannot process input type duration</expected-error>
     </compilation-unit>
   </test-case>
   <test-case FilePath="comparison">
     <compilation-unit name="issue363_inequality_interval">
       <output-dir compare="Text">issue363_inequality_interval</output-dir>
-      <expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: Comparison operations (GT, GE, LT, and LE) for the INTERVAL type are not defined</expected-error>
+      <expected-error>Unsupported type: comparison operations (&gt;, &gt;=, &lt;, and &lt;=) cannot process input type interval</expected-error>
     </compilation-unit>
   </test-case>
   <test-case FilePath="comparison">
     <compilation-unit name="issue363_inequality_point">
       <output-dir compare="Text">issue363_inequality_point</output-dir>
-      <expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: Comparison operations (GT, GE, LT, and LE) for the POINT type are not defined</expected-error>
+      <expected-error>Unsupported type: comparison operations (&gt;, &gt;=, &lt;, and &lt;=) cannot process input type point</expected-error>
     </compilation-unit>
   </test-case>
   <test-case FilePath="comparison">
     <compilation-unit name="issue363_inequality_line">
       <output-dir compare="Text">issue363_inequality_line</output-dir>
-      <expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: Comparison operations (GT, GE, LT, and LE) for the LINE type are not defined</expected-error>
+      <expected-error>Unsupported type: comparison operations (&gt;, &gt;=, &lt;, and &lt;=) cannot process input type line</expected-error>
     </compilation-unit>
   </test-case>
   <test-case FilePath="comparison">
     <compilation-unit name="issue363_inequality_polygon">
       <output-dir compare="Text">issue363_inequality_polygon</output-dir>
-      <expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: Comparison operations (GT, GE, LT, and LE) for the POLYGON type are not defined</expected-error>
+      <expected-error>Unsupported type: comparison operations (&gt;, &gt;=, &lt;, and &lt;=) cannot process input type polygon</expected-error>
     </compilation-unit>
   </test-case>
   <test-case FilePath="comparison">
     <compilation-unit name="issue363_inequality_rectangle">
       <output-dir compare="Text">issue363_inequality_rectangle</output-dir>
-      <expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: Comparison operations (GT, GE, LT, and LE) for the RECTANGLE type are not defined</expected-error>
+      <expected-error>Unsupported type: comparison operations (&gt;, &gt;=, &lt;, and &lt;=) cannot process input type rectangle</expected-error>
     </compilation-unit>
   </test-case>
   <test-case FilePath="comparison">
     <compilation-unit name="issue363_inequality_circle">
       <output-dir compare="Text">issue363_inequality_circle</output-dir>
-      <expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: Comparison operations (GT, GE, LT, and LE) for the CIRCLE type are not defined</expected-error>
+      <expected-error>Unsupported type: comparison operations (&gt;, &gt;=, &lt;, and &lt;=) cannot process input type circle</expected-error>
     </compilation-unit>
   </test-case>
   <test-case FilePath="comparison">
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
index 942b546..dd859c4 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -452,19 +452,19 @@
     <test-case FilePath="aggregate">
       <compilation-unit name="avg_mixed">
         <output-dir compare="Text">avg_mixed</output-dir>
-        <expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: Unexpected type STRING</expected-error>
+        <expected-error>Type incompatibility: function agg-avg gets incompatible input values: string and float</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="aggregate">
       <compilation-unit name="sum_mixed">
         <output-dir compare="Text">sum_mixed</output-dir>
-        <expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: Unexpected type STRING</expected-error>
+        <expected-error>Type incompatibility: function agg-sum gets incompatible input values: string and float</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="aggregate">
       <compilation-unit name="min_mixed">
         <output-dir compare="Text">min_mixed</output-dir>
-        <expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: Unexpected type STRING</expected-error>
+        <expected-error>Type incompatibility: function min/max gets incompatible input values: string and float</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="aggregate">
@@ -913,19 +913,19 @@
     <test-case FilePath="aggregate-sql">
       <compilation-unit name="avg_mixed">
         <output-dir compare="Text">avg_mixed</output-dir>
-        <expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: Unexpected type STRING</expected-error>
+        <expected-error>Type incompatibility: function agg-avg gets incompatible input values: string and float</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="aggregate-sql">
       <compilation-unit name="sum_mixed">
         <output-dir compare="Text">sum_mixed</output-dir>
-        <expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: Unexpected type STRING</expected-error>
+        <expected-error>Type incompatibility: function agg-sum gets incompatible input values: string and float</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="aggregate-sql">
       <compilation-unit name="min_mixed">
         <output-dir compare="Text">min_mixed</output-dir>
-        <expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: Unexpected type STRING</expected-error>
+        <expected-error>Type incompatibility: function min/max gets incompatible input values: string and float</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="aggregate-sql">
@@ -1560,7 +1560,7 @@
     <test-case FilePath="dml">
       <compilation-unit name="insert-duplicated-keys-from-query">
         <output-dir compare="Text">insert-duplicated-keys-from-query</output-dir>
-        <expected-error>org.apache.hyracks.storage.am.common.exceptions.TreeIndexDuplicateKeyException: Failed to insert key since key already exists</expected-error>
+        <expected-error>Failed to insert key since key already exists</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="dml">
@@ -1755,7 +1755,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>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: Duplicate field id encountered</expected-error>
+        <expected-error>Duplicate field id encountered</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="dml">
@@ -2566,7 +2566,7 @@
     <test-case FilePath="fuzzyjoin">
       <compilation-unit name="dblp-aqlplus_2">
         <output-dir compare="Text">dblp-aqlplus_2</output-dir>
-        <expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: Invalid types STRING given as arguments to jaccard</expected-error>
+        <expected-error>Type mismatch: function similarity-jaccard expects its 1st input parameter to be type orderedlist or unorderedlist, but the actual input type is string</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="fuzzyjoin">
@@ -3215,7 +3215,7 @@
     <test-case FilePath="meta">
       <compilation-unit name="query_dataset_with_meta_failure">
         <output-dir compare="Text">query_dataset_with_meta_failure</output-dir>
-        <expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: Cannot resolve to ambiguity on the meta function call -- there are more than once dataset choices!</expected-error>
+        <expected-error>Cannot resolve to ambiguity on the meta function call -- there are more than one dataset choices!</expected-error>
       </compilation-unit>
     </test-case>
   </test-group>
@@ -3224,8 +3224,8 @@
       <compilation-unit name="partition-by-nonexistent-field"> <!-- Seriously?? 3 expected errors -->
         <output-dir compare="Text">partition-by-nonexistent-field</output-dir>
         <expected-error>Type not found for partitioning key [id]</expected-error>
-        <expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: Cannot find dataset</expected-error>
-        <expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: Could not find dataset</expected-error>
+        <expected-error>Cannot find dataset</expected-error>
+        <expected-error>Could not find dataset</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="misc">
@@ -3338,25 +3338,25 @@
       <test-case FilePath="open-index-enforced/error-checking">
         <compilation-unit name="index-on-closed-type">
           <output-dir compare="Text">index-on-closed-type</output-dir>
-          <expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: Typed index on "[value]" field could be created only for open datatype</expected-error>
+          <expected-error>Typed index on "[value]" field could be created only for open datatype</expected-error>
         </compilation-unit>
       </test-case>
       <test-case FilePath="open-index-enforced/error-checking">
         <compilation-unit name="index-type-collision">
           <output-dir compare="Text">index-type-collision</output-dir>
-          <expected-error>org.apache.asterix.common.exceptions.AsterixException: Cannot create index testIdx2 , enforced index testIdx1 on field "[value]" is already defined with type "[INT32]"</expected-error>
+          <expected-error>org.apache.asterix.common.exceptions.AsterixException: Cannot create index testIdx2 , enforced index testIdx1 on field "[value]" is already defined with type "[int32]"</expected-error>
         </compilation-unit>
       </test-case>
       <test-case FilePath="open-index-enforced/error-checking">
         <compilation-unit name="index-type-promotion-collision">
           <output-dir compare="Text">index-type-promotion-collision</output-dir>
-          <expected-error>org.apache.asterix.common.exceptions.AsterixException: Cannot create index testIdx2 , enforced index testIdx1 on field "[value]" is already defined with type "[INT64]"</expected-error>
+          <expected-error>org.apache.asterix.common.exceptions.AsterixException: Cannot create index testIdx2 , enforced index testIdx1 on field "[value]" is already defined with type "[int64]"</expected-error>
         </compilation-unit>
       </test-case>
       <test-case FilePath="open-index-enforced/error-checking">
         <compilation-unit name="missing-enforce-statement">
           <output-dir compare="Text">missing-enforce-statement</output-dir>
-          <expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: Cannot create typed index on "[value]" field without enforcing it's type</expected-error>
+          <expected-error>Cannot create typed index on "[value]" field without enforcing it's type</expected-error>
         </compilation-unit>
       </test-case>
       <test-case FilePath="open-index-enforced/error-checking">
@@ -3368,7 +3368,7 @@
       <test-case FilePath="open-index-enforced/error-checking">
         <compilation-unit name="object-type-collision">
           <output-dir compare="Text">object-type-collision</output-dir>
-          <expected-error>org.apache.asterix.common.exceptions.AsterixException: A field "[value]" is already defined with the type "STRING"</expected-error>
+          <expected-error>org.apache.asterix.common.exceptions.AsterixException: A field "[value]" is already defined with the type "string"</expected-error>
         </compilation-unit>
       </test-case>
     </test-group>
@@ -4689,7 +4689,7 @@
     <test-case FilePath="open-closed"><!-- Throws two exceptions. need to be checked. proposal: (fixed expected results) -->
       <compilation-unit name="query-issue410">
         <output-dir compare="Text">query-issue410</output-dir>
-        <expected-error>HyracksDataException: ASX0000: Field type DOUBLE can't be promoted to type STRING</expected-error>
+        <expected-error>Field type double can't be promoted to type string</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="open-closed">
@@ -6589,7 +6589,7 @@
     <test-case FilePath="load">
       <compilation-unit name="issue650_query">
         <output-dir compare="Text">none</output-dir>
-        <expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException: Unable to load dataset Users since it does not exist</expected-error>
+        <expected-error>Unable to load dataset Users since it does not exist</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="load">
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 f89fd63..1030454 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -132,19 +132,19 @@
     <test-case FilePath="aggregate">
       <compilation-unit name="avg_mixed">
         <output-dir compare="Text">avg_mixed</output-dir>
-        <expected-error>Unexpected type STRING in aggregation input stream. Expected type FLOAT</expected-error>
+        <expected-error>Type incompatibility: function agg-avg gets incompatible input values: string and float</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="aggregate">
       <compilation-unit name="sum_mixed">
         <output-dir compare="Text">sum_mixed</output-dir>
-        <expected-error>Unexpected type STRING in aggregation input stream. Expected type (or a promotable type to)FLOAT</expected-error>
+        <expected-error>Type incompatibility: function agg-sum gets incompatible input values: string and float</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="aggregate">
       <compilation-unit name="min_mixed">
         <output-dir compare="Text">min_mixed</output-dir>
-        <expected-error>Unexpected type STRING in aggregation input stream. Expected type FLOAT</expected-error>
+        <expected-error>Type incompatibility: function min/max gets incompatible input values: string and float</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="aggregate">
@@ -568,19 +568,19 @@
     <test-case FilePath="aggregate-sql">
       <compilation-unit name="avg_mixed">
         <output-dir compare="Text">avg_mixed</output-dir>
-        <expected-error>Unexpected type STRING in aggregation input stream. Expected type FLOAT</expected-error>
+        <expected-error>Type incompatibility: function agg-avg gets incompatible input values: string and float</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="aggregate-sql">
       <compilation-unit name="sum_mixed">
         <output-dir compare="Text">sum_mixed</output-dir>
-        <expected-error>Unexpected type STRING in aggregation input stream. Expected type (or a promotable type to)FLOAT</expected-error>
+        <expected-error>Type incompatibility: function agg-sum gets incompatible input values: string and float</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="aggregate-sql">
       <compilation-unit name="min_mixed">
         <output-dir compare="Text">min_mixed</output-dir>
-        <expected-error>Unexpected type STRING in aggregation input stream. Expected type FLOAT</expected-error>
+        <expected-error>Type incompatibility: function min/max gets incompatible input values: string and float</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="aggregate-sql">
@@ -1112,43 +1112,43 @@
     <test-case FilePath="comparison">
       <compilation-unit name="issue363_inequality_duration">
         <output-dir compare="Text">issue363_inequality_duration</output-dir>
-        <expected-error>Comparison operations (GT, GE, LT, and LE) for the DURATION type are not defined</expected-error>
+        <expected-error>Unsupported type: comparison operations (&gt;, &gt;=, &lt;, and &lt;=) cannot process input type duration</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="comparison">
       <compilation-unit name="issue363_inequality_interval">
         <output-dir compare="Text">issue363_inequality_interval</output-dir>
-        <expected-error>Comparison operations (GT, GE, LT, and LE) for the INTERVAL type are not defined</expected-error>
+        <expected-error>Unsupported type: comparison operations (&gt;, &gt;=, &lt;, and &lt;=) cannot process input type interval</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="comparison">
       <compilation-unit name="issue363_inequality_point">
         <output-dir compare="Text">issue363_inequality_point</output-dir>
-        <expected-error>Comparison operations (GT, GE, LT, and LE) for the POINT type are not defined</expected-error>
+        <expected-error>Unsupported type: comparison operations (&gt;, &gt;=, &lt;, and &lt;=) cannot process input type point</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="comparison">
       <compilation-unit name="issue363_inequality_line">
         <output-dir compare="Text">issue363_inequality_line</output-dir>
-        <expected-error>Comparison operations (GT, GE, LT, and LE) for the LINE type are not defined</expected-error>
+        <expected-error>Unsupported type: comparison operations (&gt;, &gt;=, &lt;, and &lt;=) cannot process input type line</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="comparison">
       <compilation-unit name="issue363_inequality_polygon">
         <output-dir compare="Text">issue363_inequality_polygon</output-dir>
-        <expected-error>Comparison operations (GT, GE, LT, and LE) for the POLYGON type are not defined</expected-error>
+        <expected-error>Unsupported type: comparison operations (&gt;, &gt;=, &lt;, and &lt;=) cannot process input type polygon</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="comparison">
       <compilation-unit name="issue363_inequality_rectangle">
         <output-dir compare="Text">issue363_inequality_rectangle</output-dir>
-        <expected-error>Comparison operations (GT, GE, LT, and LE) for the RECTANGLE type are not defined</expected-error>
+        <expected-error>Unsupported type: comparison operations (&gt;, &gt;=, &lt;, and &lt;=) cannot process input type rectangle</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="comparison">
       <compilation-unit name="issue363_inequality_circle">
         <output-dir compare="Text">issue363_inequality_circle</output-dir>
-        <expected-error>Comparison operations (GT, GE, LT, and LE) for the CIRCLE type are not defined</expected-error>
+        <expected-error>Unsupported type: comparison operations (&gt;, &gt;=, &lt;, and &lt;=) cannot process input type circle</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="comparison">
@@ -2440,7 +2440,7 @@
     <test-case FilePath="global-aggregate">
       <compilation-unit name="q06_error">
         <output-dir compare="Text">q01</output-dir>
-        <expected-error>Unsupported type: STRING</expected-error>
+        <expected-error>Type mismatch: function scan-collection expects its 1st input parameter to be type orderedlist or unorderedlist, but the actual input type is string</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="global-aggregate">
@@ -3171,7 +3171,7 @@
       <test-case FilePath="open-index-enforced/error-checking">
         <compilation-unit name="enforced-field-type-collision">
           <output-dir compare="Text">enforced-field-type-collision</output-dir>
-          <expected-error>A field &quot;[value]&quot; is already defined with the type &quot;STRING&quot;</expected-error>
+          <expected-error>A field &quot;[value]&quot; is already defined with the type &quot;string&quot;</expected-error>
         </compilation-unit>
       </test-case>
       <test-case FilePath="open-index-enforced/error-checking">
@@ -4640,7 +4640,7 @@
     <test-case FilePath="open-closed">
       <compilation-unit name="query-issue410">
         <output-dir compare="Text">query-issue410</output-dir>
-        <expected-error>ASX0000: Field type DOUBLE can't be promoted to type STRING</expected-error>
+        <expected-error>Field type double can't be promoted to type string</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="open-closed">
@@ -5433,7 +5433,7 @@
     <test-case FilePath="string">
       <compilation-unit name="repeat_error">
         <output-dir compare="Text">repeat</output-dir>
-        <expected-error>repeat: expects a non-negative repeating number but got -1</expected-error>
+        <expected-error>Invalid value: function asterix:repeat expects its 1 input parameter to be a non-negative value, but gets -1</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="string">