wuchong commented on code in PR #2886:
URL: https://github.com/apache/fluss/pull/2886#discussion_r2988151915


##########
fluss-common/src/main/java/org/apache/fluss/record/DefaultLogRecordBatchStatistics.java:
##########
@@ -0,0 +1,472 @@
+/*
+ * 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.fluss.record;
+
+import org.apache.fluss.memory.MemorySegment;
+import org.apache.fluss.row.BinaryString;
+import org.apache.fluss.row.Decimal;
+import org.apache.fluss.row.InternalArray;
+import org.apache.fluss.row.InternalMap;
+import org.apache.fluss.row.InternalRow;
+import org.apache.fluss.row.TimestampLtz;
+import org.apache.fluss.row.TimestampNtz;
+import org.apache.fluss.row.aligned.AlignedRow;
+import org.apache.fluss.types.RowType;
+
+import java.util.Arrays;
+
+import static org.apache.fluss.utils.Preconditions.checkArgument;
+
+/**
+ * Byte view implementation of LogRecordBatchStatistics that provides 
zero-copy access to statistics
+ * data without creating heap objects or copying data. Uses AlignedRow for 
better performance.
+ * Supports schema-aware format with partial column statistics.
+ *
+ * <h3>Statistics Layout Format</h3>
+ *
+ * <p>The binary format of statistics data stored in memory segment:
+ *
+ * <pre>
+ * 
+------------------+---------+-------------------------------------------------------+
+ * | Field            | Size    | Description                                  
         |
+ * 
+------------------+---------+-------------------------------------------------------+
+ * | Version          | 1 byte  | Statistics format version                    
         |
+ * | Column Count     | 2 bytes | Number of columns with statistics            
         |
+ * | Column Indexes   | 2*N     | Field indexes in original schema (2 bytes 
each)      |
+ * | Null Counts      | 4*N     | Null counts for each stats column (4 bytes 
each)     |
+ * | Min Values Size  | 4 bytes | Size of min values AlignedRow data           
        |
+ * | Min Values Data  | Variable| AlignedRow containing minimum values         
         |
+ * | Max Values Size  | 4 bytes | Size of max values AlignedRow data           
        |
+ * | Max Values Data  | Variable| AlignedRow containing maximum values         
         |
+ * 
+------------------+---------+-------------------------------------------------------+
+ * </pre>
+ *
+ * <p>The statistics support partial column statistics through 
statsIndexMapping, which maps
+ * statistics column positions to the original table schema field indexes. 
This allows efficient
+ * storage when only a subset of columns have statistics collected.
+ */
+public class DefaultLogRecordBatchStatistics implements 
LogRecordBatchStatistics {
+
+    private final MemorySegment segment;
+    private final int position;
+    private final int size;
+    private final RowType rowType;
+    private final int schemaId;
+
+    private final int[] statsIndexMapping;
+
+    private final Long[] statsNullCounts;
+
+    // Offsets for min/max values in the byte array
+    private final int minValuesOffset;
+    private final int maxValuesOffset;
+    private final int minValuesSize;
+    private final int maxValuesSize;
+
+    private InternalRow cachedMinRow;
+    private InternalRow cachedMaxRow;
+    private Long[] cachedNullCounts;
+
+    private final int[] reversedStatsIndexMapping;
+
+    /** Constructor for schema-aware statistics. */
+    public DefaultLogRecordBatchStatistics(
+            MemorySegment segment,
+            int position,
+            int size,
+            RowType rowType,
+            int schemaId,
+            Long[] nullCounts,
+            int minValuesOffset,
+            int maxValuesOffset,
+            int minValuesSize,
+            int maxValuesSize,
+            int[] statsIndexMapping) {
+        this.segment = segment;
+        this.position = position;
+        this.size = size;
+        this.rowType = rowType;
+        this.schemaId = schemaId;
+        this.statsNullCounts = nullCounts;
+        this.minValuesOffset = minValuesOffset;
+        this.maxValuesOffset = maxValuesOffset;
+        this.minValuesSize = minValuesSize;
+        this.maxValuesSize = maxValuesSize;
+        this.statsIndexMapping = statsIndexMapping;
+        this.reversedStatsIndexMapping = new int[rowType.getFieldCount()];
+        Arrays.fill(this.reversedStatsIndexMapping, -1);
+        for (int statsIndex = 0; statsIndex < statsIndexMapping.length; 
statsIndex++) {
+            this.reversedStatsIndexMapping[statsIndexMapping[statsIndex]] = 
statsIndex;
+        }
+    }
+
+    @Override
+    public InternalRow getMinValues() {
+        if (minValuesSize == 0) {
+            return null;

Review Comment:
   Since we always serialize the max and min InternalRow for statistics, a 
`minValuesSize` of 0 is invalid and should be validated within the constructor. 
This approach simplifies the usage of `getMinValues` by eliminating the need to 
handle the nullability of the returned value.



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