hive 脚本传参

hive 脚本传参

20190909


向hive脚本中传入参数,两种情况:

一、shell脚本调度hive脚本, hive可以直接读取系统变量和环境变量

  • hive脚本
--#test.sql
use huh;
select '${env:month}' as month from table_name;
  • 脚本传参
--#start.sh
#!/bin/sh
set -x
export month=`date -d 'last month' +%Y-%m`
hive -f test.sql

二、使用-hivevar 和 -hiveconf 两种参数选项

  • hive脚本
-- #test.sql
use huh;
select '${hiveconf:month}' as month from table_name;
#select '${hivevar:month}' as month from table_name;
  • 脚本传参
--#start.sh
#!/bin/sh
set -x
month=`date -d 'last month' +%Y-%m`
hive -hiveconf month=$month -f test.sql
#hive -hivevar month=$month -f test.sql

未完。。。

参考文献

CSDN-参考1

原文地址:https://www.cnblogs.com/damahuhu/p/11675593.html