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. Eclipse Oxygen创建maven web项目(二)

    配置项目依赖库及第三方工具. 如示例的pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi ...

  2. SQL触发器 常用语句

    一.创建一个简单的触发器 CREATE TRIGGER 触发器名称 ON 表名 FOR INSERT.UPDATE 或 DELETE AS     T-SQL 语句 注意:触发器名称是不加引号的.   ...

  3. NTC与PTC压敏电阻在电源电路中起的作用

    https://wenku.baidu.com/view/e39beafdfab069dc502201f9.html 压敏电阻的作用 http://www.eepw.com.cn/article/27 ...

  4. ldconfig命令

    ldconfig是一个动态链接库管理命令 为了让动态链接库为系统所共享,还需运行动态链接库的管理命令--ldconfigldconfig 命令的用途,主要是在默认搜寻目录(/lib和/usr/lib) ...

  5. 三角函数 与 JavaScript

    三角函数   canvas 和 JavaScript 中所有与角相关的API如Math.sin().Math.cos().Math.tan(),都需要以弧度为单位值.但大部分人还是习惯以角度单位.所以 ...

  6. 用python参加Kaggle的经验总结【转】

    用python参加Kaggle的经验总结 转载自:http://www.jianshu.com/p/32def2294ae6,作者 JxKing    最近挤出时间,用python在kaggle上试了 ...

  7. shiro 基本认知

    1 shiro 的作用:安全.权限管理. 具有的功能:认证.授权.加密.会话管理.web集成.缓存 2 shiro 结构 3

  8. 全相FFT

    作者:桂. 时间:2017-12-02  23:29:48 链接:http://www.cnblogs.com/xingshansi/p/7956491.html 一.相位提取 以正弦信号为例,x = ...

  9. haproxy文章

    http://ximenfeibing.blog.51cto.com/8809812/1663387

  10. 【Android开发】创建你的第一个Android项目

    原文:http://android.eoe.cn/topic/summary 本文中你将了解到: 1. 使用Eclipse创建项目 2. 使用命令行创建项目 你还应该阅读: 1. 安装SDK(官网页面 ...