gpt4 book ai didi

apache-spark - 如何使用spark-avro包从spark-shell读取avro文件?

转载 作者:行者123 更新时间:2023-12-04 11:33:17 26 4
gpt4 key购买 nike

我正在尝试使用Apache Avro Data Source Guide中描述的spark-avro包。

当我提交以下命令时:

val df = spark.read.format("avro").load("~/foo.avro")

我收到一个错误:
java.util.ServiceConfigurationError: org.apache.spark.sql.sources.DataSourceRegister: Provider org.apache.spark.sql.avro.AvroFileFormat could not be instantiated
at java.util.ServiceLoader.fail(ServiceLoader.java:232)
at java.util.ServiceLoader.access$100(ServiceLoader.java:185)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:384)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
at scala.collection.convert.Wrappers$JIteratorWrapper.next(Wrappers.scala:43)
at scala.collection.Iterator$class.foreach(Iterator.scala:891)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1334)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
at scala.collection.TraversableLike$class.filterImpl(TraversableLike.scala:247)
at scala.collection.TraversableLike$class.filter(TraversableLike.scala:259)
at scala.collection.AbstractTraversable.filter(Traversable.scala:104)
at org.apache.spark.sql.execution.datasources.DataSource$.lookupDataSource(DataSource.scala:630)
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:194)
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:178)
... 49 elided
Caused by: java.lang.NoSuchMethodError: org.apache.spark.sql.execution.datasources.FileFormat.$init$(Lorg/apache/spark/sql/execution/datasources/FileFormat;)V
at org.apache.spark.sql.avro.AvroFileFormat.<init>(AvroFileFormat.scala:44)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:380)
... 62 more

我已经尝试过不同版本的 org.apache.spark:spark-avro_2.12:2.4.0软件包(2.4.0、2.4.1和2.4.2),并且我目前使用Spark 2.4.1,但均不起作用。

我使用以下命令启动spark-shell:
spark-shell --packages org.apache.spark:spark-avro_2.12:2.4.0

enter image description here

最佳答案

tl; dr Since Spark 2.4.x+ provides built-in support for reading and writing Apache Avro data,但是the spark-avro module is external and not included in spark-submit or spark-shell by default,请确保对spark-shell--packages使用相同的Scala版本(例如2.12)。

出现异常的原因是,您使用的是针对Scala 2.11.12构建的Spark中的spark-shell,而--packages指定了Scala 2.12(在org.apache.spark:spark-avro_2.12:2.4.0中)的依赖项。

使用--packages org.apache.spark:spark-avro_2.11:2.4.0,就可以了。

关于apache-spark - 如何使用spark-avro包从spark-shell读取avro文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55873023/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com