使用 sqoop从MySQL增量导出数据到hive

使用 sqoop从MySQL增量导出数据到hive

本文主要解释incremental参数下append模式和lastmodified模式的区别,想要了解具体其他参数请参考官方文档:
http://sqoop.apache.org/docs/1.4.6/SqoopUserGuide.html#_importing_data_into_hive

- 首先测试append模式

/usr/bin/sqoop import --connect 'jdbc:mysql://172.17.1.103:3306/test?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull' --username root --password 123456 -table incr_test -hive-database test -hive-table test_incr_test_20171130 -hive-import -m -1 --incremental append --check-column time_update --last-value "2017-12-01"
MySQL原始数据如下图所示:

这里写图片描述

执行上述命令后,查看hive数据如下:

这里写图片描述
只把‘2017-12-01’之后的数据导过来了,然后在MySQL添加数据之后再次导入。

MySQL数据如图:
这里写图片描述

再次执行上述命令结果如图:
这里写图片描述

把id为1的数据时间改为2017-12-01,模拟数据被更新,之后再导入hive(注:2017-11-01那条记录是之前就导入进来的)

append模式
append模式

结果表明append模式每次导入数据都会把last-value之后的数据全部导过来,不管是否超过当前时间。   

-再来测试一下lastmodified模式

/usr/bin/sqoop import --connect 'jdbc:mysql://172.17.1.103:3306/test?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull' --username root --password 123456 -table incr_test -hive-database test -hive-table test_incr_test_20171130 -hive-import -m -1 --incremental lastmodified --check-column time_update --last-value "2017-12-01" 

原始MySQL数据如下:
这里写图片描述

执行命令后查看hive数据如下:
这里写图片描述

修改原始MySQL数据:
这里写图片描述

再次执行命令:
这里写图片描述

把id为1的数据时间改为2017-12-01,模拟数据被更新,之后再导入hive注:2017-11-01那条记录是之前就导入进来的)
lastmodified模式
lastmodified模式

测试结果表明lastmodified模式只会导入当前时间之前,大于当前时间不会导入,其他的与append模式无差异。
从sqoop执行日志里也可以看出来
lastmodified模式
这里写图片描述
append模式
这里写图片描述

做这个测试的原因就是因为看不太懂官方网站对这两个模式的解释,但是从测试结果来看好像区别不大,如果有错误还请小伙伴指出来,共同学习。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值