Hive执行脚本时传参

使用-hiveconf传参

测试脚本

-- test.sql

select 'Start Testing ...';

select ${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’,导致解析错误。

因此,字符型参数传参时,在脚本中必须加引号(如’${hiveconf:url}’),才能正确获得参数。


其他方法{待更新}

参考

Hive脚本接受参数

猜你喜欢

转载自blog.csdn.net/u014203453/article/details/81111144