dongjoon-hyun commented on code in PR #41409:
URL: https://github.com/apache/spark/pull/41409#discussion_r1213812202
##########
connector/avro/src/test/scala/org/apache/spark/sql/avro/AvroLogicalTypeSuite.scala:
##########
@@ -446,6 +446,98 @@ abstract class AvroLogicalTypeSuite extends QueryTest with
SharedSparkSession {
)
}
}
+
+ test("SPARK-43901: LogicalType: Custom Decimal for Long Type") {
+ val schema =
+ new Schema.Parser().parse("""{
+ "namespace": "logical",
+ "type": "record",
+ "name": "test",
+ "fields": [
+ {
+ "name": "field1",
+ "type": {"type": "long", "logicalType": "custom-decimal", "scale":
2, "precision": 38}
+ },
+ {
+ "name": "field2",
+ "type": {"type": "long", "logicalType": "custom-decimal", "scale":
9, "precision": 33}
+ },
+ {
+ "name": "field3",
+ "type": "long"
+ }]
+ }""")
+
+ withTempDir { dir =>
+ val datumWriter = new GenericDatumWriter[GenericRecord](schema)
+ val dataFileWriter = new DataFileWriter[GenericRecord](datumWriter)
+ dataFileWriter.create(schema, new File(s"$dir.avro"))
+ val avroRec = new GenericData.Record(schema)
+ avroRec.put("field1", 123456789L)
+ avroRec.put("field2", 123456789L)
+ avroRec.put("field3", 123456789L)
+ dataFileWriter.append(avroRec)
+ dataFileWriter.flush()
+ dataFileWriter.close()
+ val df = spark
+ .read
+ .format("avro")
+ .load(s"$dir.avro")
+ assertResult(DecimalType(38, 2))(df.schema.head.dataType)
+ val firstRow = df.take(1)(0)
+ assertResult(java.math.BigDecimal.valueOf(123456789L,
2))(firstRow.getAs("field1"))
+ assertResult(java.math.BigDecimal.valueOf(123456789L,
9))(firstRow.getAs("field2"))
+ assertResult(123456789L)(firstRow.getAs("field3"))
+ }
+ }
+
+ test("SPARK-43901:LogicalType: Decimal for Long Type Exception Cases") {
Review Comment:
nit. `SPARK-43901:LogicalType` -> `SPARK-43901: LogicalType`
--
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]