两个hive表left join时,由于关联字段类型不同导致的数据错误(bigint、string),结果会多出来一批数据。
select a.id as id1
,b.id as id2
from table1 a
left join table2 b
on a.id = b.id
where a.id = '1257829907772824682'
-- 1257829907772824682 1257829907772824682
-- 1257829907772824682 1257829907772824680
推测原因可能是:因bigint数据长度截断问题导致,将两个末尾不同的id判断相等了!!!
做类型转换即可:
select a.id as id1
,b.id as id2
from table1 b1
left join table2 b2
on cast(a.id as string) = b.id
where a.id = '1257829907772824682'
本文探讨了在Hive中使用left join时,由于bigint和string关联字段的不同导致的错误,重点介绍了如何通过类型转换(cast)来避免数据冗余。作者推测问题源于bigint数据截断并提供了相应的解决方案。
2649

被折叠的 条评论
为什么被折叠?



