You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2020/04/23 15:49:17 UTC

[GitHub] [hive] dengzhhu653 commented on a change in pull request #992: HIVE-23269: Unsafe comparing bigints and (var)chars

dengzhhu653 commented on a change in pull request #992:
URL: https://github.com/apache/hive/pull/992#discussion_r413913032



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/parse/type/TypeCheckProcFactory.java
##########
@@ -789,12 +791,25 @@ protected void validateUDF(ASTNode expr, boolean isFunction, TypeCheckCtx ctx, F
 
         LogHelper console = new LogHelper(LOG);
 
+        Set<PrimitiveObjectInspector.PrimitiveCategory> unsafeConventionTyps = Sets.newHashSet(
+            PrimitiveObjectInspector.PrimitiveCategory.STRING,
+            PrimitiveObjectInspector.PrimitiveCategory.VARCHAR,
+            PrimitiveObjectInspector.PrimitiveCategory.CHAR);
         // For now, if a bigint is going to be cast to a double throw an error or warning
-        if ((oiTypeInfo0.equals(TypeInfoFactory.stringTypeInfo) && oiTypeInfo1.equals(TypeInfoFactory.longTypeInfo)) ||
-            (oiTypeInfo0.equals(TypeInfoFactory.longTypeInfo) && oiTypeInfo1.equals(TypeInfoFactory.stringTypeInfo))) {
+        if ((oiTypeInfo0 instanceof PrimitiveTypeInfo &&
+            unsafeConventionTyps.contains(((PrimitiveTypeInfo)oiTypeInfo0).getPrimitiveCategory()) &&
+            oiTypeInfo1.equals(TypeInfoFactory.longTypeInfo)) || (oiTypeInfo1 instanceof PrimitiveTypeInfo &&
+            unsafeConventionTyps.contains(((PrimitiveTypeInfo)oiTypeInfo1).getPrimitiveCategory()) &&
+            oiTypeInfo0.equals(TypeInfoFactory.longTypeInfo))) {
           String error = StrictChecks.checkTypeSafety(conf);
-          if (error != null) throw new UDFArgumentException(error);
-          console.printError("WARNING: Comparing a bigint and a string may result in a loss of precision.");
+          if (error != null) {
+            throw new UDFArgumentException(error);
+          }
+          String type = oiTypeInfo0.getTypeName();
+          if (oiTypeInfo0.equals(TypeInfoFactory.longTypeInfo)) {
+            type = oiTypeInfo1.getTypeName();
+          }
+          console.printError("WARNING: Comparing a bigint and a " + type + " may result in a loss of precision.");

Review comment:
       yes, the variable can be removed by this way, thank you.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org