如Sqoop在导出到Mysql时,使用4个Map任务,过程中有2个任务失败,那此时MySQL中存储了另外两个Map任务导入的数据,此时老板正好看到了这个报表数据。而开发工程师发现任务失败后,会调试问题并最终将全部数据正确的导入MySQL,那后面老板再次看报表数据,发现本次看到的数据与之前的不一致,这在生产环境是不允许的。
我们可以使用–staging-table创建临时表的方法来解决:
sqoop export
–connect jdbc:mysql://192.168.137.10:3306/user_behavior
–username root
–password 123456
–table app_cource_study_report
–columns watch_video_cnt,complete_video_cnt,dt
–fields-terminated-by “\t”
–export-dir “/user/hive/warehouse/tmp.db/app_cource_study_analysis_${day}”
*–staging-table app_cource_study_report_tmp
–clear-staging-table*
–input-null-string ‘\N’