You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by dl...@apache.org on 2019/06/18 20:44:36 UTC

[asterixdb] branch master updated: [NO ISSUE] Fix error message thrown by ATypeHierarchy

This is an automated email from the ASF dual-hosted git repository.

dlych pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git


The following commit(s) were added to refs/heads/master by this push:
     new d919cb4  [NO ISSUE] Fix error message thrown by ATypeHierarchy
d919cb4 is described below

commit d919cb464c16bf99bdfafef4d816db82a6e53851
Author: Dmitry Lychagin <dm...@couchbase.com>
AuthorDate: Mon Jun 17 11:26:39 2019 -0700

    [NO ISSUE] Fix error message thrown by ATypeHierarchy
    
    - user model changes: no
    - storage format changes: no
    - interface changes: no
    
    Details:
    - Align type mismatch error message thrown by ATypeHierarchy
      with the one produced by TypeMismatchException
    
    Change-Id: I830e93056d18123610b933a0e36fd1b54c6e140b
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/3441
    Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Reviewed-by: Dmitry Lychagin <dm...@couchbase.com>
    Reviewed-by: Ali Alsuliman <al...@gmail.com>
---
 .../asterix/om/exceptions/ExceptionUtil.java       |  4 +--
 .../asterix/om/types/hierachy/ATypeHierarchy.java  | 31 +++++++++++-----------
 2 files changed, 18 insertions(+), 17 deletions(-)

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
index 9a115c8..bdcb201 100644
--- 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
@@ -24,7 +24,7 @@ public class ExceptionUtil {
     private ExceptionUtil() {
     }
 
-    static String toExpectedTypeString(Object... expectedItems) {
+    public static String toExpectedTypeString(Object... expectedItems) {
         StringBuilder expectedTypes = new StringBuilder();
         int numCandidateTypes = expectedItems.length;
         for (int index = 0; index < numCandidateTypes; ++index) {
@@ -40,7 +40,7 @@ public class ExceptionUtil {
         return expectedTypes.toString();
     }
 
-    static String indexToPosition(int index) {
+    public static String indexToPosition(int index) {
         int i = index + 1;
         switch (i % 100) {
             case 11:
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/hierachy/ATypeHierarchy.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/hierachy/ATypeHierarchy.java
index f182370..e5b1c62 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/hierachy/ATypeHierarchy.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/hierachy/ATypeHierarchy.java
@@ -20,7 +20,6 @@ package org.apache.asterix.om.types.hierachy;
 
 import java.io.DataOutput;
 import java.io.IOException;
-import java.util.Arrays;
 import java.util.BitSet;
 import java.util.EnumMap;
 import java.util.HashMap;
@@ -32,6 +31,7 @@ import org.apache.asterix.om.base.ADouble;
 import org.apache.asterix.om.base.AFloat;
 import org.apache.asterix.om.base.IAObject;
 import org.apache.asterix.om.constants.AsterixConstantValue;
+import org.apache.asterix.om.exceptions.ExceptionUtil;
 import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.commons.lang3.tuple.Pair;
@@ -315,10 +315,8 @@ public class ATypeHierarchy {
             case DOUBLE:
                 return DoubleToInt32TypeConvertComputer.getInstance(strictDemote).convertType(bytes, offset);
             default:
-                throw new RuntimeDataException(ErrorCode.TYPE_MISMATCH_FUNCTION, name, argIndex,
-                        Arrays.toString(new Object[] { ATypeTag.TINYINT, ATypeTag.SMALLINT, ATypeTag.INTEGER,
-                                ATypeTag.BIGINT, ATypeTag.FLOAT, ATypeTag.DOUBLE }),
-                        sourceTypeTag);
+                throw createTypeMismatchException(name, argIndex, sourceTypeTag, ATypeTag.TINYINT, ATypeTag.SMALLINT,
+                        ATypeTag.INTEGER, ATypeTag.BIGINT, ATypeTag.FLOAT, ATypeTag.DOUBLE);
         }
     }
 
@@ -354,10 +352,8 @@ public class ATypeHierarchy {
             case DOUBLE:
                 return DoubleToInt64TypeConvertComputer.getInstance(strictDemote).convertType(bytes, offset);
             default:
-                throw new RuntimeDataException(ErrorCode.TYPE_MISMATCH_FUNCTION, name, argIndex,
-                        Arrays.toString(new Object[] { ATypeTag.TINYINT, ATypeTag.SMALLINT, ATypeTag.INTEGER,
-                                ATypeTag.BIGINT, ATypeTag.FLOAT, ATypeTag.DOUBLE }),
-                        sourceTypeTag);
+                throw createTypeMismatchException(name, argIndex, sourceTypeTag, ATypeTag.TINYINT, ATypeTag.SMALLINT,
+                        ATypeTag.INTEGER, ATypeTag.BIGINT, ATypeTag.FLOAT, ATypeTag.DOUBLE);
         }
     }
 
@@ -385,18 +381,16 @@ public class ATypeHierarchy {
             case BIGINT:
                 return IntegerToDoubleTypeConvertComputer.getInstance().convertType(bytes, offset, sourceTypeTag);
             default:
-                throw new RuntimeDataException(ErrorCode.TYPE_MISMATCH_FUNCTION, name, argIndex,
-                        Arrays.toString(new ATypeTag[] { ATypeTag.TINYINT, ATypeTag.SMALLINT, ATypeTag.INTEGER,
-                                ATypeTag.BIGINT, ATypeTag.FLOAT, ATypeTag.DOUBLE }),
-                        sourceTypeTag);
+                throw createTypeMismatchException(name, argIndex, sourceTypeTag, ATypeTag.TINYINT, ATypeTag.SMALLINT,
+                        ATypeTag.INTEGER, ATypeTag.BIGINT, ATypeTag.FLOAT, ATypeTag.DOUBLE);
         }
     }
 
     /**
      * Applies certain math function (e.g., ceil or floor) to a double value and returns that value.
      */
-    public static double applyMathFunctionToDoubleValue(IAObject sourceObject, TypeCastingMathFunctionType mathFunction)
-            throws RuntimeDataException {
+    public static double applyMathFunctionToDoubleValue(IAObject sourceObject,
+            TypeCastingMathFunctionType mathFunction) {
         switch (mathFunction) {
             case CEIL:
                 return Math.ceil(((ADouble) sourceObject).getDoubleValue());
@@ -421,6 +415,13 @@ public class ATypeHierarchy {
         }
     }
 
+    private static RuntimeDataException createTypeMismatchException(String functionName, int argIdx,
+            ATypeTag actualTypeTag, ATypeTag... expectedTypeTags) {
+        return new RuntimeDataException(ErrorCode.TYPE_MISMATCH_FUNCTION, functionName,
+                ExceptionUtil.indexToPosition(argIdx), ExceptionUtil.toExpectedTypeString(expectedTypeTags),
+                actualTypeTag);
+    }
+
     public enum Domain {
         SPATIAL,
         NUMERIC,