apache-sparkpysparkavrorecursive-datastructuresspark-avro

Spark can not process recursive avro data


I have avsc schema like below:

{
  "name": "address",
  "type": [
     "null", 
        {
           "type":"record",
           "name":"Address",
           "namespace":"com.data",
           "fields":[
              {
                 "name":"address",
                 "type":[ "null","com.data.Address"],
                 "default":null
              }
           ]
        }
     ],
  "default": null
}

On loading this data in pyspark:

jsonFormatSchema = open("Address.avsc", "r").read()

spark = SparkSession.builder.appName('abc').getOrCreate()
df = spark.read.format("avro")\
.option("avroSchema", jsonFormatSchema)\
.load("xxx.avro")

I got such exception:

"Found recursive reference in Avro schema, which can not be processed by Spark"

I tried many other configurations, but without any success. To execute I use with spark-submit:

--packages org.apache.spark:spark-avro_2.12:3.0.1

Solution

  • This is a intended feature, you can take a look at the "issue" :

    https://issues.apache.org/jira/browse/SPARK-25718