当 HIVE 中 string 隐式转换为 int 时会发生什么?

use*_*498 1 java hadoop hive

我使用hive查询数据的时候遇到了下面这样的情况\xef\xbc\x9a

\n\n

select '6455983054544699410' = 6455983054544699395 ===> true\n

\n\n

所以我想知道当hive中string隐式转换为int时会发生什么?

\n\n

谢谢。

\n

Dav*_*itz 5

双方都被施放为双倍

hive> select '6455983054544699410' =  6455983054544699395;
WARNING: Comparing a bigint and a string may result in a loss of precision.
OK
_c0
true
Run Code Online (Sandbox Code Playgroud)
hive> select cast('6455983054544699410' as double) , cast (6455983054544699395 as double);
OK
_c0 _c1
6.4559830545446994E18   6.4559830545446994E18
Run Code Online (Sandbox Code Playgroud)

https://github.com/apache/hive/blob/master/ql/src/java/org/apache/hadoop/hive/ql/plan/ExprNodeGenericFuncDesc.java

// 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))) {
        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.");
      } else if ((oiTypeInfo0.equals(TypeInfoFactory.doubleTypeInfo) && oiTypeInfo1.equals(TypeInfoFactory.longTypeInfo)) ||
          (oiTypeInfo0.equals(TypeInfoFactory.longTypeInfo) && oiTypeInfo1.equals(TypeInfoFactory.doubleTypeInfo))) {
        String error = StrictChecks.checkTypeSafety(conf);
        if (error != null) throw new UDFArgumentException(error);
        console.printError("WARNING: Comparing a bigint and a double may result in a loss of precision.");
      }
Run Code Online (Sandbox Code Playgroud)