Dmitry Lychagin has submitted this change and it was merged. ( 
https://asterix-gerrit.ics.uci.edu/3441 )

Change subject: [NO ISSUE] Fix error message thrown by ATypeHierarchy
......................................................................

[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 <[email protected]>
Integration-Tests: Jenkins <[email protected]>
Reviewed-by: Dmitry Lychagin <[email protected]>
Reviewed-by: Ali Alsuliman <[email protected]>
---
M 
asterixdb/asterix-om/src/main/java/org/apache/asterix/om/exceptions/ExceptionUtil.java
M 
asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/hierachy/ATypeHierarchy.java
2 files changed, 18 insertions(+), 17 deletions(-)

Approvals:
  Jenkins: Verified; Verified
  Dmitry Lychagin: Looks good to me, but someone else must approve
  Ali Alsuliman: Looks good to me, approved

Objections:
  Jenkins: Violations found
  Anon. E. Moose (1000171): Violations found



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 @@
     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 @@
         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 @@

 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.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 @@
             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 @@
             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 @@
             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 @@
         }
     }

+    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,

--
To view, visit https://asterix-gerrit.ics.uci.edu/3441
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I830e93056d18123610b933a0e36fd1b54c6e140b
Gerrit-Change-Number: 3441
Gerrit-PatchSet: 3
Gerrit-Owner: Dmitry Lychagin <[email protected]>
Gerrit-Reviewer: Ali Alsuliman <[email protected]>
Gerrit-Reviewer: Anon. E. Moose (1000171)
Gerrit-Reviewer: Anon. E. Moose <[email protected]>
Gerrit-Reviewer: Dmitry Lychagin <[email protected]>
Gerrit-Reviewer: Jenkins <[email protected]>

Reply via email to