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. unity, ugui toggle, dynamic bool

    假设Canvas_debugControl.cs有一个函数 public void showNextSceneButton(bool value){ ... } 欲将其添加到一个ugui toggle ...

  2. mysql性能测试(索引)

    首先,使用Talend随机生成一千万条数据: 数据库表中现在有1千万+的数据: mysql> select count(*) from zhangchao; +----------+ | cou ...

  3. InlineModelAdmin

    参考博客:https://www.cnblogs.com/linxiyue/p/4074562.html

  4. KMP算法理解

    1.KMP算法解决问题:对BF(Brute Force)算法优化,避免对主串进行回溯匹配(匹配不成功主串指针向后移1位,子串指针重置开始位置,两串继续匹配),效率底. 2.KMP算法原则/目的:主串不 ...

  5. 使用ASIHTTPRequest和ASIDownloadCache实现本地缓存

    源码:http://files.cnblogs.com/ios8/ASIHttpRequestDemo2.zip NSURL *url = [NSURLURLWithString:@"htt ...

  6. 【Unity】5.1 3D坐标系基础知识

    分类:Unity.C#.VS2015 创建日期:2016-04-20 一.简介 在虚拟的游戏世界中,与3D有关的数学知识决定了游戏引擎如何计算和模拟出开发者以及玩家看到的每一帧画面.学习或者回想一下基 ...

  7. Warning Template OS Linux: /etc/passwd has been changed on {HOST.NAME} {monitor:vfs.file.cksum[/etc/passwd].diff(0)}>0 Unknown

    # ll -h /etc/passwd -rw-r--r-- 1 root root 1.5K Apr 15 16:10 /etc/passwd 让zabbix 可以登录服务器 # mkdir /ho ...

  8. Dubbo实践笔记

    注意的地方 默认情况下,cluster=failover.retries=2,意为失败重试两次,不包含原生调用.如需配置不重试,需设置retries=-1,或者使用failfast(快速失败)模式 如 ...

  9. uWSGI listen queue 队列溢出的问题

    如果没有设置uwsgi的--listen,如果sysctl -a | grep net.core.somaxconn发现net.core.somaxconn=128. 那你使用uwsgi启动的服务,单 ...

  10. Windows下GUI编程——窗口

    windows下创建一个基于GUI的窗口程序很简单,使用MFC或者Win32 API都可以实现.本文简单整理下windows API创建GUI应用程序的基本编码框架. 比较常见的窗口包括:桌面窗口.应 ...