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数据库的通用程序(二)的更多相关文章
- hive表增量抽取到oracle数据库的通用程序(一)
hive表增量抽取到oracle数据库的通用程序(二) sqoop在export的时候 只能通过--export-dir参数来指定hdfs的路径.而目前的需求是需要将hive中某个表中的多个分区记录一 ...
- hive表增量抽取到mysql(关系数据库)的通用程序(三)
hive表增量抽取到oracle数据库的通用程序(一) hive表增量抽取到oracle数据库的通用程序(二) 这几天又用到了该功能了,所以又改进了一版,增加了全量抽取和批量抽取两个参数.并且可以设置 ...
- Oracle数据库基础入门《二》Oracle内存结构
Oracle数据库基础入门<二>Oracle内存结构 Oracle 的内存由系统全局区(System Global Area,简称 SGA)和程序全局区(Program Global Ar ...
- 细说Oracle数据库与操作系统存储管理二三事
在上大学的时候,学习操作系统感觉特别枯燥,都是些条条框框的知识点,感觉和实际应用的关联不大.发现越是工作以后,在工作中越想深入了解,发现操作系统知识越发重要.在实践中结合理论还是不错的一种学习方法.自 ...
- 在.NET开发面向Oracle数据库的应用程序
其实这个不是一个什么新的话题.但是之前在多次项目中,总是遇到大家针对Oracle数据库的访问时,会有各种各样的问题,最基本的就是要在客户端安装各种client,版本不一样的话还有各种问题. 静下心来看 ...
- oozie4.3.0+sqoop1.4.6实现mysql到hive的增量抽取
1.准备数据源 mysql中表bigdata,数据如下: 2. 准备目标表 目标表存放hive中数据库dw_stg表bigdata 保存路径为 hdfs://localhost:9000/user/h ...
- 一条sql,有分页,表合并查询,多表连接,用于oracle数据库
SELECT * FROM ( SELECT TT.*,ROWNUM RN FROM ( SELECT A.CASE_ID AS TREATID, A.TYPE AS TYPE, B.CONTENT ...
- Java连接Oracle数据库开发银行管理系统【二、设计篇】
一.总体分析 此系统的实现并不难,但是如何更好的设计出实现方式还是需要更深入的分析,例如:如果再增加其他功能,是不是需要变动的 代码很少,只是直接再增加一点功能就可以了呢?如果使用的不是Ora ...
- Oracle数据库操作---基础使用(二)
此篇承接上一篇的基本原理,继续展开学习,本篇主要面向数据的使用和管理,也就是开发者常用的基础语句,开始喽…… >>>对整表的操作 >创建表 关键字 Create creat ...
随机推荐
- linux 调用shell脚本传参
例子: boolean execResult = true; BufferedReader br = null; try { //lin ...
- 【转载】linux 测试机器端口连通性方法
转载原文:http://blog.csdn.net/z1134145881/article/details/54706711 下面一一介绍: 1 telnet方法 2 wget方法 3 ssh方法 4 ...
- Android长度单位详解(dp、sp、px、in、pt、mm、dip)
Android中定义的dimension单位有以下这些:px(Pixels ,像素):对应屏幕上的实际像素点.in(Inches ,英寸):屏幕物理长度单位.mm(Millimeters ,毫米):屏 ...
- css 温故而知新 字体方向 将文字竖着显示
writing-mode: vertical-rl;
- YMP运行初始化步骤
, Version.VersionType.Release); private static final Log _LOG = LogFactory.getLog(YMP.class); privat ...
- SQL Server中判断字符串出现的位置及字符串截取
首先建一张测试表: )); insert into teststring values ('张三,李四,王五,马六,萧十一,皇宫'); 1.判断字符串中某字符(字符串)出现的次数,第一次出现的位置最后 ...
- MySQL update 语句与标准SQL不同的地方
[SQL标准中有一个叫同时执行的概念] 同时执行指的是在同一个子句中的各个部分的执行时机是不区分先后的,如下面的SQL语句 ),); +---------+--------+ ) ) | +----- ...
- C++ smart pointer智能指针
在C++中,程序员可以直接操作内存,给编程增加了不少的灵活性.但是灵活性是有代价的,程序员必须负责自己负责释放自己申请的内存,否则就会出现内存泄露.智能指针就是为了解决这个问题而存在的.它和其他指 ...
- JDK1.5新特性,基础类库篇,XML增强
Document Object Model (DOM) Level 3 文件对象模型(Document Object Model,简称DOM),是W3C组织推荐的处理可扩展置标语言的标准编程接口.DO ...
- Android 源码解析:单例模式-通过容器实现单例模式-懒加载方式
本文分析了 Android 系统服务通过容器实现单例,确保系统服务的全局唯一. 开发过 Android 的用户肯定都用过这句代码,主要作用是把布局文件 XML 加载到系统中,转换为 Android 的 ...