yihua commented on code in PR #13882:
URL: https://github.com/apache/hudi/pull/13882#discussion_r2345478282


##########
hudi-spark-datasource/hudi-spark/src/test/java/org/apache/hudi/functional/TestSparkSortAndSizeClustering.java:
##########
@@ -130,24 +155,55 @@ public void writeAndClustering(boolean isRow) throws 
IOException {
 
     List<Row> rows = readRecords();
     assertEquals(numRecords, rows.size());
-    validateDecimalTypeAfterClustering(writeStats);
+    validateTypesAfterClustering(writeStats);
+    validateDateAndTimestampFields(rows, ts);
   }
 
-  // Validate that clustering produces decimals in legacy format
-  private void validateDecimalTypeAfterClustering(List<HoodieWriteStat> 
writeStats) {
+  private void validateDateAndTimestampFields(List<Row> rows, long ts) {
+    Schema schema = HoodieAvroUtils.addMetadataFields(getSchema(), false);
+    Timestamp timestamp = new Timestamp(ts);
+    int dateFieldIndex = schema.getField("date_nullable_field").pos();
+    int tsMillisFieldIndex = schema.getField("timestamp_millis_field").pos();
+    int tsMicrosNullableFieldIndex = 
schema.getField("timestamp_micros_nullable_field").pos();
+    int tsLocalMillisFieldIndex = 
schema.getField("timestamp_local_millis_nullable_field").pos();
+    int tsLocalMicrosFieldIndex = 
schema.getField("timestamp_local_micros_field").pos();
+    for (Row row : rows) {
+      assertEquals(timestamp, row.get(tsMillisFieldIndex));
+      if (!row.isNullAt(tsMicrosNullableFieldIndex)) {
+        assertEquals(timestamp, row.get(tsMicrosNullableFieldIndex));
+      }
+      if (!row.isNullAt(dateFieldIndex)) {
+        assertTrue(row.get(dateFieldIndex) instanceof Date);
+      }
+      if (!row.isNullAt(tsLocalMillisFieldIndex)) {
+        assertEquals(ts, row.get(tsLocalMillisFieldIndex));
+      }
+      assertEquals(ts * 1000L, row.get(tsLocalMicrosFieldIndex));
+    }
+  }
+
+  // Validate that clustering produces decimals in legacy format and lists in 
newer format. Assert that the unit is correct on the timestamps
+  private void validateTypesAfterClustering(List<HoodieWriteStat> writeStats) {
     writeStats.stream().map(writeStat -> new 
StoragePath(metaClient.getBasePath(), writeStat.getPath())).forEach(writtenPath 
-> {
       MessageType schema = ParquetUtils.readMetadata(storage, writtenPath)
           .getFileMetaData().getSchema();
-      int index = schema.getFieldIndex("height");
-      Type decimalType = schema.getFields().get(index);
+      int decimalFieldIndex = schema.getFieldIndex("decimal_field");
+      Type decimalType = schema.getFields().get(decimalFieldIndex);

Review Comment:
   Should the precision and scale of decimal type be validated too? Wondering 
if this PR fixes #11335 already.



##########
hudi-spark-datasource/hudi-spark/src/test/java/org/apache/hudi/functional/TestSparkSortAndSizeClustering.java:
##########
@@ -130,24 +155,55 @@ public void writeAndClustering(boolean isRow) throws 
IOException {
 
     List<Row> rows = readRecords();
     assertEquals(numRecords, rows.size());
-    validateDecimalTypeAfterClustering(writeStats);
+    validateTypesAfterClustering(writeStats);
+    validateDateAndTimestampFields(rows, ts);
   }
 
-  // Validate that clustering produces decimals in legacy format
-  private void validateDecimalTypeAfterClustering(List<HoodieWriteStat> 
writeStats) {
+  private void validateDateAndTimestampFields(List<Row> rows, long ts) {
+    Schema schema = HoodieAvroUtils.addMetadataFields(getSchema(), false);
+    Timestamp timestamp = new Timestamp(ts);
+    int dateFieldIndex = schema.getField("date_nullable_field").pos();
+    int tsMillisFieldIndex = schema.getField("timestamp_millis_field").pos();
+    int tsMicrosNullableFieldIndex = 
schema.getField("timestamp_micros_nullable_field").pos();
+    int tsLocalMillisFieldIndex = 
schema.getField("timestamp_local_millis_nullable_field").pos();
+    int tsLocalMicrosFieldIndex = 
schema.getField("timestamp_local_micros_field").pos();
+    for (Row row : rows) {
+      assertEquals(timestamp, row.get(tsMillisFieldIndex));
+      if (!row.isNullAt(tsMicrosNullableFieldIndex)) {
+        assertEquals(timestamp, row.get(tsMicrosNullableFieldIndex));
+      }
+      if (!row.isNullAt(dateFieldIndex)) {
+        assertTrue(row.get(dateFieldIndex) instanceof Date);

Review Comment:
   Also validate the exact value?



-- 
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]

Reply via email to