我有一个Hive SQL脚本/动作,作为Oozie工作流的一部分。我正在执行CREATE TABLE AS SELECT以输出结果。我想使用用户名加上附加的字符串来命名表(例如"User123456_output_table"),但似乎无法获得正确的语法。
set tablename=${hivevar:current_user()};
CREATE TABLE `${hiveconf:tablename}_output_table` AS SELECT ...
这不起作用,并给出了:
Error while compiling statement: FAILED: IllegalArgumentException java.net.URISyntaxException: Relative path in absolute URI: ${hivevar:current_user()%7D_output_table
或更改第一行以设置tablename=${current_user()};开始运行SELECT查询,但最终以以下代码停止:
Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. org.apache.hadoop.hive.ql.metadata.HiveException: [${current_user()}_output_table]: is not a valid table name
或更改第一行以设置tablename=current_user();开始运行SELECT查询,但最终以以下代码停止:
Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. org.apache.hadoop.hive.ql.metadata.HiveException: [current_user()_output_table]: is not a valid table name
或者,有没有办法通过参数从Oozie工作流中传递用户名?
我使用Hue而不是命令行来完成所有这些工作。
谢谢
发布于 2021-02-04 22:14:23
这是错误的:set tablename=${hivevar:current_user()};
-它将不会按原样被解析和替换。
Hive在替换之前不计算变量,它按原样替换它们,变量中的所有函数都不计算。变量只是文本替换。
这一点:
set tablename=current_user();
CREATE TABLE `${hiveconf:tablename}_output_table` ...
解析为
CREATE TABLE `current_user()_output_table` ...
和函数在表名中不受支持,它不会以这种方式工作。
解决方案是在脚本之外计算函数,并将它们作为参数传递。
请参阅此博客:https://prodlife.wordpress.com/2013/12/06/parameterizing-hive-actions-in-oozie-workflows/
https://stackoverflow.com/questions/66046873
复制相似问题