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


##########
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:
   [P2] Serialize statistics with nullable field types
   
   Please make the statistics serializer's fields nullable, as 
SimpleStatsConverter already does. For a valid INT NOT NULL table with 
metadata.stats-mode=counts, merged min/max are null, but this serializer uses 
the original NOT NULL getter and throws while unboxing the bound. I reproduced 
this with two real Parquet inputs: all 20 rows survive via normal fallback, but 
the fast-path HIT stays 0; making only the serializer fields nullable produces 
HIT=1.
   
   Because copier.copy has already completed before buildResult invokes this 
serializer, each such compaction first writes and deletes a full copied output 
and then re-reads/re-encodes the inputs. Add a NOT NULL primitive + 
counts-stats regression asserting that the fast path actually hits, rather than 
only checking the fallback result.



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