使用-hiveconf传参:
测试脚本
– test.sql
select ‘Start Testing …’;
select
h
i
v
e
c
o
n
f
:
d
a
y
,
′
{hiveconf:day}, '
hiveconf:day,′{hiveconf:url}’;
select ‘Test End!’;
命令行:
hive -hiveconf day=20180716 -hiveconf url=‘www.baidu.com’ -S -f test.sql
结果
Start Testing …
20180716 www.baidu.com
Test End!
注意
hive -hiveconf day=‘monday’ -hiveconf url=‘www.baidu.com’ -S -f test.sql
运行上述命令,会报如下错误:
Start Testing …
FAILED: SemanticException [Error 10004]: Line 3:7 Invalid table alias or column reference ‘monday’: (possible column names are: )
其原因在于,sql脚本中的${hiveconf:day}没有加引号,即day默认为数字型参数。然而,上述命令传入了字符型参数day=’monday’,导致解析错误。