oozie4.3.0+sqoop1.4.6实现mysql到hive的增量抽取
1.准备数据源
mysql中表bigdata,数据如下:

2. 准备目标表
目标表存放hive中数据库dw_stg表bigdata
保存路径为 hdfs://localhost:9000/user/hive/warehouse/dw_stg.db/bigdata
hive中建表语句如下:
create external table bigdata(
class_id string comment '课程id',
class_name string comment '课程名称',
class_month int comment '课程周期',
teacher string comment '课程老师',
update_time string comment '更新日期'
)
partitioned by(dt string comment '年月日')
row format delimited
fields terminated by '\001'
lines terminated by '\n'
stored as textfile;
注意点: 字段分隔符使用\001,行分隔符使用\n ,增加表分区dt格式为yyyMMdd
在hive中创建上面表bigdata.
3. 编写oozie脚本文件
3.1 配置job.properties
# 公共变量
timezone=Asia/Shanghai
jobTracker=dwtest-name1:8032
nameNode=hdfs://dwtest-name1:9000
queueName=default
warehouse=/user/hive/warehouse
dw_stg=${warehouse}/dw_stg.db
dw_mdl=${warehouse}/dw_mdl.db
dw_dm=${warehouse}/dw_dm.db
app_home=/user/oozie/app
oozie.use.system.libpath=true # coordinator
oozie.coord.application.path=${nameNode}${app_home}/bigdata/coordinator.xml
workflow=${nameNode}${app_home}/bigdata # source
connection=jdbc:mysql://192.168.1.100:3306/test
username=test
password=test
source_table=bigdata # target
target_path=${dw_stg}/bigdata # 脚本启动时间,结束时间
start=2018-01-24T10:00+0800
end=2199-01-01T01:00+0800
3.2 配置coordinator.xml
<coordinator-app name="coord_bigdata" frequency="${coord:days(1)}" start="${start}" end="${end}" timezone="${timezone}" xmlns="uri:oozie:coordinator:0.5">
<action>
<workflow>
<app-path>${workflow}</app-path>
<configuration>
<property>
<name>startTime</name>
<value>${coord:formatTime(coord:dateOffset(coord:nominalTime(), -1, 'DAY'), 'yyyy-MM-dd 00:00:00')}</value>
</property>
<property>
<name>endTime</name>
<value>${coord:formatTime(coord:dateOffset(coord:nominalTime(), 0, 'DAY'), 'yyyy-MM-dd 00:00:00')}</value>
</property>
<property>
<name>outputPath</name>
<value>${target_path}/dt=${coord:formatTime(coord:dateOffset(coord:nominalTime(), 0, 'DAY'), 'yyyyMMdd')}/</value>
</property>
</configuration>
</workflow>
</action>
</coordinator-app>
注意点:
增量的开始时间startTime获取: 当前时间的前一天 输出值为 2018-01-23 00:00:00
${coord:formatTime(coord:dateOffset(coord:nominalTime(), -, 'DAY'), 'yyyy-MM-dd 00:00:00')}
增量的结束时间endTime获取: 输出值为 2018-01-24 00:00:00
${coord:formatTime(coord:dateOffset(coord:nominalTime(), , 'DAY'), 'yyyy-MM-dd 00:00:00')}
输出路径需要带上分区字段dt: 输出值 /user/hive/warehouse/dw_stg.db/bigdata/dt=20180124/
${target_path}/dt=${coord:formatTime(coord:dateOffset(coord:nominalTime(), , 'DAY'), 'yyyyMMdd')}/
3.3 配置workflow.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<workflow-app xmlns="uri:oozie:workflow:0.4" name="wf_bigdata">
<start to="sqoop-node"/> <action name="sqoop-node">
<sqoop xmlns="uri:oozie:sqoop-action:0.2">
<job-tracker>${jobTracker}</job-tracker>
<name-node>${nameNode}</name-node>
<prepare>
<delete path="${nameNode}${outputPath}"/>
</prepare>
<configuration>
<property>
<name>mapred.job.queue.name</name>
<value>${queueName}</value>
</property>
</configuration>
<arg>import</arg>
<arg>--connect</arg>
<arg>${connection}</arg>
<arg>--username</arg>
<arg>${username}</arg>
<arg>--password</arg>
<arg>${password}</arg>
<arg>--verbose</arg>
<arg>--query</arg>
<arg>select class_id,class_name,class_month,teacher,update_time from ${source_table} where $CONDITIONS and update_time >= '${startTime}' and update_time < '${endTime}'</arg>
<arg>--fields-terminated-by</arg>
<arg>\001</arg>
<arg>--target-dir</arg>
<arg>${outputPath}</arg>
<arg>-m</arg>
<arg>1</arg>
</sqoop>
<ok to="end"/>
<error to="fail"/>
</action> <kill name="fail">
<message>Sqoop free form failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<end name="end"/>
</workflow-app>
4. 上传脚本
将以上3个文件上传到hdfs的oozie目录app下如下:

5. 执行job
oozie job -config job.properties -run

6. 查看job状态

7. 查询hive中表
使用 msck repair table bigdata 自动修复分区,然后查询结果,测试没用问题。

