xkrogen commented on code in PR #36506:
URL: https://github.com/apache/spark/pull/36506#discussion_r965125762
##########
connector/avro/src/test/scala/org/apache/spark/sql/avro/AvroFunctionsSuite.scala:
##########
@@ -220,26 +220,36 @@ class AvroFunctionsSuite extends QueryTest with
SharedSparkSession {
functions.from_avro($"avro", avroTypeStruct)), df)
}
- test("to_avro with unsupported nullable Avro schema") {
+ test("to_avro optional union Avro schema") {
val df = spark.range(10).select(struct($"id",
$"id".cast("string").as("str")).as("struct"))
- for (unsupportedAvroType <- Seq("""["null", "int", "long"]""", """["int",
"long"]""")) {
+ for (supportedAvroType <- Seq("""["null", "int", "long"]""", """["int",
"long"]""")) {
val avroTypeStruct = s"""
|{
| "type": "record",
| "name": "struct",
| "fields": [
- | {"name": "id", "type": $unsupportedAvroType},
+ | {"name": "id", "type": $supportedAvroType},
| {"name": "str", "type": ["null", "string"]}
| ]
|}
""".stripMargin
- val message = intercept[SparkException] {
- df.select(functions.to_avro($"struct",
avroTypeStruct).as("avro")).show()
- }.getCause.getMessage
- assert(message.contains("Only UNION of a null type and a non-null type
is supported"))
+ val avroStructDF = df.select(functions.to_avro($"struct",
avroTypeStruct).as("avro"))
+ checkAnswer(avroStructDF.select(
+ functions.from_avro($"avro", avroTypeStruct)), df)
}
}
+ test("to_avro complex union Avro schema") {
+ val df = Seq(Tuple2(Some(1), None), Tuple2(None, Some("a"))).toDF()
Review Comment:
Why the explicit reference to `Tuple2`? You should be able to just do
`(Some(1), None)` right?
--
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]