This is an automated email from the ASF dual-hosted git repository.

voonhous pushed a commit to branch release-1.2.1
in repository https://gitbox.apache.org/repos/asf/hudi.git

commit d030eb17dd899d7f59d9f7d9a5c2e8cb1e633193
Author: ashokkumar-allu <[email protected]>
AuthorDate: Fri May 1 12:32:02 2026 -0500

    test(spark): Add date logical type test to TestAvroConversionUtils (#18584)
    
    * [MINOR] Add date logical type test to TestAvroConversionUtils
    
    Add a test case that verifies createConverterToRow correctly handles
    Avro's date logical type (int with logicalType=date), ensuring the
    conversion from epoch-days integer to java.sql.Date preserves the
    correct date value.
    
    * [MINOR] Address review comments: rename convertor to converter, add 
comments
    
    ---------
    
    Co-authored-by: gallu <[email protected]>
    (cherry picked from commit f7508ded95a534f5e6e5ffc5150a83a5662d05db)
---
 .../org/apache/hudi/TestAvroConversionUtils.scala  | 27 ++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git 
a/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/TestAvroConversionUtils.scala
 
b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/TestAvroConversionUtils.scala
index 5f4ec78c13cf..0430dd081237 100644
--- 
a/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/TestAvroConversionUtils.scala
+++ 
b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/TestAvroConversionUtils.scala
@@ -28,6 +28,7 @@ import org.apache.spark.sql.types.{ArrayType, BinaryType, 
DataType, DataTypes, M
 import org.scalatest.{FunSuite, Matchers}
 
 import java.nio.ByteBuffer
+import java.time.LocalDate
 import java.util.Objects
 
 class TestAvroConversionUtils extends FunSuite with Matchers {
@@ -456,4 +457,30 @@ class TestAvroConversionUtils extends FunSuite with 
Matchers {
       HoodieSchemaConversionUtils.convertStructTypeToHoodieSchema(struct, 
"SchemaName", "SchemaNS")
     } should have message "Duplicate field name in record SchemaNS.SchemaName: 
name type:UNION pos:2 and name type:UNION pos:1."
   }
+
+  test("Logical type: date") {
+    val dateSchema = s"""
+      {
+        "namespace": "logical",
+        "type": "record",
+        "name": "test",
+        "fields": [
+          {"name": "date", "type": {"type": "int", "logicalType": "date"}}
+        ]
+      }
+    """
+
+    val dateInputData = Seq(7, 365, 0) // one week, one year, epoch
+    val schema = HoodieSchema.parse(dateSchema)
+    val converter = AvroConversionUtils.createConverterToRow(schema, 
HoodieSchemaConversionUtils.convertHoodieSchemaToStructType(schema))
+
+    val dateOutputData = dateInputData.map(x => {
+      val record = new GenericData.Record(schema.toAvroSchema) {{ put("date", 
x) }}
+      converter(record).get(0)
+    })
+
+    assert(dateOutputData(0).toString === 
LocalDate.ofEpochDay(dateInputData(0)).toString)
+    assert(dateOutputData(1).toString === 
LocalDate.ofEpochDay(dateInputData(1)).toString)
+    assert(dateOutputData(2).toString === 
LocalDate.ofEpochDay(dateInputData(2)).toString)
+  }
 }

Reply via email to