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 ...
随机推荐
- 网络相关系列之四:数据解析之SAX方式解析XML数据
一.XML和Json数据的引入: 通常情况下.每一个须要訪问网络的应用程序都会有一个自己的server.我们能够向server提交数据,也能够从server获取数据.只是这个时候就有一个问题,这些数据 ...
- qtav----ffmeg在ubuntu和win10上的编译和运行
最近在windows上和ubuntu上都安装了qtav并且通过了编译测试,实测播放中英文的视频文件功能正常,有图像有声音. 大致情况是,操作系统ubuntu: wkr@sea-X550JK:~$ ca ...
- 红米手机连接logcat,调试信息刷屏解决办法
我买了红米,平时拿它来当作安卓测试机的 可是把它接入eclipse里面,发现它会往logcat打印大量的日志,我自己想调试一个程序的时候,自己的程序的日志一会儿就被冲刷没了 新建一个logcat me ...
- html中keydown事件
实现在输入框按回车按钮进行查询的功能: 1.<input type="text" id="inputChannel" onkeydown="ke ...
- Android Activity去除标题栏和状态栏
一.在代码中设置public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //去除ti ...
- 在Linux中配置DNS的正确方式
链接:http://ccl.cse.nd.edu/operations/condor/hostname.shtml Common Hostname Problem on Linux Newly ins ...
- jquery简洁遮罩插件
/************************** *Desc:提交操作时遮罩 *Argument:type=0 全屏遮 1局部遮 *Author:Zery-Zhang *Date:2014-09 ...
- erlang 最大公约数
一般面试会遇到问一些算法,什么排序,树,图等等,冷不丁还会问几个蛋疼的问题,我估计生产情况十有八九都用不上,只是题目罢了. 题目:求两个大数的最大公约数. 什么是最大公约数呢? 百度百科的答案这样的: ...
- e.target与e.currentTarget对比
复制以下代码,即可查看效果 <!DOCTYPE html> <html> <head lang="en"> <meta charset=& ...
- PHP、jQuery、AJAX和MySQL 数据库实例
index.html页面 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...