the-other-tim-brown commented on code in PR #1018:
URL: https://github.com/apache/incubator-xtable/pull/1018#discussion_r4727642590
##########
xtable-core/src/test/java/org/apache/xtable/ITConversionController.java:
##########
@@ -403,6 +403,42 @@ public void
testVariousOperationsDeltaKernelTarget(SyncMode syncMode, boolean is
}
}
+ // A Hudi timestamp-millis column has its stats in millis. Delta readers
skip files using the
+ // min and max stats in the Delta log, so stats written in the wrong unit
drop rows from a read
+ // that filters on the column. Runs against both the Standalone and the
Kernel Delta target.
+ @ParameterizedTest(name = "useKernelTarget={0}")
+ @ValueSource(booleans = {false, true})
+ public void testMillisTimestampFilterDeltaTarget(boolean useKernelTarget) {
Review Comment:
Instead of adding a new IT, let's update
`testVariousOperationsDeltaKernelTarget` to do the same filtering. The ITs are
quite heavy already so I want to improve existing tests where possible.
##########
xtable-core/src/test/java/org/apache/xtable/kernel/TestDeltaKernelDataFileUpdatesExtractor.java:
##########
@@ -458,6 +464,131 @@ public void testDifferentialSyncWithExistingData() throws
IOException {
// Note: file2 should not appear in actions as it's unchanged
}
+ @Test
+ public void testTimestampStatsUseFieldPrecision() throws IOException {
+ // Range stores TIMESTAMP and TIMESTAMP_NTZ stats as millis or micros,
depending on the field's
+ // TIMESTAMP_PRECISION. Sources with millisecond timestamps (Hudi, Paimon,
Parquet) send millis.
+ Instant min = Instant.parse("2024-03-15T10:20:30Z");
+ Instant max = Instant.parse("2024-03-16T11:22:33Z");
+ InternalField tsMillis = timestampField("ts_millis",
InternalType.TIMESTAMP, MILLIS);
+ InternalField tsMicros = timestampField("ts_micros",
InternalType.TIMESTAMP, MICROS);
+ InternalField ntzMillis = timestampField("ntz_millis",
InternalType.TIMESTAMP_NTZ, MILLIS);
+ InternalField ntzMicros = timestampField("ntz_micros",
InternalType.TIMESTAMP_NTZ, MICROS);
+ InternalSchema schema =
+ InternalSchema.builder()
+ .name("record")
+ .dataType(InternalType.RECORD)
+ .fields(Arrays.asList(tsMillis, tsMicros, ntzMillis, ntzMicros))
+ .build();
+ List<ColumnStat> columnStats =
+ Arrays.asList(
+ millisStat(tsMillis, min, max),
+ microsStat(tsMicros, min, max),
+ millisStat(ntzMillis, min, max),
+ microsStat(ntzMicros, min, max));
+
+ Path dataFilePath = tempDir.resolve("ts_data.parquet");
+ Files.createFile(dataFilePath);
+ InternalDataFile dataFile =
+ InternalDataFile.builder()
+ .physicalPath(dataFilePath.toString())
+ .fileSizeBytes(1024L)
+ .lastModified(Instant.now().toEpochMilli())
+ .recordCount(10L)
+ .partitionValues(Collections.emptyList())
+ .columnStats(columnStats)
+ .build();
+ DeltaKernelDataFileUpdatesExtractor statsExtractor =
+ DeltaKernelDataFileUpdatesExtractor.builder()
+ .engine(engine)
+ .basePath(tempDir.toString())
+ .includeColumnStats(true)
+ .build();
+ Table table = Table.forPath(engine,
tempDir.resolve("new_table").toString());
+
+ List<RowBackedAction> actions =
+ JavaConverters.seqAsJavaList(
+ statsExtractor.applySnapshot(
+ table,
+ Collections.singletonList(
+ PartitionFileGroup.builder()
+ .files(Collections.singletonList(dataFile))
+ .partitionValues(Collections.emptyList())
+ .build()),
+ schema,
+ null));
+ assertEquals(1, actions.size());
+ JsonNode kernelStats =
+ new ObjectMapper().readTree(((AddFile)
actions.get(0)).getStatsJson().get());
Review Comment:
Nit: `ObjectMapper` is expensive to initialize so we should just create a
single instance for the test class as a `private static final` variable
--
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]