sqoop导入增量数据
使用sqoop导入增量数据.
核心参数
--check-column
用来指定一些列,这些列在增量导入时用来检查这些数据是否作为增量数据进行导入,和关系行数据库中的自增字段及时间戳类似
这些被指定的列的类型不能使用任意字符类型,如char、varchar等类型都是不可以的,同时 --check-column 可以去指定多个列
--incremental
用来指定增量导入的模式,两种模式分别为append 和 lastmodified
--last-value
指定上一次导入中检查列指定字段的最大值
append模式
- 创建mysql表
CREATE TABLE `sqoop_test` (
`id` int() DEFAULT NULL,
`name` varchar() DEFAULT NULL,
`age` int() DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
- 创建hive表(表结构与mysql一致)
hive> create external table sqoop_test(id int,name string,age int)
> ROW FORMAT DELIMITED
> FIELDS TERMINATED BY ','
> STORED AS TEXTFILE
> location '/user/hive/external/sqoop_test';
OK
Time taken: 0.126 seconds
- 先导入mysql中的原始数据
sqoop import --connect jdbc:mysql://localhost:3306/sqooptest --username root --password 123qwe --table sqoop_test
--hive-import --hive-overwrite --hive-table sqoop_test --fields-terminated-by ',' -m 1
导入成功,查看hive表中的数据
hive> select * from sqoop_test;
OK
fz
dx
test
Time taken: 0.074 seconds, Fetched: row(s)
- 在mysql中添加几条增量数据
fz
dx
test
test_add_1
test_add_2
test-add-
test-
test-
- 现在开始导入增量数据,增量数据加入前最大id值为3
开始尝试这样写
sqoop import --connect jdbc:mysql://localhost:3306/sqooptest --username root --password 123qwe --table sqoop_test
--hive-import --hive-table sqoop_test --check-column id --incremental append --last-value 3 -m 1
但是提示append模式不支持写入到hive表中
Append mode for hive imports is not yet supported. Please remove the parameter --append-mode
正确写法,直接写入到hdfs
sqoop import --connect jdbc:mysql://localhost:3306/sqooptest --username root --password 123qwe --table sqoop_test
--target-dir '/user/hive/external/sqoop_test' --incremental append --check-column id --last-value 3 -m 1
job完成,在hive查看表数据
hive> select * from sqoop_test;
OK
fz
dx
test
test_add_1
test_add_2
test-add-
test-
test-
Time taken: 0.075 seconds, Fetched: row(s)
成功。
Lastmodified模式
- Mysql新建一个表customertest
CREATE TABLE customertest (
id INT,
name VARCHAR (),
last_mod TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
插入数据
insert into customertest(id,name) values(,'enzo');
insert into customertest(id,name) values(,'din');
insert into customertest(id,name) values(,'fz');
insert into customertest(id,name) values(,'dx');
insert into customertest(id,name) values(,'ef');
enzo -- ::
din -- ::
fz -- ::
dx -- ::
ef -- ::
- 在hive中新建表customertest,表结构类似
hive> create table customertest(id int,name string,last_mod string)
> ROW FORMAT DELIMITED
> FIELDS TERMINATED BY ','
> STORED AS TEXTFILE;
OK
Time taken: 0.189 seconds
- 导入mysql表中的数据
sqoop import --connect jdbc:mysql://localhost:3306/sqooptest --username root --password 123qwe --table customertest
--hive-import --hive-table customertest --fields-terminated-by ',' -m 1
hive> select * from customertest;
OK
enzo -- ::54.0
din -- ::58.0
fz -- ::01.0
dx -- ::05.0
ef -- ::09.0
Time taken: 0.064 seconds, Fetched: row(s)
- 此时在mysql中插入一条数据
insert into customertest(id,name) values(,'enzoDin')
插入之后表中的数据
enzo -- ::
din -- ::
fz -- ::
dx -- ::
ef -- ::
enzoDin -- ::
- 再来根据last_mod来导入增量数据
sqoop import --connect jdbc:mysql://localhost:3306/sqooptest --username root --password 123qwe --table customertest
--hive-import --hive-table customertest --check-column last_mod --incremental lastmodified --last-value "2017-09-20 16:13:09" --fields-terminated-by ',' -m 1
导入成功
hive> select * from customertest;
OK
enzo -- ::54.0
din -- ::58.0
fz -- ::01.0
dx -- ::05.0
ef -- ::09.0
ef -- ::09.0
enzoDin -- ::53.0
Time taken: 0.064 seconds, Fetched: row(s)
查看hive中的数据会发现插入了两条数据,这是因为使用lastmodified 会将大于等于 –last-value 的值都导入进来,所以会造成数据的重复
研究下merge-key....
sqoop导入增量数据的更多相关文章
- sqoop 导入增量数据到hive
版本 hive:apache-hive-2.1.0 sqoop:sqoop-1.4.6 hadoop:hadoop-2.7.3 导入方式 1.append方式 2.lastmodified方式,必须要 ...
- Sqoop导入mysql数据到Hbase
sqoop import --driver com.mysql.jdbc.Driver --connect "jdbc:mysql://11.143.18.29:3306/db_1" ...
- Sqoop导入MySQL数据
导入所有表: sqoop import-all-tables –connect jdbc:mysql://ip:port/dbName --username userName --password p ...
- 第3节 sqoop:6、sqoop的数据增量导入和数据导出
增量导入 在实际工作当中,数据的导入,很多时候都是只需要导入增量数据即可,并不需要将表中的数据全部导入到hive或者hdfs当中去,肯定会出现重复的数据的状况,所以我们一般都是选用一些字段进行增量的导 ...
- sqoop导入数据
来源https://www.cnblogs.com/qingyunzong/p/8807252.html 一.概述 sqoop 是 apache 旗下一款“Hadoop 和关系数据库服务器之间传送数据 ...
- 大数据学习——sqoop导入数据
把数据从关系型数据库导入到hadoop 启动sqoop 导入表表数据到HDFS 下面的命令用于从MySQL数据库服务器中的emp表导入HDFS. sqoop import \ --connect jd ...
- sqoop上传数据到hdfs,并用hive管理数据。
sqoop导入mysql数据表到HDFS中sqoop import --connect jdbc:mysql://master:3306/test --username root --password ...
- 1.11-1.12 Sqoop导入数据时两种增量方式导入及direct
一.增量数据的导入 1.两种方式 ## query 有一个唯一标识符,通常这个表都有一个字段,类似于插入时间createtime where createtime => 201509240000 ...
- Sqoop将mysql数据导入hbase的血与泪
Sqoop将mysql数据导入hbase的血与泪(整整搞了大半天) 版权声明:本文为yunshuxueyuan原创文章.如需转载请标明出处: https://my.oschina.net/yunsh ...
随机推荐
- unity3d动态加载资源
在Unity3D的网络游戏中实现资源动态加载 分类: 最新学习2012-06-14 13:35 1127人阅读 评论(0) 收藏 举报 网络游戏nullvectorjson游戏string 用Unit ...
- [WebGL入门]二十五,点光源的光照
注:文章译自http://wgld.org/,原作者杉本雅広(doxas),文章中假设有我的额外说明.我会加上[lufy:].另外,鄙人webgl研究还不够深入,一些专业词语.假设翻译有误,欢迎大家指 ...
- myeclipse配置问题
一,配置相关 1,myeclipse配置jdk Window --> Preferences --> Java --> Installed JREs 2.myeclipse配置tom ...
- parse arguments in bash
There are lots of ways to parse arguments in sh. Getopt is good. Here's a simple script that parses ...
- CG标准函数库——数学函数(GPU编程与CG语言之阳春白雪下里巴人)
- Linux下安装 activemq 并指定jdk 1.8
1. 下载安装包 <apache-activemq-5.15.4-bin.tar.gz> 下载地址:https://pan.baidu.com/s/18xzjBAchjWqsHNA1HuY ...
- docker安装并配置加速
安装 旧版本的 Docker 称为 docker 或者 docker-engine,使用以下命令卸载旧版本: sudo apt-get remove docker \ docker-engine \ ...
- What I learned from competing against a ConvNet on ImageNet
http://karpathy.github.io/2014/09/02/what-i-learned-from-competing-against-a-convnet-on-imagenet/
- js滚动到指定位置显示或隐藏元素
$(function(){ $(window).scroll(function(){ var scroll_top=$(window).scrollTop(); console.log(scroll_ ...
- Python菜鸟之路:Python基础-Python操作RabbitMQ
RabbitMQ简介 rabbitmq中文翻译的话,主要还是mq字母上:Message Queue,即消息队列的意思.rabbitmq服务类似于mysql.apache服务,只是提供的功能不一样.ra ...