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


##########
xtable-core/src/test/java/org/apache/xtable/iceberg/TestIcebergConversionSource.java:
##########
@@ -259,6 +277,76 @@ void testGetCurrentSnapshotForEmptyTable(@TempDir Path 
workingDir) throws IOExce
     verify(spyDataFileExtractor, never()).fromIceberg(any(), any(), any());
   }
 
+  @Test
+  void testSyncToDeltaWithMissingColumnStats(@TempDir Path workingDir) throws 
IOException {

Review Comment:
   Split it. `TestIcebergConversionSource` now only checks the `ColumnStat`s 
the Iceberg source reads for a data file with missing sizes and null counts. 
The Delta handling is tested in `TestDeltaStatsExtractor` and 
`TestDeltaKernelDataFileUpdatesExtractor`, which take `ColumnStat`s as input, 
so neither test needs the other format.
   



##########
xtable-core/src/main/java/org/apache/xtable/iceberg/IcebergColumnStatsConverter.java:
##########
@@ -93,20 +93,26 @@ public List<ColumnStat> fromIceberg(
       Map<Integer, Long> size,
       Map<Integer, ByteBuffer> minValues,
       Map<Integer, ByteBuffer> maxValues) {
-    if (valueCounts == null || valueCounts.isEmpty()) {
+    // Iceberg writers may omit any of these metrics. A field without a null 
count is skipped, like
+    // one without a value count, since a null count of zero would let targets 
skip the file for
+    // IS NULL filters. A missing column size is reported as zero.
+    if (valueCounts == null || valueCounts.isEmpty() || nullCounts == null) {
       return Collections.emptyList();
     }
     return fields.stream()
-        .filter(field -> valueCounts.containsKey(field.getFieldId()))
+        .filter(
+            field ->
+                valueCounts.containsKey(field.getFieldId())
+                    && nullCounts.containsKey(field.getFieldId()))
         .map(
             field -> {
               Integer fieldId = field.getFieldId();
               long numValues = valueCounts.get(fieldId);
               long numNulls = nullCounts.get(fieldId);
-              long totalSize = size.get(fieldId);
+              long totalSize = size == null ? 0L : size.getOrDefault(fieldId, 
0L);

Review Comment:
   Done in 77cc50b: `totalSize` is now a `Long` that is null when unknown, and 
so is `numNulls` (see the next thread). The Iceberg target now leaves an 
unknown size out of `column_sizes`. Hudi has no way to store an unknown size 
and does not prune on it, so it still gets 0.
   



##########
xtable-core/src/main/java/org/apache/xtable/iceberg/IcebergColumnStatsConverter.java:
##########
@@ -93,20 +93,26 @@ public List<ColumnStat> fromIceberg(
       Map<Integer, Long> size,
       Map<Integer, ByteBuffer> minValues,
       Map<Integer, ByteBuffer> maxValues) {
-    if (valueCounts == null || valueCounts.isEmpty()) {
+    // Iceberg writers may omit any of these metrics. A field without a null 
count is skipped, like
+    // one without a value count, since a null count of zero would let targets 
skip the file for
+    // IS NULL filters. A missing column size is reported as zero.
+    if (valueCounts == null || valueCounts.isEmpty() || nullCounts == null) {

Review Comment:
   Yes. Now that `numNulls` is nullable, the field keeps its value count and 
bounds and only the null count is null (0776548), and the Delta and Iceberg 
targets just leave the null count out. Hudi can't store an unknown null count, 
and dropping only that column would let a filter on it plus another column skip 
the file, so in Hudi such a file gets no column stats and is always read.
   



##########
xtable-core/src/main/java/org/apache/xtable/iceberg/IcebergColumnStatsConverter.java:
##########
@@ -93,20 +93,26 @@ public List<ColumnStat> fromIceberg(
       Map<Integer, Long> size,
       Map<Integer, ByteBuffer> minValues,
       Map<Integer, ByteBuffer> maxValues) {
-    if (valueCounts == null || valueCounts.isEmpty()) {
+    // Iceberg writers may omit any of these metrics. A field without a null 
count is skipped, like
+    // one without a value count, since a null count of zero would let targets 
skip the file for
+    // IS NULL filters. A missing column size is reported as zero.
+    if (valueCounts == null || valueCounts.isEmpty() || nullCounts == null) {
       return Collections.emptyList();
     }
     return fields.stream()
-        .filter(field -> valueCounts.containsKey(field.getFieldId()))
+        .filter(
+            field ->
+                valueCounts.containsKey(field.getFieldId())
+                    && nullCounts.containsKey(field.getFieldId()))

Review Comment:
   For a file read from a manifest, the values can't be null, since `DataFile` 
declares each map's values as required. But `ContentFile` and `Metrics` don't 
promise that, so a null value is now treated like a missing key (0776548).
   



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