sqoop导数

#!/bin/bash

source ExitCodeCheck.sh
opts=$@
getparam(){
echo $opts|xargs -n1|cut -b 2-|awk -v arg=$1 -F'=' '$1==arg{print $2}'
}

IncStart=`getparam inc_start`
IncEnd=`getparam inc_end`
db_connection=`getparam jdbc_str`
db_username=`getparam db_user`
db_password=`getparam db_psw`
dataName=`getparam db_sid`
queueName=`getparam hdp_queue`
hdfshostname=`getparam hdfs_host`
hduser=`getparam hdp_user_name`

IncStartYear=${IncStart:0:4}
IncStartMonth=${IncStart:4:2}
IncStartDay=${IncStart:6:2}
IncStartAll=${IncStartYear}"-"${IncStartMonth}"-"${IncStartDay}" 00:00:00.0"
IncEndYear=${IncEnd:0:4}
IncEndMonth=${IncEnd:4:2}
IncEndDay=${IncEnd:6:2}
IncEndAll=${IncEndYear}"-"${IncEndMonth}"-"${IncEndDay}" 00:00:00.0"
IncStartFormat=${IncStartYear}"-"${IncStartMonth}"-"${IncStartDay}

job_name=${0}_$$

hive_db_name=sx_bdp_smdb_safe
hive_db_user=hduser1519

#源表
src_table=smdbwsdata.ashareblocktrade
#初始化临时表
idld_table=idld_smdbds_ashareblocktrade
#目标表
hive_table=bas_smdbds_ashareblocktrade
#导出临时目录
target_dir=/apps-data/${hive_db_user}/${hive_db_name}/import/${idld_table}
#支持二次运行
if [[ $target_dir =~ ^/apps-data/${hive_db_user}/${hive_db_name}/import/[a-zA-Z0-9_]+ ]];then
hadoop fs -rm -r $target_dir
fi

sqoop import -D mapred.job.queue.name=${queueName} -D mapred.job.name=${job_name} \
--connect ${db_connection} \
--username ${db_username} \
--password ${db_password} \
--query "
select
object_id
,s_info_windcode
,trade_dt
,s_block_price
,s_block_volume
,s_block_amount
,crncy_code
,s_block_buyername
,s_block_sellername
,s_block_frequency
,opdate
,opmode
,created_by
,created_date
,updated_by
,updated_date
,'hduser1519' creator
,sysdate cdate
,'hduser1519' updator
,sysdate udate
from $src_table
where 1=1 and \$CONDITIONS
" \
-m 1 \
--hive-table ${hive_db_name}.${idld_table} \
--hive-drop-import-delims \
--fetch-size 5000 \
--target-dir "${target_dir}" \
--hive-overwrite \
--null-string '\\N' \
--null-non-string '\\N' \
--hive-import;

exitCodeCheck $?

hive -v -e "
use ${hive_db_name};
set mapred.job.queue.name=${queueName};
set mapred.job.name=${job_name};


insert overwrite TABLE ${hive_db_name}.${hive_table}
select
object_id
,s_info_windcode
,trade_dt
,s_block_price
,s_block_volume
,s_block_amount
,crncy_code
,s_block_buyername
,s_block_sellername
,s_block_frequency
,opdate
,opmode
,created_by
,created_date
,updated_by
,updated_date
,creator
,cdate
,updator
,udate
from ${hive_db_name}.$idld_table
;

"
exitCodeCheck $?

转载于:https://www.cnblogs.com/koushr/p/9483777.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值