问题原因
分别从MySQL和Hive获取数据进行join操作。由于join时,使用的字段数据类型不同,导致无法join。需要指定字段数据类型,让左右两边的字段数据类型保持一致。
报错信息
# table1和table2表中的id在R中的数据类型不同,一个是integer64,另一个是characte
> table <- table1 %>%
inner_join(table2, by = "id") %>%
collect()
Error: Can't join on 'id' x 'id' because of incompatible types (integer64 / character)
处理方法1:在使用dbGetQuery()方法在使用SQL获取Hive中table2的数据时,将id改为cast(id as int) as id
,再重新执行,继续报错:
Warning message:
Column `suite_id` has different attributes on LHS and RHS of join
处理方法2:使用sapply方法查看两个table中id的数据类型,这次虽然都是integer但是仍然不是相同的数据类型。将table2中的id改为integer64类型,执行成功。需要先安装bit或者bit64包。
# 检查table1和t