我使用结构化的spark流来写入来自kafka的hbase数据。
我的集群发行版是:hadoop3.0.0-cdh6.2.0,我使用的是spark2.4.0
我的代码如下:
val df = spark
.readStream
.format("kafka")
.option("kafka.bootstrap.servers", bootstrapServers)
.option("subscribe", topic)
.option("failOnDataLoss", false)
.load()
.selectExpr("CAST(key AS STRING)" , "CAST(value AS STRING)")
.as(Encoders.STRING)
df.writeStream
.foreachBatch { (batchDF: Dataset[Row], batchId: Long) =>
batchDF.write
.options(Map(HBaseTableCatalog.tableCatalog->catalog, HBaseTableCatalog.newTable -> "6"))
.format("org.apache.spark.sql.execution.datasources.hbase").save()
}
.option("checkpointLocation", checkpointDirectory)
.start()
.awaitTermination()
hbasetablecatalog使用json4s-jackson\u 2.11库。此库包含在spark core中,但版本不正确,会产生冲突。。。
为了解决这个问题,我在spark core中排除了json4s-jacksonï2.11库,并在pom中添加了一个降级版本:
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>2.4.0-cdh6.2.0</version>
<exclusions>
<exclusion>
<groupId>org.json4s</groupId>
<artifactId>json4s-jackson_2.11</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.json4s</groupId>
<artifactId>json4s-jackson_2.11</artifactId>
<version>3.2.11</version>
</dependency>
当我在本地计算机中执行代码时,它工作得很好,但问题是,当我在cloudera集群中提交代码时,出现了库冲突的第一个错误:
Caused by: java.lang.NoSuchMethodError: org.json4s.jackson.JsonMethods$.parse(Lorg/json4s/JsonInput;Z)Lorg/json4s/JsonAST$JValue;
at org.apache.spark.sql.execution.datasources.hbase.HBaseTableCatalog$.apply(HBaseTableCatalog.scala:257)
at org.apache.spark.sql.execution.datasources.hbase.HBaseRelation.<init>(HBaseRelation.scala:80)
at org.apache.spark.sql.execution.datasources.hbase.DefaultSource.createRelation(HBaseRelation.scala:59)
at org.apache.spark.sql.execution.datasources.SaveIntoDataSourceCommand.run(SaveIntoDataSourceCommand.scala:45)
at org.apache.spark.sql.execution.command.ExecutedCommandExec.sideEffectResult$lzycompute(commands.scala:70)
at org.apache.spark.sql.execution.command.ExecutedCommandExec.sideEffectResult(commands.scala:68)
at org.apache.spark.sql.execution.command.ExecutedCommandExec.doExecute(commands.scala:86)
at org.apache.spark.sql.execution.SparkPlan$$anonfun$execute$1.apply(SparkPlan.scala:131)
at org.apache.spark.sql.execution.SparkPlan$$anonfun$execute$1.apply(SparkPlan.scala:127)
at org.apache.spark.sql.execution.SparkPlan$$anonfun$executeQuery$1.apply(SparkPlan.scala:155)
at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:151)
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.QueryExecution.toRdd$lzycompute(QueryExecution.scala:80)
at org.apache.spark.sql.execution.QueryExecution.toRdd(QueryExecution.scala:80)
at org.apache.spark.sql.DataFrameWriter$$anonfun$runCommand$1.apply(DataFrameWriter.scala:668)
at org.apache.spark.sql.DataFrameWriter$$anonfun$runCommand$1.apply(DataFrameWriter.scala:668)
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.DataFrameWriter.runCommand(DataFrameWriter.scala:668)
at org.apache.spark.sql.DataFrameWriter.saveToV1Source(DataFrameWriter.scala:276)
at org.apache.spark.sql.DataFrameWriter.save(DataFrameWriter.scala:270)
at com.App$$anonfun$main$1.apply(App.scala:129)
at com.App$$anonfun$main$1.apply(App.scala:126)
我知道集群有自己的hadoop和spark库,它也在使用它们,因此,在spark提交中,我将confs spark.driver.userclasspathfirst和spark.executor.userclasspathfirst设置为true,但我有另一个错误,我不明白:
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.apache.spark.deploy.yarn.YarnSparkHadoopUtil$.<init>(YarnSparkHadoopUtil.scala:48)
at org.apache.spark.deploy.yarn.YarnSparkHadoopUtil$.<clinit>(YarnSparkHadoopUtil.scala)
at org.apache.spark.deploy.yarn.Client$$anonfun$1.apply$mcJ$sp(Client.scala:83)
at org.apache.spark.deploy.yarn.Client$$anonfun$1.apply(Client.scala:83)
at org.apache.spark.deploy.yarn.Client$$anonfun$1.apply(Client.scala:83)
at scala.Option.getOrElse(Option.scala:121)
at org.apache.spark.deploy.yarn.Client.<init>(Client.scala:82)
at org.apache.spark.deploy.yarn.YarnClusterApplication.start(Client.scala:1603)
at org.apache.spark.deploy.SparkSubmit.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:851)
at org.apache.spark.deploy.SparkSubmit.doRunMain$1(SparkSubmit.scala:167)
at org.apache.spark.deploy.SparkSubmit.submit(SparkSubmit.scala:195)
at org.apache.spark.deploy.SparkSubmit.doSubmit(SparkSubmit.scala:86)
at org.apache.spark.deploy.SparkSubmit$$anon$2.doSubmit(SparkSubmit.scala:926)
at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:935)
at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
Caused by: java.lang.ClassCastException: org.apache.hadoop.yarn.api.records.impl.pb.PriorityPBImpl cannot be cast to org.apache.hadoop.yarn.api.records.Priority
at org.apache.hadoop.yarn.api.records.Priority.newInstance(Priority.java:39)
at org.apache.hadoop.yarn.api.records.Priority.<clinit>(Priority.java:34)
... 15 more
最后,我想要的是,在我的pom中使用json4s-jacksonè2.11而不是spark内核中的json4s-jacksonè2.11来生成spark
1条答案
按热度按时间7y4bm7vi1#
要解决这个问题,不要使用
spark.driver.userClassPathFirst
以及spark.executor.userClassPathFirst
但实际上,使用spark.driver.extraClassPath
以及spark.executor.extraClassPath
.官方文档中的定义:“额外的类路径条目,以预先添加到驱动程序的类路径。”
“prepend”放在spark的核心类路径前面。
例子:
--conf spark.driver.extraclasspath=c:\users\khalid\documents\projects\libs\jackson-annotations-2.6.0.jar;c:\users\khalid\documents\projects\libs\jackson-core-2.6.0.jar;c:\users\khalid\documents\projects\libs\jackson-databind-2.6.0.jar文件
这解决了我的问题(我想要使用的jackson版本和spark使用的版本之间的冲突)。
希望有帮助。