hbgstc123 commented on code in PR #9660:
URL: https://github.com/apache/paimon/pull/9660#discussion_r4056778086


##########
paimon-core/src/main/java/org/apache/paimon/stats/SimpleStatsMerger.java:
##########
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.stats;
+
+import org.apache.paimon.data.BinaryArray;
+import org.apache.paimon.data.GenericRow;
+import org.apache.paimon.data.InternalArray;
+import org.apache.paimon.data.InternalRow;
+import org.apache.paimon.data.serializer.InternalRowSerializer;
+import org.apache.paimon.io.DataFileMeta;
+import org.apache.paimon.types.DataType;
+import org.apache.paimon.types.RowType;
+import org.apache.paimon.utils.SortUtil;
+
+import javax.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.apache.paimon.stats.SimpleStats.EMPTY_STATS;
+
+/** Utility to merge {@link SimpleStats} from multiple files with the same 
stats schema. */
+public class SimpleStatsMerger {
+
+    private SimpleStatsMerger() {}
+
+    public static SimpleStats merge(List<SimpleStats> statsList, RowType 
rowType) {
+        return merge(statsList, rowType, null);
+    }
+
+    public static SimpleStats merge(
+            List<SimpleStats> statsList, RowType rowType, @Nullable 
List<String> valueStatsCols) {
+        if (statsList.isEmpty()) {
+            return EMPTY_STATS;
+        }
+
+        RowType statsRowType = valueStatsCols == null ? rowType : 
rowType.project(valueStatsCols);
+        int fieldCount = statsRowType.getFieldCount();
+        InternalRowSerializer serializer = new 
InternalRowSerializer(statsRowType);

Review Comment:
   Thanks for catching this. Fixed by making the stats row type's fields 
nullable in `SimpleStatsMerger.merge`, mirroring `SimpleStatsConverter`, which 
covers both the serializer and the field getters.
   
   Added regressions:
   - `SimpleStatsMergerTest#testMergeWithNotNullFieldType`: NOT NULL INT + null 
min/max bounds (counts stats mode). Verified it throws the exact NPE you 
described without the fix.
   - 
`ParquetFastPathCompactRewriterTest#testFastPathHitWithNotNullColumnAndCountsStatsMode`:
 NOT NULL primitive + `metadata.stats-mode=counts` end-to-end, asserting 
`HIT_COUNT == 1` (no silent fallback) plus row content and null min/max bounds 
on the compacted file.



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