【问题标题】:Jackson version issue in spark structured streamingSpark结构化流中的杰克逊版本问题
【发布时间】:2019-05-10 18:41:21
【问题描述】:

当使用 spark structured streamingspark-sql-kafka-0-10_2.11 时,我看到了 MethodNotFoundError's 。基于另一个问题Cannot run queries in SQLContext from Apache Spark SQL 1.5.2, getting java.lang.NoSuchMethodError 我试图明确设置 jackson 版本。

版本 2.9.6、2.4.3、2.9.0 已试用。 2.4.3 说“杰克逊版本太旧”。其他版本说

引起:com.fasterxml.jackson.databind.JsonMappingException: 不兼容的 Jackson 版本:2.9.0

这是2.9.0的完整ST:

19/05/10 11:30:18 ERROR MicroBatchExecution: Query [id = dbd581ba-42d7-4496-9fde-fe04dab6e7b4, runId = b5b023df-cb39-4048-90dc-e9a57cce4883] terminated with error
java.lang.ExceptionInInitializerError
    at org.apache.spark.sql.execution.SparkPlan.executeQuery(SparkPlan.scala:152)
    at org.apache.spark.sql.execution.SparkPlan.execute(SparkPlan.scala:127)
    at org.apache.spark.sql.execution.SparkPlan.getByteArrayRdd(SparkPlan.scala:247org.apache.spark.sql.Dataset$$anonfun$53.apply(Dataset.scala:3365)
    at org.apache.spark.sql.execution.SQLExecution$$anonfun$withNewExecutionId$1.apply(SQLExecution.scala:78)
    at org.apache.spark.sql.execution.SQLExecution$.withSQLConfPropagated(SQLExecution.scala:125)
    at org.apache.spark.sql.execution.SQLExecution$.withNewExecutionId(SQLExecution.scala:73)
    at org.apache.spark.sql.Dataset.withAction(Dataset.scala:3364)
    at org.apache.spark.sql.Dataset.collect(Dataset.scala:2783)
    at org.apache.spark.sql.execution.streaming.MicroBatchExecution$$anonfun$org$apache$spark$sql$execution$streaming$MicroBatchExecution$$runBatch$5$$anonfun$apply$17.apply(MicroBatchExecution.scala:537)
    at org.apache.spark.sql.execution.SQLExecution$$anonfun$withNewExecutionId$1.apply(SQLExecution.scala:78)
    at      at org.apache.spark.sql.execution.streaming.ProgressReporter$class.reportTimeTaken(ProgressReporter.scala:351)
    at 
 ..
org.apache.spark.sql.execution.streaming.StreamExecution$$anon$1.run(StreamExecution.scala:189)
    Caused by: com.fasterxml.jackson.databind.JsonMappingException: 
   Incompatible Jackson version: 2.9.0
        at com.fasterxml.jackson.module.scala.JacksonModule$class.setupModule(JacksonModule.scala:64)
        at com.fasterxml.jackson.module.scala.DefaultScalaModule.setupModule(DefaultScalaModule.scala:19)
        at com.fasterxml.jackson.databind.ObjectMapper.registerModule(ObjectMapper.java:751)
        at org.apache.spark.rdd.RDDOperationScope$.<init>(RDDOperationScope.scala:82)
        at org.apache.spark.rdd.RDDOperationScope$.<clinit>(RDDOperationScope.scala)

另请注意,我确实在 pom.xml 中设置了排除项:

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>${jackson.databind.version}</version>
    </dependency>

    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-sql_${scala.binary.version}</artifactId>
        <version>${spark.version}</version>
        <scope>compile</scope>
       <exclusions>
            <exclusion>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

AWS 的类似排除项

    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk</artifactId>
        <version>1.7.4</version>
       <exclusions>
            <exclusion>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

有什么想法可以解决这里的杰克逊版本控制问题吗?

【问题讨论】:

    标签: apache-spark jackson jackson-databind


    【解决方案1】:

    通过查看 $SPARK_HOME/jars 目录并搜索 jackson-databind 找到答案:

    $ll *jackson-databind*
    -rw-r--r--@ 1 steve  staff  1165323 Mar 26 17:13 jackson-databind-2.6.7.1.jar
    

    然后更新pom.xml

        <jackson.databind.version>2.6.7</jackson.databind.version>
    

    解决了这个问题。

    【讨论】:

      【解决方案2】:

      对于 Scala,添加您的 build.sbt 文件:

      dependencyOverrides += "com.fasterxml.jackson.core" % "jackson-databind" % "2.6.7"
      

      【讨论】: