hive表增量抽取到oracle数据库的通用程序(一)

前一篇介绍了java程序的如何编写、使用以及引用到的依赖包。这篇接着上一篇来介绍如何在oozie中使用该java程序。

在我的业务中,分为两段:

1. 查询hive表中的信息,通过oozie可以设置不同的变量作为增量查询的条件。

2. 将hive查询到的信息写入到oracle中。

对应oozie中的workflow文件如下:

<?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_${job_name}_day">
<start to="hive-node"/> <!-- 统计day: dm_guba_loginlog -->
<action name="hive-node" retry-max="10" retry-interval="3">
<hive xmlns="uri:oozie:hive-action:0.2">
<job-tracker>${jobTracker}</job-tracker>
<name-node>${nameNode}</name-node>
<job-xml>${hive_site_path}</job-xml>
<configuration>
<property>
<name>mapred.job.queue.name</name>
<value>${queueName}</value>
</property>
</configuration>
<script>script.q</script>
<param>tmp_table=tmp_dm_xxx_day</param>
<param>params_dt=${params_dt}</param>
</hive>
<ok to="java-node"/>
<error to="senderror"/>
</action> <!-- 注意:hive_hql,rdms_presql语句结尾不能使用分号 -->
<action name="java-node">
<java>
<job-tracker>${jobTracker}</job-tracker>
<name-node>${nameNode}</name-node>
<configuration>
<property>
<name>mapred.job.queue.name</name>
<value>${queueName}</value>
</property>
</configuration>
<main-class>com.exe.Hive2RMDS</main-class>
<arg>--hive_url</arg>
<arg>jdbc:hive2://xx.xx.xx.xx:10000/default</arg>
<arg>--hive_hql</arg>
<arg>select field1,field2,field3,dim,period,period_value from dw_dm.dm_xxx where period = 'day' and period_value = ${params_dt}</arg>
<arg>--rdms_driver</arg>
<arg>oracle.jdbc.driver.OracleDriver</arg>
<arg>--rdms_url</arg>
<arg>jdbc:oracle:thin:@xx.xx.xx.xx:1521:test001</arg>
<arg>--rdms_username</arg>
<arg>DW_test</arg>
<arg>--rdms_password</arg>
<arg>DW_test</arg>
<arg>--rdms_tableName</arg>
<arg>DW_DM.DM_xxx_TEST</arg>
<arg>--rdms_columnNames</arg>
<arg>field1,field2,field3,dim,period,period_value</arg>
<arg>--rdms_presql</arg>
<arg>delete from DW_DM.DM_xxx_TEST where period = 'day' and period_value = '${params_dt}'</arg> </java>
<ok to="end"/>
<error to="senderror"/>
</action>

<!--出错发送邮件 -->
<action name="senderror">
<email xmlns="uri:oozie:email-action:0.1">
<to>xxx@qq.com</to>
<subject>${job_name} log error in ${params_dt}</subject>
<body>Error: ${params_dt} ,error message[${wf:errorMessage(wf:lastErrorNode())}]</body>
</email>
<ok to="fail"/>
<error to="fail"/>
</action> <kill name="fail">
<message>workflow: ${wf:id()}, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<end name="end"/> </workflow-app>

以下为在oozie中的执行过程提示信息:

总结:

该程序相对来说比较通用,可以在导入oracle前,预先执行一段sql语句用于清除oracle中已有的记录。

通过批处理导入,执行效率比较高。

通常用于将汇总的结果导出到关系型数据库中,然后通过关系型数据库直接展示到BI报表系统中。

