Hive 参数传递
命令行模式,或者说目录模式,可以使用hive 执行命令。
选项说明:
-
-e : 执行短命令
-
-f : 执行文件(适合脚本封装)
-
-S : 安静模式,不显示MR的运行过程
-
-hivevar : 传参数 ,专门提供给用户自定义变量。
-
-hiveconf : 传参数,包括了hive-site.xml中配置的hive全局变量。
案例:脚本调用
test.sql
use default;
select
'${hiveconf:month}' as month
from default.user1;
use default;
select
'${hivevar:month}' as month
from default.user1;
#!/bin/sh
#ecoding=utf-8
set -x
month=`date -d 'last month' +%Y-%m`
hive --hiveconf month=$month -f test.sql
#!/bin/sh
#ecoding=utf-8
set -x
month=`date -d 'last month' +%Y-%m`
hive --hivevar month=$month -f test.sql
如果熟悉HIVE操作的话,这些配置属性还可以利用“set”指令进行修正,如下:
首先启动HIVE
hive
然后设置参数
set mapred.job.queue.name=root.default
上面的指令可等价于“hive --hiveconf”命令,如下:
hive --hiveconf "mapred.job.queue.name=root.default"