0

我尝试使用 CassandraSQLContext 从 Spark 查询 Cassandra,但我得到一个奇怪的缺少依赖项错误。我有一个 Spark 应用程序,如下所示:

val spark: SparkSession = SparkSession.builder().appName(appName).getOrCreate()
val cassandraSQLContext = new org.apache.spark.sql.cassandra.CassandraSQLContext(spark.sparkContext)

val path = args(0)
cassandraSQLContext.setKeyspace(args(1))

val dataFrame: DataFrame = cassandraSQLContext.sql(args(2))
dataFrame.write.mode(SaveMode.Overwrite).option("header", "true").csv(path)

我得到一个缺少的 Spark scala 类错误:

User class threw exception: java.lang.NoClassDefFoundError: org/apache/spark/sql/catalyst/analysis/Catalog
    at com.test.batch.utils.CSVFromCassandraSQLQuery$.<init>(CSVFromCassandraSQLQuery.scala:19)
    at com.test.batch.utils.CSVFromCassandraSQLQuery$.<clinit>(CSVFromCassandraSQLQuery.scala)
    at com.test.batch.utils.CSVFromCassandraSQLQuery.main(CSVFromCassandraSQLQuery.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.spark.deploy.yarn.ApplicationMaster$$anon$4.run(ApplicationMaster.scala:721)
Caused by: java.lang.ClassNotFoundException: org.apache.spark.sql.catalyst.analysis.Catalog
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 8 more

我还尝试spark-catalyst在命令中显式添加 jar 路径spark-submit,但我仍然遇到相同的问题(无论是在本地运行还是在 yarn 集群上运行)...

这是我的项目设置build.sbt

scalaVersion := "2.11.11"
val sparkVersion = "2.3.1"

libraryDependencies ++= Seq(
  "log4j" % "log4j" % "1.2.17",
  "org.apache.spark" %% "spark-core" % sparkVersion % "provided",
  "org.apache.spark" %% "spark-sql" % sparkVersion  % "provided",
  "org.apache.spark" %% "spark-hive" % sparkVersion % "provided",
  "org.apache.spark" %% "spark-catalyst" % sparkVersion % "provided",
  "org.apache.spark" %% "spark-streaming" % sparkVersion % "provided",
  "com.datastax.spark" %% "spark-cassandra-connector" % "2.3.1",
  "org.scala-lang.modules" %% "scala-java8-compat" % "0.9.0",
  "com.twitter" % "jsr166e" % "1.1.0"
)

关于我所缺少的任何想法?

4

1 回答 1

1

出现此问题是因为 org.apache.spark.sql.catalyst.analysis。目录类不再是spark-catalyst_2.11:2.xx的一部分。请参考spark-catalyst_2.11:2.0.0的源代码

https://jar-download.com/artifacts/org.apache.spark/spark-catalyst_2.11/2.0.0/source-code

org.apache.spark.sql.catalyst.analysis.Catalog类在spark-catalyst_2.11:1.6.3版本之前可用。

https://jar-download.com/artifacts/org.apache.spark/spark-catalyst_2.11/1.6.3/source-code

我会要求您不要使用CassandraSQLContext,因为它已被弃用。请查看https://datastax-oss.atlassian.net/browse/SPARKC-399

请查看 SO 帖子以在 spark 2.0 中使用 Cassandra Context

如何在 spark 2.0 中使用 Cassandra 上下文

于 2019-03-21T11:52:39.383 回答