sadikovi commented on code in PR #37191:
URL: https://github.com/apache/spark/pull/37191#discussion_r930451902


##########
connector/avro/src/test/scala/org/apache/spark/sql/avro/AvroFunctionsSuite.scala:
##########
@@ -238,4 +239,35 @@ class AvroFunctionsSuite extends QueryTest with 
SharedSparkSession {
       assert(message.contains("Only UNION of a null type and a non-null type 
is supported"))
     }
   }
+
+  test("SPARK-39775: Disable validate default values when parsing Avro 
schemas") {
+    val avroTypeStruct = s"""
+      |{
+      |  "type": "record",
+      |  "name": "struct",
+      |  "fields": [
+      |    {"name": "id", "type": "long", "default": null}
+      |  ]
+      |}
+    """.stripMargin
+    val avroSchema = AvroOptions(Map("avroSchema" -> 
avroTypeStruct)).schema.get
+    val sparkSchema = 
SchemaConverters.toSqlType(avroSchema).dataType.asInstanceOf[StructType]
+
+    val df = spark.range(5).select($"id")
+    val structDf = df.select(struct($"id").as("struct"))
+    val avroStructDF = structDf.select(functions.to_avro('struct, 
avroTypeStruct).as("avro"))
+    checkAnswer(avroStructDF.select(functions.from_avro('avro, 
avroTypeStruct)), structDf)
+
+    withTempPath { dir =>
+      df.write.format("avro").save(dir.getCanonicalPath)
+      
checkAnswer(spark.read.schema(sparkSchema).format("avro").load(dir.getCanonicalPath),
 df)
+
+      val msg = intercept[SparkException] {
+        spark.read.option("avroSchema", avroTypeStruct).format("avro")

Review Comment:
   It seems the description is not accurate anymore because we do throw 
exception when parsing Avro schemas with default values. Could you elaborate or 
add a comment explaining why this test should fail since we disable validation?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to