Spark 2.0 with Play! 2.5

时间:2016-10-07 09:07:05

标签: apache-spark playframework sbt playframework-2.5 apache-spark-2.0

我正在尝试使用Spark 2.0和Play! 2.5但我无法使其正常工作(似乎Github上没有例子)。

我没有任何编译错误,但我有一些奇怪的执行错误 例如: 几乎DatasetDataframe上的所有操作都会导致NullPointerException

val ds: Dataset[Event] = df.as[Event]
println(ds.count()) //Works well and prints the good results
ds.collect() // --> NullPointerException

ds.show也会导致NullPointerException

所以我遗失了一个很大的问题所以我认为它来自不兼容的版本。以下是我build.sbt的相关部分:

object Version {
  val scala            = "2.11.8"
  val spark            = "2.0.0"
  val postgreSQL       = "9.4.1211.jre7"
}

object Library {
  val sparkSQL          = "org.apache.spark"            %% "spark-sql"          % Version.spark
  val sparkMLLib        = "org.apache.spark"            %% "spark-mllib"        % Version.spark
  val sparkCore         = "org.apache.spark"            %% "spark-core"         % Version.spark
  val postgreSQL        = "org.postgresql"              %  "postgresql"         % Version.postgreSQL
}

object Dependencies {
  import Library._

  val dependencies = Seq(
    sparkSQL,
    sparkMLLib,
    sparkCore,
    postgreSQL)
}

lazy val root = (project in file("."))
  .settings(scalaVersion := Version.scala)
  .enablePlugins(PlayScala)

libraryDependencies ++= Dependencies.dependencies

dependencyOverrides ++= Set(
  "com.fasterxml.jackson.core" % "jackson-databind" % "2.7.4",
  "com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.7.4"
)

1 个答案:

答案 0 :(得分:2)

我使用spark 2.0.0和play 2.5.12 java遇到了同样的问题。 激活器似乎默认包含com.fasterxml.jackson-databind 2.7.8,它不适用于jackson-module-scala。

我清理了我的sbt缓存

scalaVersion := "2.11.8"
libraryDependencies ++= Seq(
   "com.fasterxml.jackson.core" % "jackson-core" % "2.8.7",
   "com.fasterxml.jackson.core" % "jackson-databind" % "2.8.7",
   "com.fasterxml.jackson.core" % "jackson-annotations" % "2.8.7",
   "com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.8.7",
   "org.apache.spark" % "spark-core_2.11" % "2.0.0",
   "org.apache.spark" % "spark-mllib_2.11" % "2.0.0"
)

我的新build.sbt,在编译时产生一个waring,因为spark 2.0.0是用jackson-module-scala_2.11:2.6.5编译的,但仍然可以使用jackson-module-scala 2.8来触发2个接缝.7

{{1}}

从jackson.databind.JsonMappingException派生的NullpointerException:不兼容的Jackson版本:2.x.x 请阅读https://github.com/FasterXML/jackson-module-scala/issues/233