hive-e封装HQL模板

 hive -e方式

hive -e "待执行sql"。这种方式允许我们在引号中写入需要执行的SQL语句。通常适合于语句较长的情况。这种方式也是在需要进行任务调度时采用的最直接方式,此时可以结合shell定义可变参数(如日期),再结合调度系统就可以实现脚本自动化。

#!/bin/bash 
ago_day=`date -d '-2days' +%Y%m%d`
hive -e "SET hive.exec.dynamic.partition.mode=nonstrict;
insert overwrite table dim.dim_sku_info_df partition(ds)
select 
C1.id,C1.spu_id,C1.price,C1.sku_name,C1.sku_desc,
C1.weight,C1.tm_id,C1.sku_default_img,C1.category3_id,C2.category2_id,
C3.category1_id,C2.name,C3.name,C4.name,C1.create_time,C1.ds 
from ods.ods_sku_info_df C1 
join ods.ods_base_category3_df  C2 on C1.id =C2.id 
join ods.ods_base_category2_df  C3 on C1.id =C3.id 
join ods.ods_base_category1_df  C4 on C1.id =C4.id
where C1.ds=${ago_day} and C1.id is not null;"


hive -e "SET hive.exec.dynamic.partition.mode=nonstrict;
insert overwrite table dim.dim_user_info_df partition(ds)
select 
id,login_name,nick_name,passwd,name,phone_num,
email,head_img,user_level,birthday,gender,create_time,ds 
from ods.ods_user_info_df where ds=${ago_day} and id is not null;"


hive -e "SET hive.exec.dynamic.partition.mode=nonstrict;
insert overwrite table dim.dim_base_province_df partition(ds)
select 
C1.id,C1.name,C1.region_id,C2.region_name,C1.area_code,C1.ds 
from ods.ods_base_province_dd  C1 
join ods.ods_base_region_dd C2 on C1.region_id = C2.id
where C1.ds=${ago_day} and C1.id is not null;"

你可能感兴趣的:(shell,sql)