QuakeWang commented on code in PR #703:
URL: https://github.com/apache/paimon-rust/pull/703#discussion_r3746733223


##########
crates/paimon/src/table/table_scan.rs:
##########
@@ -394,33 +394,56 @@ fn split_row_ranges_for_files(
     Ok(Some(split_ranges))
 }
 
+fn scan_predicate_field_ids(predicates: &[Predicate], schema_fields: 
&[DataField]) -> HashSet<i32> {
+    let mut leaf_refs = Vec::new();
+    for predicate in predicates {
+        crate::arrow::residual::collect_predicate_leaf_refs(predicate, &mut 
leaf_refs);
+    }
+    leaf_refs
+        .into_iter()
+        // `_ROW_ID` uses a placeholder leaf index, so match the scanner's 
name-based resolution.
+        .filter_map(|(column, _)| find_field_id_by_name(schema_fields, column))
+        .collect()
+}
+
 fn retain_index_manifest_entry(
     entry: &IndexManifestEntry,
     global_index_needed: bool,
     deletion_vectors_needed: bool,
 ) -> bool {
-    (deletion_vectors_needed && entry.index_file.index_type == 
DELETION_VECTORS_INDEX_TYPE)
-        || (global_index_needed
-            && 
normalize_sorted_global_index_type(&entry.index_file.index_type).is_some())
+    entry.kind == FileKind::Add
+        && ((deletion_vectors_needed && entry.index_file.index_type == 
DELETION_VECTORS_INDEX_TYPE)
+            || (global_index_needed
+                && 
normalize_sorted_global_index_type(&entry.index_file.index_type).is_some()))
 }
 
 fn retain_index_manifest_entry_for_scan(
     entry: &IndexManifestEntry,
     global_index_needed: bool,
     deletion_vectors_needed: bool,
     partition_filter: Option<&PartitionFilter>,
+    predicate_field_ids: &HashSet<i32>,
 ) -> crate::Result<bool> {
     if !retain_index_manifest_entry(entry, global_index_needed, 
deletion_vectors_needed) {
         return Ok(false);
     }
-    // Deletion vectors are selected by partition and bucket when splits are 
built.
+    if let Some(filter) = partition_filter {
+        if !filter.matches_entry(&entry.partition)? {
+            return Ok(false);
+        }
+    }
     if 
normalize_sorted_global_index_type(&entry.index_file.index_type).is_none() {
         return Ok(true);
     }
-    partition_filter
-        .map(|filter| filter.matches_entry(&entry.partition))
-        .transpose()
-        .map(|matched| matched.unwrap_or(true))
+    let Some(global_index) = entry.index_file.global_index_meta.as_ref() else {
+        // Keep malformed entries so the scanner can preserve fail-loud 
validation.
+        return Ok(true);
+    };
+    Ok(predicate_field_ids.contains(&global_index.index_field_id)

Review Comment:
   @XiaoHongbo-Hope Good catch. This is intentional: unrelated indexes are 
pruned before `index_meta` validation, matching Java. I've updated the PR 
description to clarify the fail-loud scope.



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