【问题标题】:Spark java.lang.NoSuchMethodError for Univocity CSV Parser setDelimiter methodUnivocity CSV Parser setDelimiter 方法的 Spark java.lang.NoSuchMethodError
【发布时间】:2019-08-26 23:51:10
【问题描述】:

我正在尝试运行使用 Univocity CSV 解析器的 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 依赖:树 -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 是第一个支持字符串参数的版本。以前,它只支持字符)。

有什么见解吗?

【问题讨论】:

    标签: apache-spark univocity


    【解决方案1】:

    有点晚了,但如果使用--conf spark.driver.extraClassPathspark.executor.extraClassPath 是一个选项,请参阅我的回复here

    【讨论】:

    • 感谢您的回复,但仍然失败并出现同样的错误。我尝试添加 --conf spark.driver.extraClassPath=hdfs:///path/to/jar 并将 jar 复制到本地目录并尝试 spark.driver.extraClassPath=/path/to/罐。 spark.executor.extraClassPath 也是如此
    • 太糟糕了..你试过阴影吗? maven.apache.org/plugins/maven-shade-plugin/examples/…
    • 是的,找到了解决方案。请参阅下面的答案。
    【解决方案2】:

    花了很多时间进行故障排除后,我找到了解决方案。我必须使用这里描述的 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>
    

    【讨论】:

      猜你喜欢
      • 2020-07-16
      • 2017-01-21
      • 2017-10-27
      • 1970-01-01
      • 1970-01-01
      • 2022-12-16
      • 2016-09-10
      • 1970-01-01
      • 2019-11-09
      相关资源
      最近更新 更多