8. 开发中遇到的坑如下:
8.1 workflow.xml中字段分隔符不能带单引号。正确的是<arg>\001</arg> ,错误的是<arg>'\001'</arg>
8.2 由于sqoop的脚本配置在xml中,所以在判断条件时使用小于号"<"会报错,xml文件校验不通过。
解决方法使用 < 代替 "<" ,所以使用大于号时最好也使用 >代替 ">"
oozie4.3.0+sqoop1.4.6实现mysql到hive的增量抽取的更多相关文章
- hive表增量抽取到mysql(关系数据库)的通用程序(三)
hive表增量抽取到oracle数据库的通用程序(一) hive表增量抽取到oracle数据库的通用程序(二) 这几天又用到了该功能了,所以又改进了一版,增加了全量抽取和批量抽取两个参数.并且可以设置 ...
- 【转】Oozie4.2.0配置安装实战
什么是Oozie? Oozie是一种Java Web应用程序,它运行在Java servlet容器——即Tomcat——中,并使用数据库来存储以下内容: 工作流定义 当前运行的工作流实例,包括实例的状 ...
- oozie4.3.0的安装与配置 + hadoop2.7.3
安装步骤 mysql的配置 oozie的安装 oozie的配置 oozie的启动与登录 常用oozie的命令 1. mysql的配置 mysql的安装自行解决,然后在mysql上 创建oozie数据库 ...
- Oozie4.2.0配置安装实战
软件版本号: Oozie4.2.0.Hadoop2.6.0,Spark1.4.1.Hive0.14.Pig0.15.0.Maven3.2.JDK1.7,zookeeper3.4.6.HBase1.1. ...
- 【Linux】【MySQL】CentOS7安装最新版MySQL8.0.13(最新版MySQL从安装到运行)
1.前言 框框博客在线报时:2018-11-07 19:31:06 当前MySQL最新版本:8.0.13 (听说比5.7快2倍) 官方之前表示:MySQL 8.0 正式版 8.0.11 已发布,MyS ...
- CentOS 7.0下使用yum安装MySQL
CentOS7默认数据库是mariadb,配置等用着不习惯,因此决定改成mysql,但是CentOS7的yum源中默认好像是没有mysql的.为了解决这个问题,我们要先下载mysql的repo源. 1 ...
- (转)maven3.3.9编译oozie4.3.0
1.Java版本1.8 [root@sht-sgmhadoopdn-04 app]# java -versionjava version "1.8.0_66"Java(TM) SE ...
- (0)linux下的Mysql安装与基本使用(编译安装)
一.大致操作步骤 环境介绍: OS:center OS6.5 mysql:5.6版本 1.关闭防火墙 查看防火墙状态:service iptables status 这样就意味着没有关闭. 运行以下命 ...
- MySQL 8.0 正式版 8.0.11 发布:比 MySQL 5.7 快 2 倍
ySQL 8.0 正式版 8.0.11 已发布,官方表示 MySQL 8 要比 MySQL 5.7 快 2 倍,还带来了大量的改进和更快的性能! 注意:从 MySQL 5.7 升级到 MySQL 8. ...
随机推荐
- EasyUI-window包含一个iframe,在iframe中如何关闭window
我试过类似$('#win').window('close');报$.data...options无效的错误,我已经引入了js文件,路径没问题,而且在同一个页面,不用iframe是可以关闭的 在ifra ...
- js看起来比较怪异的写法 (综合)
1.$(function() {}中$是什么意思? <script type="text/javascript"> $(function(){ $("#tre ...
- LeetCode 303 Range Sum Query - Immutable(范围总和查询-永久不变)(*)
翻译 给定一个整型数组nums,找出在索引i到j(i小于等于j)之间(包含i和j)的全部元素之和. 比如: 给定nums = [-2,0,3,-5,2,-1] sumRange(0, 2) -> ...
- Eclipse启动Tomcat错误(其他类似)
Eclipse启动Tomcat错误信息: Several ports (8080, 8009) required by Tomcat v6.0 Server at localhost are alre ...
- Reusing dialogs with a dialog pool--一个sql server service broker例子
一个sql server service broker例子 ----------------------------------- USE master GO -------------------- ...
- 如何阅读Android系统源码-收藏必备
对于任何一个对Android开发感兴趣的人而言,对于android系统的学习必不可少.而学习系统最佳的方法就如linus所言:"RTFSC"(Read The Fucking So ...
- [转发]在Visual Studio 2010/2012/2013/2015上使用C#开发Android/IOS安装包和操作步骤
官方学习文档:http://developer.xamarin.com/guides/android/getting_started/ 官方学习例子:http://developer.xamarin. ...
- windows设置文件夹显示缩略图
windows设置文件夹显示缩略图 CreateTime--2017年7月26日16:32:59Author:Marydon 为什么要显示缩略图? a.显示缩略图后,图片文件能够直接显示内容,不能 ...
- IDEA中同窗口导入新的maven项目
创建请看这个:http://www.cnblogs.com/oskyhg/p/6649266.html 下边开始导入: 完毕. 结果展示:
- Ubuntu下安装使用Xfce4
编辑于 2007-05-05 21:30 安装: 代码: sudo apt-get install xfce4 xfce4-taskbar-plugin (xfce4-taskb ...