来自 sbt scala 的 google dataproc 上的 spark-sql

spark-sql on google dataproc from sbt scala

使用 Google Dataproc Spark 集群,我的 sbt 构建的程序集 jar 可以通过 SparkContext 访问 Cassandra。

但是,当我尝试通过 sqlContext 访问时,我得到了 spark sql 类 not found on the remote cluster - 虽然我相信应该配置 dataproc 集群对于火花 sql.

java.lang.NoClassDefFoundError: org/apache/spark/sql/types/UTF8String$
        at org.apache.spark.sql.cassandra.CassandraSQLRow$$anonfun$fromJavaDriverRow.apply$mcVI$sp(CassandraSQLRow.scala:50)
        at scala.collection.immutable.Range.foreach$mVc$sp(Range.scala

我的 sbt 文件:

libraryDependencies ++= Seq(
  "org.apache.spark" %% "spark-core" % "1.5.0" % "provided",
  "org.apache.spark" %% "spark-sql" % "1.5.0" % "provided",
  "com.datastax.spark" %% "spark-cassandra-connector" % "1.4.0"
)

在 spark-sql 上关闭 "provided" 会使我陷入 jar 重复合并地狱。

感谢任何帮助。

看来您还需要 spark-cassandra-connector 的版本 1.5.0 以确保您的 类 兼容。这是 commit which upgraded the cassandra connector to 1.5.0,您可以看到它删除了 org.apache.spark.sql.types.UTF8String 的导入并添加了 import org.apache.spark.unsafe.types.UTF8String,更改了 CassandraSQLRow.scala:

中的相关行
       data(i) = GettableData.get(row, i)
       data(i) match {
         case date: Date => data.update(i, new Timestamp(date.getTime))
-        case str: String => data.update(i, UTF8String(str))
+        case bigInt: BigInteger => data.update(i, new JBigDecimal(bigInt))
+        case str: String => data.update(i, UTF8String.fromString(str))
         case set: Set[_] => data.update(i, set.toSeq)
         case _ =>
       }

尽管在 Maven central for the cassandra connector, you should still be able to get the latest milestone connector 1.5.0-M2 中似乎只有 "milestone" 工件类型而不是 "release" 类型可以使用您的代码。

编辑:link compatibility table from the Cassandra connector's GitHub README.md