hive表增量抽取到oracle数据库的通用程序(二)的更多相关文章

  1. hive表增量抽取到oracle数据库的通用程序(一)

    hive表增量抽取到oracle数据库的通用程序(二) sqoop在export的时候 只能通过--export-dir参数来指定hdfs的路径.而目前的需求是需要将hive中某个表中的多个分区记录一 ...

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

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

  3. Oracle数据库基础入门《二》Oracle内存结构

    Oracle数据库基础入门<二>Oracle内存结构 Oracle 的内存由系统全局区(System Global Area,简称 SGA)和程序全局区(Program Global Ar ...

  4. 细说Oracle数据库与操作系统存储管理二三事

    在上大学的时候,学习操作系统感觉特别枯燥,都是些条条框框的知识点,感觉和实际应用的关联不大.发现越是工作以后,在工作中越想深入了解,发现操作系统知识越发重要.在实践中结合理论还是不错的一种学习方法.自 ...

  5. 在.NET开发面向Oracle数据库的应用程序

    其实这个不是一个什么新的话题.但是之前在多次项目中,总是遇到大家针对Oracle数据库的访问时,会有各种各样的问题,最基本的就是要在客户端安装各种client,版本不一样的话还有各种问题. 静下心来看 ...

  6. oozie4.3.0+sqoop1.4.6实现mysql到hive的增量抽取

    1.准备数据源 mysql中表bigdata,数据如下: 2. 准备目标表 目标表存放hive中数据库dw_stg表bigdata 保存路径为 hdfs://localhost:9000/user/h ...

  7. 一条sql,有分页,表合并查询,多表连接,用于oracle数据库

    SELECT * FROM ( SELECT TT.*,ROWNUM RN FROM ( SELECT A.CASE_ID AS TREATID, A.TYPE AS TYPE, B.CONTENT ...

  8. Java连接Oracle数据库开发银行管理系统【二、设计篇】

    一.总体分析     此系统的实现并不难,但是如何更好的设计出实现方式还是需要更深入的分析,例如:如果再增加其他功能,是不是需要变动的 代码很少,只是直接再增加一点功能就可以了呢?如果使用的不是Ora ...

  9. Oracle数据库操作---基础使用(二)

    此篇承接上一篇的基本原理,继续展开学习,本篇主要面向数据的使用和管理,也就是开发者常用的基础语句,开始喽…… >>>对整表的操作 >创建表   关键字 Create creat ...

随机推荐

  1. 替代crontab,任务计划统一集中管理系统cronsun简介

    一.背景 crontab 是 Linux 系统里面最简单易用的定时任务管理工具,相信绝大多数开发和运维都用到过.在咱们公司,很多业务系统的定时任务都是通过 crontab 来定义的,时间长了后会发现存 ...

  2. RAID简介[zz]

    RAID 0 是指磁盘分段(Disk Striping)技术其实现方法为将数据分段,同时写到多个磁盘上.其优点是磁盘可以实现并行的输入和输出,提高磁盘读写速度,但是这种技术无容错性能:RAID 1是指 ...

  3. 闭包(Closures)

    本文转自:http://goddyzhao.tumblr.com/post/11311499651/closures 翻译自:http://dmitrysoshnikov.com/ 概要 本文将介绍一 ...

  4. kibana 的search 的的搜索提示挡住输入框

    解决方案就是 [root@10-19-148-59 styles]# pwd /data/package/kibana/src/public/styles [root@10-19-148-59 sty ...

  5. Vue(五):Vue模板语法

    1.{{...}}(双大括号) 文本插值 <div id="app"> <p>{{ message }}</p> </div> 2. ...

  6. CentOS 7 安装中文环境

    centos升级到7后,系统设置好多和6有了很大的区别,中文支持就有很大的变化. 1.安装中文语言包. yum install kde-l10n-Chinese 2.安装(已经安装的要重新安装)gli ...

  7. apache-tomcat-7.0.53-windows-x86或者x64:出现错误提示:(Unable to open the service 'tomcat7)或者(Failed installing 'Tomcat7' service) tomcat7 %1 不是有效的 Win32 应用程序。

    具体 安装行动 :打开下令 行提醒 符窗口 => 进入Tomcat安装目次 ==> 进入bin目次 下==> 输入:service.bat install 即可而且tomcat_ho ...

  8. Go基础--终端操作和文件操作

    终端操作 操作终端相关的文件句柄常量os.Stdin:标准输入os.Stdout:标准输出os.Stderr:标准错误输出 关于终端操作的代码例子: package main import " ...

  9. Django使用manage.py备份与恢复数据

    Django dumpdata and loaddata django database model dumpdata dumpdata command It is a django manageme ...

  10. SSH框架整合开发具体解释(个人笔记)

    一.创建数据库并设置编码. A) create database oa default character set utf8. 二.MyEclipseproject A) 在Myeclipse里创建w ...