1、使用说明
查询脚本[select_statement.sql]:
select * from dwt.dwt_asset_coupon_use_incr_1d where dt='${hiveconf:dt}' limit 10;
使用范例:
hive -hiveconf dt='2019-10-17' -f select_statement.sql
2、跑批shell脚本及其他
2.1、调用的shell脚本
/home/hadoop/moveBat/moveBat.sh
#/bin/bash
echo "要跑数的日期:$1";
/usr/local/service/hive/bin/hive -hiveconf dt="$1" -f /home/hadoop/moveBat/scriptDir/partition_add.sql
/usr/local/service/hive/bin/hive -hiveconf dt="$1" -f /tmp/20191017-19-dde2/xxmove_nisj_dwt_product_dispute_incr_1d.sql
/usr/local/service/hive/bin/hive -hiveconf dt="$1" -f /tmp/20191017-19-dde2/xxmove_nisj_dwt_trade_delivery_base_incr_1d.sql
/usr/local/service/hive/bin/hive -hiveconf dt="$1" -f /tmp/20191017-19-dde2/xxmove_nisj_dwt_trade_delivery_base_incr_20d.sql
/usr/local/service/hive/bin/hive -hiveconf dt="$1" -f /tmp/20191017-19-dde2/xxmove_nisj_dwt_trade_return_goods_incr_1d.sql
2.2、查询及执行的sql脚本示例
[hadoop@10 scriptDir]$ cat /home/hadoop/moveBat/scriptDir/partition_add.sql
alter table tmp.dwt_trade_return_goods_incr_1d drop if exists partition (dt='${hiveconf:dt}');
alter table tmp.dwt_product_dispute_incr_1d drop if exists partition (dt='${hiveconf:dt}');
alter table tmp.dwt_trade_delivery_base_incr_1d drop if exists partition (dt='${hiveconf:dt}');
alter table tmp.dwt_trade_delivery_base_incr_20d drop if exists partition (dt='${hiveconf:dt}');
alter table tmp.dwt_trade_return_goods_incr_1d add partition (dt='${hiveconf:dt}');
alter table tmp.dwt_product_dispute_incr_1d add partition (dt='${hiveconf:dt}');
alter table tmp.dwt_trade_delivery_base_incr_1d add partition (dt='${hiveconf:dt}');
alter table tmp.dwt_trade_delivery_base_incr_20d add partition (dt='${hiveconf:dt}');
[hadoop@10 moveBat]$ cat /tmp/20191017-19-dde2/xxmove_nisj_dwt_trade_delivery_base_incr_20d.sql
--guotao
--2019-08-06
--update by nisj at 2019-10-16
--交易主题发货基础表-近20天最新的发货信息,防止修改物流单号-用于刷单
insert overwrite table tmp.dwt_trade_delivery_base_incr_20d partition(dt='${hiveconf:dt}')
select
t1.sale_id as sale_id,
t3.sale_uri as sale_uri,
t3.sale_type as sale_type,
t3.shop_id as shop_id,
t3.category_id as category_id,
t3.sec_category_id as category_id,
t3.userinfo_id as userinfo_id,
t2.delivery_code as delivery_code,
t2.delivery_com as delivery_com,
t1.delivery_time as delivery_time
from
(
select
sale_id,
delivery_time
from
dwt.dwt_trade_delivery_origin_incr_1d
where
dt<='${hiveconf:dt}' and dt >= date_sub('${hiveconf:dt}',20)
) t1
left join
(
select
t1.delivery_com as delivery_com,
t1.delivery_code as delivery_code,
t1.sale_id as sale_id
from (
select
*,
row_number() over(partition by sale_id order by mtime desc ) as rn
from(
select
get_json_object(deliveryJson, '$.com') as delivery_com,
get_json_object(deliveryJson, '$.code') as delivery_code,
saleId as sale_id,
mtime
from
sds.mysql_sale_order__sale_extend_incr_view
where
dt <= '${hiveconf:dt}' and dt >= date_sub('${hiveconf:dt}', 20)
) t
) t1
where
t1.rn = 1
) t2
on t1.sale_id = t2.sale_id
left join
(
select
*
from
dwt.dwt_trade_residue_trade_base_incr_1d
where
dt between date_sub('${hiveconf:dt}', 50) and '${hiveconf:dt}'
) t3
on t1.sale_id = t3.sale_id
2.3、脚本执行调用
nohup sh moveBat.sh 2019-10-17 &
3、注意事项及说明
向shell脚本里传入外部参数时,一定要[dt="$1"],而不能[dt='$1'];即是必须要用双引号,否则报错。
调用的时候是[sh moveBat.sh 具体日期]的形式。