shell脚本执行hive命令传值给sql文件、shell传参

使用场景,大数据平台azkaban任务中通过shell脚本调用sql文件(尤其是调用多个sql时),希望可以传参到sql文件中

方法:本例以sh调用hive命令执行sql为例,道理相同

1、sh 文件中执行hive -f 命令 将inputdate传给sql文件使用 如下

hive -hiveconf input_date=`date +%Y-%m-%d` -f dm_f_count_assigned_user.sql

sh中 用 -hiveconf input_date=`date +%Y-%m-%d` 这个变量去传值

如果此处执行多次语句 也可以将input_date 作为变量提出来

2、sql文件 获取input_date

ALTER TABLE hive_dm.dm_f_count_assigned_user DROP IF EXISTS PARTITION (date_calculated='${hiveconf:input_date}');

sql中 用' ${hiveconf:input_date}' 来接收

提示,可以同时传多个值

      -hiveconf input_date=`date +%Y-%m-%d`

      -hiveconf usename=`groot`

      -hiveconf password=`qwertyu596`

取值

     '${hiveconf:input_date}'

     '${hiveconf:usename}'

     '${hiveconf:password}'

此处取值使用了 单引号,因为我想要字符串类型的值,也是大家最常用的。根据个人需要吧,如果你传的是int类型,取值时不使用单引号,应该可以直接取到int类型,直接进行大小比较,计算之类的。。。哈哈  这个没去细细研究。

猜你喜欢

转载自blog.csdn.net/CaptainJava/article/details/82253656