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. document.getElementsByName和document.getElementById用法

    本文的问题在国外的一个网站得到了答案http://stackoverflow.com/questions/11235409/no-getelementbyid-for-body document.bo ...

  2. (剑指Offer)面试题49:把字符串转换为整数

    题目: 将一个字符串转换成一个整数,要求不能使用字符串转换整数的库函数. 思路: 考虑+.-.空格.非数字字符,以及溢出问题 代码: #include <iostream> using n ...

  3. 免费资源:Bootstrap开发的创意模板

    在线演示 免费下载 一套免费的Bootstrap网站模板,使用现代的布局并支持响应式.拥有非常棒的CSS3动画效果及其滚动效果.

  4. android中listview点击事件失效的灵异事件

    首先说明一下我想实现的功能: 点击某个item之后,让其颜色发生变化.如果变化网上有很多例子,我就不班门弄斧了.Listview之所以点击没有反应是因为上图中绿色部分(自己定义的一个继承BaseAda ...

  5. C 语言-HelloWorld

    C 语言-HelloWorld C 语言是一种通用的.面向过程式的计算机程序设计语言.1972 年,为了移植与开发 UNIX 操作系统,丹尼斯·里奇在贝尔电话实验室设计开发了 C 语言. C 语言是一 ...

  6. Linux系统登录:本地登录与远程登录

    安装登录系统的位置可以将登录方式分为两种:本地登录和远程登录.本地登录可以使用图形界面和命令行模式(也称字符界面)两种方式:远程登录可以使用SSH.Telnent.VNC.SFTP 4种方式. 常见的 ...

  7. OpenERP Web Client设置闲置有效时间

    在Web Client端使用OpenERP时,默认的cookie有效时间是浏览器的当前作业窗口,这样就是说只要你不关闭浏览器,不管闲置多长时间,当前的连线都是有效的.这样就会有安全问题,如果你忘了登出 ...

  8. 02-maven常用命令,以及使用命令创建目录

    maven常用命令 mvn  -v 查看maven版本 compile 编译 test 测试 package 打包 clean 删除target install  安装jar包到本地仓库中. mave ...

  9. CentOS7——gitlab本地git仓库搭建 以及web hook配置

    整个搭建用的都是各种默认设置,所以没有用到高深的的东西,比较简单,比较傻瓜式,这篇也仅仅是一个入门. 另外本文具有时效性,浏览本文请注意发表时间,为防止过时产生误导,本文尽量把 “如何得知应该这样做” ...

  10. oracle中如何设置主键并且让其自动增长

    由于oracle中是没有自动增长的的,需要自己去进行写触发器等方式去进行设置: 找了一下他人写的,有两种方法可以设置主键,一种是自增长主键,另一种就是生成唯一序列. 一.自增长主键 我创建一个用户的信 ...