Indian-boult commented on code in PR #1018:
URL: https://github.com/apache/incubator-xtable/pull/1018#discussion_r4727697728


##########
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:
   Done in 66addaa. The test class now has one `private static final 
ObjectMapper MAPPER`, and the older test that built its own mapper uses it too.
   



##########
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:
   Done in 66addaa. The separate IT is gone, and 
`testVariousOperationsDeltaKernelTarget` now also checks a filter on 
`timestamp_millis_nullable_field` after the deletes. The Standalone case the 
old IT ran is dropped with it, since this PR only changes the Kernel target.
   
   It still catches the bug. With the extractor from main, all four cases fail 
on that filter with 57 rows from the source against 0 from the Delta target, 
and with the fix they pass. I also merged main into the branch in 5e9015e.
   



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