yihua commented on code in PR #13882:
URL: https://github.com/apache/hudi/pull/13882#discussion_r2345511616
##########
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) {
Review Comment:
Do we want to validate the types before clustering to make sure the write
behavior of Avro and Row writer are aligned, which serves as another validation
to make sure any future change in either Avro or Row writer will be caught by
this test?
--
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]