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 &gt;= '${startTime}' and update_time &lt; '${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文件校验不通过。

解决方法使用 &lt; 代替 "<"  ,所以使用大于号时最好也使用 &gt;代替 ">" 

oozie4.3.0+sqoop1.4.6实现mysql到hive的增量抽取的更多相关文章

  1. hive表增量抽取到mysql(关系数据库)的通用程序(三)

    hive表增量抽取到oracle数据库的通用程序(一) hive表增量抽取到oracle数据库的通用程序(二) 这几天又用到了该功能了,所以又改进了一版,增加了全量抽取和批量抽取两个参数.并且可以设置 ...

  2. 【转】Oozie4.2.0配置安装实战

    什么是Oozie? Oozie是一种Java Web应用程序,它运行在Java servlet容器——即Tomcat——中,并使用数据库来存储以下内容: 工作流定义 当前运行的工作流实例,包括实例的状 ...

  3. oozie4.3.0的安装与配置 + hadoop2.7.3

    安装步骤 mysql的配置 oozie的安装 oozie的配置 oozie的启动与登录 常用oozie的命令 1. mysql的配置 mysql的安装自行解决,然后在mysql上 创建oozie数据库 ...

  4. 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. ...

  5. 【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 ...

  6. CentOS 7.0下使用yum安装MySQL

    CentOS7默认数据库是mariadb,配置等用着不习惯,因此决定改成mysql,但是CentOS7的yum源中默认好像是没有mysql的.为了解决这个问题,我们要先下载mysql的repo源. 1 ...

  7. (转)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 ...

  8. (0)linux下的Mysql安装与基本使用(编译安装)

    一.大致操作步骤 环境介绍: OS:center OS6.5 mysql:5.6版本 1.关闭防火墙 查看防火墙状态:service iptables status 这样就意味着没有关闭. 运行以下命 ...

  9. 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. ...

随机推荐

  1. 初始小R-安装启动与测试

    非常感谢<深入浅出数据分析>这本书让我有幸认识了R,多多少少的弥补了我心里对R语言.R分析.R工具的模糊认知,下面我们就来体验一下R语言的魅力吧!GO! 一:下载R R官方地址:http: ...

  2. Dragon of Loowater

    option=com_onlinejudge&Itemid=8&page=show_problem&problem=2267" style="color:b ...

  3. DIV CSS布局中绝对定位和浮动用法

    转自:http://developer.51cto.com/art/201009/223337_1.htm 你对DIV CSS布局中绝对定位和浮动的概念及使用是否熟悉,这里和大家分享一下,CSS中,实 ...

  4. JavaScript 正则表达式——基本语法(2)

    来源:http://www.cnblogs.com/dolphinX/p/3486214.html 定义 JavaScript种正则表达式有两种定义方式,定义一个匹配类似 <%XXX%>  ...

  5. cscope无法索引代码树之外的软链接

    http://blog.csdn.net/sudolee/article/details/9052291 背景:为什么非要使用cscope?不用ctags? 尽管ctags可以索引软链接,但是,cta ...

  6. LeetCode_Path Sum

    一.题目 Path Sum My Submissions Given a binary tree and a sum, determine if the tree has a root-to-leaf ...

  7. Python 创建特殊元组tuple

    创建1个元素的tuple  (1,) 创建单元素tupletuple和list一样,可以包含 0 个.1个和任意多个元素.包含多个元素的 tuple,前面我们已经创建过了.包含 0 个元素的 tupl ...

  8. leetCode(29):Happy Number

    Write an algorithm to determine if a number is "happy". A happy number is a number defined ...

  9. 【Linux】(2013-7-19)配置tftp与开发板传送文件

    1. 安装必须软件 sudo apt-get install -y xinetd tftp-hpa 2. 修改配置文件 vi /etc/default/tftpd-hpa # /etc/default ...

  10. Maven + Apache Felix + CXF + DOSGi series

    This is a blog series on how to combine Maven + Apache Felix + CXF + DOSGi. The information presente ...