anoopj commented on code in PR #3015:
URL: https://github.com/apache/iceberg-rust/pull/3015#discussion_r3844664953


##########
crates/iceberg/src/arrow/caching_delete_file_loader.rs:
##########
@@ -374,16 +383,51 @@ impl CachingDeleteFileLoader {
                     ));
                 }
 
-                result
-                    .entry(file_path.to_string())
-                    .or_default()
-                    .insert(pos as u64);
+                if run_path != Some(file_path) {
+                    if let Some(prev_path) = run_path {
+                        Self::merge_delete_positions(&mut result, prev_path, 
&run_positions);
+                        run_positions.clear();
+                    }
+
+                    run_path = Some(file_path);
+                }
+
+                run_positions.push(pos as u64);
+            }
+
+            if let Some(prev_path) = run_path {
+                Self::merge_delete_positions(&mut result, prev_path, 
&run_positions);
+                run_positions.clear();
             }
         }
 
         Ok(result)
     }
 
+    /// Marks every position in `positions` as deleted for `file_path`, merging
+    /// into any delete vector already recorded for that file.
+    fn merge_delete_positions(
+        result: &mut HashMap<String, DeleteVector>,
+        file_path: &str,
+        positions: &[u64],
+    ) {
+        // Callers only flush a run after pushing at least one position onto 
it.
+        debug_assert!(!positions.is_empty());
+
+        let delete_vector = result.entry(file_path.to_string()).or_default();
+        // A run is a strictly ascending slice in the spec-compliant case, 
which
+        // `insert_positions` bulk-appends in one pass. Fall back to 
per-position
+        // inserts when the append precondition doesn't hold (unsorted rows, 
or a
+        // run that overlaps positions already recorded from an earlier batch).
+        // `insert` is idempotent, so re-inserting any prefix the failed append
+        // already added is harmless.
+        if delete_vector.insert_positions(positions).is_err() {

Review Comment:
   Added a log before the fallback. Went with `tracing::debug!` rather than 
`warn!:` because as you note in the "strictly ascending" thread, spec-compliant 
files with duplicate positions land on this path too, so warn! would fire on 
valid input.  I also skipped the match on `PreconditionFailed` + propagate



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to