Hive 在Oozie工作流中运行的配置单元查询中使用用户名创建表名?

Hive 在Oozie工作流中运行的配置单元查询中使用用户名创建表名?,hive,hiveql,oozie,oozie-workflow,Hive,Hiveql,Oozie,Oozie Workflow,我有一个HiveSQL脚本/操作作为Oozie工作流的一部分。我正在创建一个表作为SELECT来输出结果。我想使用用户名加上附加字符串(例如“User123456_output_table”)来命名表,但似乎无法获得正确的语法 set tablename=${hivevar:current_user()}; CREATE TABLE `${hiveconf:tablename}_output_table` AS SELECT ... 这不起作用,会导致: Error while compili

我有一个HiveSQL脚本/操作作为Oozie工作流的一部分。我正在创建一个表作为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
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
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工作流传递用户名

我使用的是色调,而不是命令行


谢谢这是错误的:
set tablename=${hivevar:current_user()}-不会按原样解析和替换

Hive在替换之前不计算变量,它按原样替换变量,不计算变量中的所有函数。变量只是文本替换

这:

解析为

CREATE TABLE `current_user()_output_table` ...
表名中不支持函数,因此无法以这种方式工作

解决方案是计算脚本之外的函数,并将它们作为参数传递


查看此博客:

非常感谢您的帮助