0

我正在尝试运行使用 Univocity CSV Parser 的 Scala Spark 作业,并且在升级以支持字符串分隔符(与仅字符)之后,当我在集群中运行我的 jar 时出现以下错误。在我的 IDEA IDE 中本地运行它会产生没有错误的预期结果。

ERROR yarn.ApplicationMaster: User class threw exception: java.lang.NoSuchMethodError: com.univocity.parsers.csv.CsvFormat.setDelimiter(Ljava/lang/String;)V
java.lang.NoSuchMethodError: com.univocity.parsers.csv.CsvFormat.setDelimiter(Ljava/lang/String;)V

我尝试了以下方法:通过检查依赖关系树消除了所有冲突的单义性解析器: mvn dependency:tree -Dverbose -Dincludes=com.univocity:univocity-parsers 产生:

[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ preval ---
[INFO] dataqa:preval:jar:1.0-SNAPSHOT
[INFO] \- com.univocity:univocity-parsers:jar:2.8.2:compile

我还尝试在运行 spark 作业时设置 spark.executor.userClassPathFirst=true 配置,但行为没有变化。

这是我的 pom.xml 中的依赖项部分:

<dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>2.11.12</version>
        </dependency>
        <!--
            Spark library. spark-core_2.xx must match the scala language version
        -->
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-core_2.11</artifactId>
            <version>2.0.0</version>
        </dependency>

        <!--
            Spark SQL library. spark-sql_2.xx must match the scala language version
        -->
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-sql_2.11</artifactId>
            <version>2.0.0</version>
            <exclusions>
                <exclusion>  <!-- declare the exclusion here -->
                    <groupId>com.univocity</groupId>
                    <artifactId>univocity-parsers</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!--
            Library to make REST API call
        -->
        <dependency>
            <groupId>com.typesafe.play</groupId>
            <artifactId>play-ahc-ws-standalone_2.11</artifactId>
            <version>2.0.0-M1</version>
        </dependency>


        <!--
            Parses delimited files
        -->
        <dependency>
            <groupId>com.univocity</groupId>
            <artifactId>univocity-parsers</artifactId>
            <version>2.8.2</version>
            <type>jar</type>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1.1</version>
        </dependency>

我想知道 Spark 是否具有覆盖我的版本的内置依赖项(2.8 是第一个支持字符串参数的版本。以前,它只支持字符)。

有什么见解吗?

4

2 回答 2

0

在花了很多时间进行故障排除后,我找到了解决方案。我必须使用此处描述的 maven-shade-plugin https://www.cloudera.com/documentation/enterprise/5-13-x/topics/spark_building.html#relocation

这是我必须添加到我的 pom.xml 中的 maven-shade-plugin 定义的相关代码部分:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>3.2.1</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>

                <!-- other non-revelant filters etc omitted for brevity -->

                <relocations>
                    <!-- used to make sure there are no conflicts between the univocity parser version used here and the one that is bundled with spark -->
                    <relocation>
                        <pattern>com.univocity.parsers</pattern>
                        <shadedPattern>com.shaded.parsers</shadedPattern>
                    </relocation>
                </relocations>
            </configuration>
        </execution>
    </executions>
</plugin>
于 2019-08-26T15:51:10.637 回答
0

有点晚了,但如果使用 --conf spark.driver.extraClassPathandspark.executor.extraClassPath是一个选项,请在此处查看我的回复。

于 2019-08-24T12:33:40.570 回答