Skip to content

Scan Delete Support Part 2: introduce DeleteFileManager skeleton. Use in ArrowReader #950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ port_scanner = "0.1.5"
rand = "0.8.5"
regex = "1.10.5"
reqwest = { version = "0.12.2", default-features = false, features = ["json"] }
roaring = "0.10"
rust_decimal = "1.31"
serde = { version = "1.0.204", features = ["rc"] }
serde_bytes = "0.11.15"
Expand Down
1 change: 1 addition & 0 deletions crates/iceberg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ parquet = { workspace = true, features = ["async"] }
paste = { workspace = true }
rand = { workspace = true }
reqwest = { workspace = true }
roaring = { workspace = true }
rust_decimal = { workspace = true }
serde = { workspace = true }
serde_bytes = { workspace = true }
Expand Down
93 changes: 93 additions & 0 deletions crates/iceberg/src/arrow/delete_file_manager.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// 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.

use crate::delete_vector::DeleteVector;
use crate::expr::BoundPredicate;
use crate::io::FileIO;
use crate::scan::{ArrowRecordBatchStream, FileScanTaskDeleteFile};
use crate::spec::SchemaRef;
use crate::{Error, ErrorKind, Result};

#[allow(unused)]
pub trait DeleteFileManager {
/// Read the delete file referred to in the task
///
/// Returns the raw contents of the delete file as a RecordBatch stream
fn read_delete_file(task: &FileScanTaskDeleteFile) -> Result<ArrowRecordBatchStream>;
}

#[allow(unused)]
#[derive(Clone, Debug)]
pub(crate) struct CachingDeleteFileManager {
file_io: FileIO,
concurrency_limit_data_files: usize,
}

impl DeleteFileManager for CachingDeleteFileManager {
fn read_delete_file(_task: &FileScanTaskDeleteFile) -> Result<ArrowRecordBatchStream> {
// TODO, implementation in https://github.com/apache/iceberg-rust/pull/982

Err(Error::new(
ErrorKind::FeatureUnsupported,
"Reading delete files is not yet supported",
))
}
}

#[allow(unused_variables)]
impl CachingDeleteFileManager {
pub fn new(file_io: FileIO, concurrency_limit_data_files: usize) -> CachingDeleteFileManager {
Self {
file_io,
concurrency_limit_data_files,
}
}

pub(crate) async fn load_deletes(
&self,
delete_file_entries: Vec<FileScanTaskDeleteFile>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should pass this in constructor, rather it should be in an argument of load_equality_delete method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, see second commit in this PR.

) -> Result<()> {
// TODO

if !delete_file_entries.is_empty() {
Err(Error::new(
ErrorKind::FeatureUnsupported,
"Reading delete files is not yet supported",
))
} else {
Ok(())
}
}

pub(crate) fn build_delete_predicate(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should return arrow record batch rather predicate here. Or we could have a method built on the one which returns arrow record batch. The reason is that different engines may evaluate it in different approaches.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've indicated within the newly-added trait definition that the basic file-to-record-batch-stream functionality is coming in a follow-up PR that I'll refactor so that it is used either in a struct that implements the trait or in a default implementation for the trait.

&self,
snapshot_schema: SchemaRef,
) -> Result<Option<BoundPredicate>> {
// TODO

Ok(None)
}

pub(crate) fn get_positional_delete_indexes_for_data_file(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to above comment, we should provide a base version with actual data (like arrow record batch) to give advanced users enough flexibility to do that. Also I don't think we should return internal data structure directly, maybe sth like following is better?

struct PositionDeleteIndex {

  bitmap: RoaringTreemap
}

Motivated by java version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding wrapping the RoaringBitmap in a PositionalDeleteIndex. I can do that, although the Java version's interface precludes us from using advance_to which would be very useful to have access to within the ArrowReader row selection / page skipping code that I have in the follow-up PR to this one, #951.

Would you be ok with your proposed struct PositionDeleteIndex exposing an .iter() method to return a public PositionDeleteIndexIter iterator, which itself implements advance_to?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be ok with your proposed struct PositionDeleteIndex exposing an .iter() method to return a public PositionDeleteIndexIter iterator, which itself implements advance_to?

I'm fine with that. My concern is not exposing too much internals data structures to, and I think the advance_to method is easy to understand as iceberg spec requires that position delete file should be sorted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The third commit in this PR is focussed on changes raised by your original comment here.

&self,
data_file_path: &str,
) -> Option<DeleteVector> {
// TODO

None
}
}
1 change: 1 addition & 0 deletions crates/iceberg/src/arrow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

mod schema;
pub use schema::*;
pub(crate) mod delete_file_manager;
mod reader;
pub(crate) mod record_batch_projector;
pub(crate) mod record_batch_transformer;
Expand Down
Loading
Loading