怎樣在Spark、Flink應用中使用Protobuf 3的包


如果在在Spark、Flink應用中使用Protobuf 3的包,因為Spark默認使用的是2.5版本的包,提交任務時,可能會報如下異常:

com.google.protobuf.CodedInputStream.readStringRequireUtf8()Ljava/lang/String;

針對Spark,可以使用SPARK_CLASSPATH或是指定

--conf spark.executor.extraClassPath

的方式解決,今天在調試Flink程序時,發現還有一種解決方式:

https://maven.apache.org/plugins/maven-shade-plugin/examples/class-relocation.html

If the uber JAR is reused as a dependency of some other project, directly including classes from the artifact's dependencies in the uber JAR can cause class loading conflicts due to duplicate classes on the class path. To address this issue, one can relocate the classes which get included in the shaded artifact in order to create a private copy of their bytecode:

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>com.google.protobuf</pattern>
<shadedPattern>shaded.com.google.protobuf</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM