一、场景
源数据库:SQL server 拥有1700多张表100G的数据
目标数据库:Hive
使用工具:sqoop
二、全表导入
sudo -u hdfs \
sqoop import-all-tables \
--connect 'jdbc:sqlserver://192.168.0.212:1433;username=sa;password=xxxx;database=PORTAL_HIS' \
--hive-import \
--hive-overwrite \
-m 1
三、遇到的问题
3.1 hive不支持SQL server中的字段类型
解决方案分三步
1、查出所有不支持Hive字段的表
让开发使用Java实现
2、sqoop全表导入Hive,并排除这些表
添加--exclude-tables
参数
sudo -u hdfs \
sqoop import-all-tables \
--connect 'jdbc:sqlserver://192.168.0.212:1433;username=sa;password=xxxx;database=PORTAL_HIS' \
--hive-import \
--hive-overwrite \
--exclude-tables MSG_MSGTALK,IENR_BDYS \
-m 1
3、通过sqoop更换字段类型,单独导入这些表
添加--map-column-hive
参数
sudo -u hdfs \
sqoop import \
--connect 'jdbc:sqlserver://192.168.0.212:1433;username=sa;password=xxxx;database=PORTAL_HIS' \
--table MSG_MSGTALK \
--hive-import \
--map-column-hive MSGTEXT=STRING \
-m 1 \