JingsongLi commented on code in PR #196:
URL: https://github.com/apache/paimon-rust/pull/196#discussion_r3031778175


##########
crates/paimon/src/table/table_scan.rs:
##########
@@ -166,6 +168,86 @@ fn partition_matches_predicate(
     }
 }
 
+#[derive(Debug, Clone)]
+struct FileStatsRows {
+    row_count: i64,
+    min_values: Option<BinaryRow>,
+    max_values: Option<BinaryRow>,
+    null_counts: Vec<i64>,
+}
+
+impl FileStatsRows {
+    /// Build file stats only when they are compatible with the current table 
schema.
+    ///
+    /// Schema-evolved files are conservatively skipped here so callers don't
+    /// accidentally interpret old stats rows using current field indexes.
+    fn try_from_data_file(
+        file: &DataFileMeta,
+        current_schema_id: i64,
+        expected_fields: usize,
+    ) -> Option<Self> {
+        if file.schema_id != current_schema_id {
+            return None;
+        }
+
+        let stats = Self {
+            row_count: file.row_count,
+            min_values: 
BinaryRow::from_serialized_bytes(file.value_stats.min_values()).ok(),
+            max_values: 
BinaryRow::from_serialized_bytes(file.value_stats.max_values()).ok(),
+            null_counts: file.value_stats.null_counts().clone(),
+        };
+
+        stats.arity_matches(expected_fields).then_some(stats)
+    }
+
+    fn null_count(&self, index: usize) -> Option<i64> {
+        self.null_counts.get(index).copied()
+    }
+
+    /// Check whether the stats rows have the expected number of fields.
+    ///
+    /// If either min or max BinaryRow has an arity different from
+    /// `expected_fields`, the stats were likely written in dense mode or
+    /// under a different schema — making index-based access unsafe.
+    fn arity_matches(&self, expected_fields: usize) -> bool {
+        let min_ok = self
+            .min_values
+            .as_ref()
+            .is_none_or(|r| r.arity() as usize == expected_fields);
+        let max_ok = self
+            .max_values
+            .as_ref()
+            .is_none_or(|r| r.arity() as usize == expected_fields);
+        let null_ok = self.null_counts.is_empty() || self.null_counts.len() == 
expected_fields;
+        min_ok && max_ok && null_ok
+    }
+}
+
+fn split_partition_and_data_predicates(

Review Comment:
   Can you align this implementation to Java 
`splitPartitionPredicatesAndDataPredicates`? 



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