使用 Java 写了一个 UDF,然后添加到 Hive 临时函数,运行下面语句可以正常使用
select func_name(xxx) from table_name where xx
但是假如使用下面语句就会提示 java.lang.NoClassDefFoundError 错误
select count(*) from table_name where func_name(xxx)=xxx
或
select count(func_name(xxx)) from table_name
错误提示如下:
Caused by: java.lang.RuntimeException: Map operator initialization failed
at org.apache.hadoop.hive.ql.exec.tez.MapRecordProcessor.init(MapRecordProcessor.java:293)
at org.apache.hadoop.hive.ql.exec.tez.TezProcessor.initializeAndRunProcessor(TezProcessor.java:171)
... 14 more
Caused by: org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.NoClassDefFoundError: org/bouncycastle/jce/provider/BouncyCastleProvider
at org.apache.hadoop.hive.ql.exec.FilterOperator.initializeOp(FilterOperator.java:73)
at org.apache.hadoop.hive.ql.exec.vector.VectorFilterOperator.initializeOp(VectorFilterOperator.java:71)
at org.apache.hadoop.hive.ql.exec.Operator.initialize(Operator.java:355)
at org.apache.hadoop.hive.ql.exec.Operator.initialize(Operator.java:504)
at org.apache.hadoop.hive.ql.exec.Operator.initializeChildren(Operator.java:457)
at org.apache.hadoop.hive.ql.exec.Operator.initialize(Operator.java:365)
at org.apache.hadoop.hive.ql.exec.MapOperator.initializeMapOperator(MapOperator.java:498)
at org.apache.hadoop.hive.ql.exec.tez.MapRecordProcessor.init(MapRecordProcessor.java:262)
... 15 more
Caused by: java.lang.NoClassDefFoundError: org/bouncycastle/jce/provider/BouncyCastleProvider
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.apache.hadoop.hive.ql.udf.generic.GenericUDFBridge.getUdfClass(GenericUDFBridge.java:130)
at org.apache.hadoop.hive.ql.exec.FunctionRegistry.isStateful(FunctionRegistry.java:1352)
at org.apache.hadoop.hive.ql.exec.ExprNodeGenericFuncEvaluator.<init>(ExprNodeGenericFuncEvaluator.java:110)
at org.apache.hadoop.hive.ql.exec.ExprNodeEvaluatorFactory.get(ExprNodeEvaluatorFactory.java:51)
at org.apache.hadoop.hive.ql.exec.ExprNodeGenericFuncEvaluator.<init>(ExprNodeGenericFuncEvaluator.java:100)
at org.apache.hadoop.hive.ql.exec.ExprNodeEvaluatorFactory.get(ExprNodeEvaluatorFactory.java:51)
at org.apache.hadoop.hive.ql.exec.FilterOperator.initializeOp(FilterOperator.java:65)
... 22 more
开始是 MapReduce 引擎,后来尝试换到 Tez,都是同样到错误,哪位遇到过这种问题,求解答。
UDF的jar包使用下面命令生成的:
javac -classpath xxx.jar:yyy.jar zzz.java
jar cvf zzz.jar zzz.class
生成的jar包没有包含用到的 xxx.jar yyy.jar这些第三方包
1
qiyuey 2017-09-19 19:29:20 +08:00
检查依赖是否缺失
|
2
oaix 2017-09-19 21:33:15 +08:00
是不是第三方的包没打到 jar 里面?
如果用 gradle,使用 https://github.com/johnrengelman/shadow 这个插件打包。 如果用 maven,用这个: https://github.com/johnrengelman/shadow |
3
linuxchild OP |
4
linuxchild OP @oaix 同时编译的时候已经指定了使用的 jar 包
|
5
linuxchild OP @qiyuey 依赖缺失会存在部分命令可执行的情况么?刚接触 Hive 和 Java 这些,有点迷糊
|
6
oaix 2017-09-20 20:38:17 +08:00
@linuxchild 所以你需要使用我上面说的插件来把第三方包都打到 jar 包里面。
|
7
linuxchild OP @oaix 话说使用 eclipse 打了一个 jar 包,也不行 - -
|