title: Can not read avro in DataProc Spark with spark-avro
body: <p>I have a cluster on Google DataProc (with image 1.4) and I want to read avro files with Spark from google cloud storage. I follow this guide: <a href="https://spark.apache.org/docs/latest/sql-data-sources-avro.html" rel="nofollow noreferrer">Spark read avro</a>.</p>
  <p>The command I ran is:</p>
  <pre><code>gcloud dataproc jobs submit pyspark test.py \
  --cluster $CLUSTER_NAME \
  --region $REGION \
  --properties spark.jars.packages='org.apache.spark:spark-avro_2.12:2.4.1'
  </code></pre>
  <p>test.py is very simple, just</p>
  <pre><code>from pyspark.sql import SparkSession
  
  from pyspark.sql import SQLContext
  
  spark = SparkSession.builder.appName('test').getOrCreate()
  
  df = spark.read.format(&quot;avro&quot;).load(&quot;gs://mybucket/abc.avro&quot;)
  
  df.show()
  </code></pre>
  <p>I got the following error:</p>
  <pre><code>Py4JJavaError: An error occurred while calling o196.load.
  : 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)
      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 py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
      at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
      at py4j.Gateway.invoke(Gateway.java:282)
      at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
      at py4j.commands.CallCommand.execute(CallCommand.java:79)
      at py4j.GatewayConnection.run(GatewayConnection.java:238)
      at java.lang.Thread.run(Thread.java:748)
  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.&lt;init&gt;(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)
      ... 24 more
  </code></pre>
  <p>Even if I ssh to master node and start the shell there with <code>spark-shell --packages org.apache.spark:spark-avro_2.12:2.4.1</code>, running <code>val usersDF = spark.read.format(&quot;avro&quot;).load(&quot;gs://mybucket/abc.avro&quot;)</code> has the same error.</p>
  <p>Why this happens? Thank you.</p>