hive - 字符串string和bigint类型的坑
- 1、string = bigint (假设)
- 2、bigint = string (假设)
1、string = bigint (假设)
person 表数据:
id:string | name |
---|---|
72315**********49 | aa |
72315**********48 | bb |
spc 表数据:
id:bigint | modify_user_id:bigint |
---|---|
1 | 72315**********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:bigint | name:string |
---|---|
72315**********49 | aa |
72315**********48 | bb |
spc 表数据:
id:string | modify_user_id:string |
---|---|
1 | 72315**********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的数字)。当数字超过精度的时候就会比较不准确,出现上面描述的现象。
相关文章
暂无评论...