我尝试使用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
在 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"
)
你知道我遗漏了什么吗?
1条答案
按热度按时间4uqofj5v1#
之所以出现此问题,是因为org.apache.spark.sql.catalyst.analysis.catalog类不再是spark-catalyst 2.11:2.x.x的一部分。请参考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 post以在spark 2.0中使用cassandra上下文。
如何在spark 2.0中使用cassandra上下文