gengliangwang commented on a change in pull request #26907: [SPARK-30267][SQL] 
Avro arrays can be of any List
URL: https://github.com/apache/spark/pull/26907#discussion_r362396571
 
 

 ##########
 File path: 
external/avro/src/test/scala/org/apache/spark/sql/avro/AvroCatalystDataConversionSuite.scala
 ##########
 @@ -246,4 +271,37 @@ class AvroCatalystDataConversionSuite extends 
SparkFunSuite
     }.getMessage
     assert(message ==  "Cannot convert Catalyst type StringType to Avro type 
\"long\".")
   }
+
+  test("avro array can be generic java collection") {
+    val jsonFormatSchema =
+      """
+        |{ "type": "record",
+        |  "name": "record",
+        |  "fields" : [{
+        |    "name": "array",
+        |    "type": {
+        |      "type": "array",
+        |      "items": ["null", "int"]
+        |    }
+        |  }]
+        |}
+      """.stripMargin
+    val avroSchema = new Schema.Parser().parse(jsonFormatSchema)
+    val dataType = SchemaConverters.toSqlType(avroSchema).dataType
+    val deserializer = new AvroDeserializer(avroSchema, dataType)
+
+    def validateDeserialization(array: java.util.Collection[Integer]): Unit = {
+      val data = new GenericRecordBuilder(avroSchema)
+        .set("array", array)
+        .build()
+      deserializer.deserialize(data)
+
+      val reEncoded = new BinaryMessageDecoder[GenericData.Record](new 
GenericData(), avroSchema)
+        .decode(new BinaryMessageEncoder(new GenericData(), 
avroSchema).encode(data))
+      deserializer.deserialize(reEncoded)
 
 Review comment:
   It would be better to validate the deserialization result here. (For 
example,  use `checkEvaluation`)

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to