问题分析
问题:自定义hive udf执行运行udf函数出现错误。主要原因是okhttp3无法进行初始化
排查问题的思路:okhttp3包冲突或者版本引起的
可能性分析:
- jar包中多版本冲突,idea中使用dependency analyzer分析。如果存在多个版本,exclude多余的版本。
- 运行环境中存在okhttp3冲突,比如我这边出现的主要原因:udf使用spark运行,运行环境中存在okhttp3导致冲突,解决方案:使用maven-shade-plugin将本地引用的okhttp3包重新命名。例如:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<configuration>
<shadedClassifierName>shaded</shadedClassifierName>
<shadedArtifactAttached>true</shadedArtifactAttached>
<relocations combine.children="append">
<relocation>
<pattern>okhttp3</pattern>
<shadedPattern>test.okhttp3</shadedPattern>
</relocation>
<relocation>
<pattern>okio</pattern>
<shadedPattern>test.okio</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>