實現Hive資料同步更新的shell指令碼

來源:互聯網
上載者:User

實現Hive資料同步更新的shell指令碼
引言:上一篇文章《Sqoop1.4.4 實現將 Oracle10g 中的增量資料匯入 Hive0.13.1 ,並更新Hive中的主表》描述了累加式更新Hive表的原理和Sqoop,Hive命令,本文基於上一篇文章的內容實現了shell指令碼的編寫,稍加修改就可用於實際工程。 shell指令碼 #!/bin/bash #Please set the synchronize interval,unit is hour.update_interval=24 #Please set the RDBMS connection paramsrdbms_connstr="jdbc:oracle:thin:@192.168.0.147:1521:ORCLGBK"rdbms_username="SP"rdbms_pwd="fulong"rdbms_table="OMP_SERVICE"rdbms_columns="ID,SERVICE_NAME,SERVICE_PROCESS,CREATE_TIME,ENABLE_ORG,ENABLE_PLATFORM,IF_DEL" #Please set the hive paramshive_increment_table="SERVICE_TMP"hive_full_table="service_all" #--------------------------------------------------------- #Import icrement data in RDBMS into Hiveenddate=$(date '+%Y/%m/%d %H:%M:%S')startdate=$(date '+%Y/%m/%d %H:%M:%S' -d '-'+${update_interval}+' hours') $SQOOP_HOME/bin/sqoop import --connect ${rdbms_connstr} --username ${rdbms_username} --password ${rdbms_pwd} --table ${rdbms_table} --columns "${rdbms_columns}" --where "CREATE_TIME > to_date('${startdate}','yyyy-mm-dd hh24:mi:ss') and CREATE_TIME < to_date('${enddate}','yyyy-mm-dd hh24:mi:ss')" --hive-import --hive-overwrite --hive-table ${hive_increment_table} #--------------------------------------------------------- #Update the old full data table to latest status$HIVE_HOME/bin/hive -e "insert overwrite table ${hive_full_table} select * from ${hive_increment_table} union all select a.* from ${hive_full_table} a left outer join ${hive_increment_table} b on a.service_code = b.service_code where b.service_code is null;"

注意:在shell指令碼中執行hive hql的命令格式是  hive -e "select ..."Cron指令碼添加定時任務每天淩晨2點執行該指令碼0 2 * * * /home/fulong/shell/dataSync.sh

基於Hadoop叢集的Hive安裝

Hive內表和外表的區別

Hadoop + Hive + Map +reduce 叢集安裝部署

Hive本地獨立模式安裝

Hive學習之WordCount單詞統計

Hive運行架構及配置部署

Hive 的詳細介紹:請點這裡
Hive 的:請點這裡

本文永久更新連結地址:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.