hive表增量抽取到oracle数据库的通用程序(二)
2023-09-14 08:57:20 时间
前一篇介绍了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报表系统中。
相关文章
- Oracle正则表达式中文书写实战(oracle正则匹配中文)
- Oracle增加效率:节省时间(oracle加时间)
- Oracle数据库的转换之路(oracle转换)
- 解决Oracle文件过大的方法(oracle文件太大)
- Oracle财务软件:管理企业财务数据的最佳选择(oracle财务软件)
- 如何在Oracle中实现字段相减操作(oracle字段相减)
- 解读甲骨文Oracle:掌握未来商业智慧的秘诀(甲骨文oracle)
- Oracle服务器时间:确保您的数据和应用程序一致性(oracle服务器时间)
- Oracle数据库免费使用吗(oracle免费使用吗)
- Oracle数据库深度连接JavaScript的突破(js oracle数据库)
- 4063 Oracle突破技术界限的数据库管理系统(4063 oracle)
- 伪列在Oracle数据库中的应用(oracle中的伪列)
- Oracle中优化游标使用的必要步骤(oracle中游标优化)
- Oracle数据库中两用户之间的相互访问(oracle两用户之间相互访问)
- 错误排查Oracle数据库1067错误症状及解决方案(oracle不能1067)
- Oracle编程语言让数据库功能更强大(oracle_lang)
- Oracle UTS最全面的数据库管理解决方案(oracle uts)
- Oracle 8i 快速开启数据库之旅(oracle 8i 启动)
- 新纪元Oracle 12c开启数据库新纪元(oracle 12c打开)
- 应用发挥最大效能Oracle 11g有效推动应用的发展(oracle 11g 让)