栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

hive - 字符串string和bigint类型的坑

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

hive - 字符串string和bigint类型的坑

hive - 字符串string和bigint类型的坑
  • 1、string = bigint (假设)
  • 2、bigint = string (假设)

1、string = bigint (假设)

person 表数据:

id:stringname
72315**********49aa
72315**********48bb

spc 表数据:

id:bigintmodify_user_id:bigint
172315**********49
SELECt person.id , person.name , spc.modify_user_id, spc.id as spc_id ,cast(person.id as string) as aaa, cast(spc.modify_user_id as string)   as bbb
from  spc 
join  person on person.id = spc.modify_user_id; -- 相当于person.id <= spc.modify_user_id

2、bigint = string (假设)

person 表数据:

id:bigintname:string
72315**********49aa
72315**********48bb

spc 表数据:

id:stringmodify_user_id:string
172315**********49
SELECt person.id , person.name , spc.modify_user_id, spc.id as spc_id ,cast(person.id as string) as aaa, cast(spc.modify_user_id as string)   as bbb
from  spc 
join  person on person.id = spc.modify_user_id; -- 相当于person.id <= spc.modify_user_id

综上所述,以上sql会输出两条记录,
原因:bigint和string比较时会隐式地都转换成double,java中double的精度只有15-16位(double可以精确的表示小于2^52=4503599627370496的数字)。当数字超过精度的时候就会比较不准确,出现上面描述的现象。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/964087.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号