无法在 hive 服务器上运行 UDF
我在节俭服务器模式下运行配置单元。我在 jar 文件中有一个 UDF,我尝试通过运行来使用它
add jar <path to jar>
create temporary function func_name as 'com.test.udf.UDF_CLASS'
但是,当我运行 create tempor function 命令时,出现错误
查询返回非零代码:9,原因:FAILED:执行错误, 从 org.apache.hadoop.hive.ql.exec.FunctionTask 返回代码 1
我已经检查过名称 & jar 的路径,并且运行 hive 服务器的用户具有访问该 jar 的所有正确权限。奇怪的是,如果我在 CLI 模式下运行 hive 并运行完全相同的命令,那么一切都会正常。关于为什么 hive CLI 的行为可能与 hive thrift 服务器不同的任何想法?
I'm running hive in thrift server mode. I have a UDF in a jar file that I'm trying to use by running
add jar <path to jar>
create temporary function func_name as 'com.test.udf.UDF_CLASS'
However, when I run the create temporary function command I get an error
Query returned non-zero code: 9, cause: FAILED: Execution Error,
return code 1 from org.apache.hadoop.hive.ql.exec.FunctionTask
I've checked that the name & path of the jar and that the user running the hive server has all the correct permissions to access the jar. What is weird is if I run hive in CLI mode and run the exact same commands, then everything works. Any ideas on why hive CLI may be behaving differently from the hive thrift server?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您还可以通过将 --auxpath 选项传递给 hive 命令来完成
hive --auxpath /path-to-/hive-examples.jar
或
通过设置 HIVE_AUX_JARS_PATH 环境变量。
You can also do by passing the --auxpath option to the hive command
hive --auxpath /path-to-/hive-examples.jar
or
by setting the HIVE_AUX_JARS_PATH environmental varialble.
在玩了一段时间后,我通过将 .class 文件放入与其包匹配的目录结构中,然后将其添加到 .jar 中,使其正常工作。作为参考,我已经包含了整个过程,包括编译和插入到配置单元中。
javac -classpath $ CLASSPATH Lower.java
。注意:CLASSPATH 的定义如下: CLASSPATH=$(ls $HIVE_HOME/lib/hive-serde-*.jar):$(ls $HIVE_HOME/lib/hive-exec-*.jar) :$(ls $HADOOP_HOME/hadoop-core-*.jar),如所述此处.jar -cf lower.jar com/example/hive/udf/Lower.class
jar -tf lower.jar
。您应该看到如下行:com/example/hive/udf/Lower.class
。添加jar lower.jar;创建临时函数 my_lower 作为 'com.example.hive.udf.Lower';
After playing with this for awhile I got it to work by putting the .class file into a directory structure that matches it's package, and adding it to the .jar from there. For reference I've included the whole process, including compiling and inserting into hive.
javac -classpath $CLASSPATH Lower.java
. Note: the CLASSPATH was defined like this:CLASSPATH=$(ls $HIVE_HOME/lib/hive-serde-*.jar):$(ls $HIVE_HOME/lib/hive-exec-*.jar):$(ls $HADOOP_HOME/hadoop-core-*.jar)
, as described here.jar -cf lower.jar com/example/hive/udf/Lower.class
jar -tf lower.jar
. You should see a line like this:com/example/hive/udf/Lower.class
.add jar lower.jar; create temporary function my_lower as 'com.example.hive.udf.Lower';
使用以下步骤修复了该问题:
1) 将每个 UDF jar 放入 /usr/lib/hive/auxlib
2) 在 hive-site.xml 中为 hive.aux.jars.path 属性指定每个 jar 的路径(例如: file:///usr/lib/hive/auxlib/jar1.jar,file:///usr/lib/hive/auxlib/jar2.jar)
3) 创建脚本向 hive 服务器发出 thrift 请求来运行创建临时的hive 服务器启动后,每个 UDF 的 function func_name as 'com.test.udf.ClassName'
编辑:对于 Hive 0.9,无论我做什么,Hiveserver 都无法在 auxlib 目录中找到 jar。为了让它在 Hiveserver 0.9 上工作,我必须将 jar 转储到 Hive 类路径指定的目录中。
Fixed the problem using the following steps:
1) Place each UDF jar in /usr/lib/hive/auxlib
2) Specify the path to each jar in hive-site.xml for the hive.aux.jars.path property (ex: file:///usr/lib/hive/auxlib/jar1.jar,file:///usr/lib/hive/auxlib/jar2.jar)
3) Create a script to make a thrift request to the hive server to run create temporary function func_name as 'com.test.udf.ClassName' for each UDF after the hive server is started
Edit: For Hive 0.9 no matter what I did, Hiveserver couldn't find jars in the auxlib directory. To get this to work on Hiveserver 0.9 I had to just dump the jar in the directory specified by Hive's classpath.