sdd commented on code in PR #982: URL: https://github.com/apache/iceberg-rust/pull/982#discussion_r2025403948
########## crates/iceberg/src/arrow/delete_file_manager.rs: ########## @@ -0,0 +1,564 @@ +// 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 std::collections::HashMap; +use std::future::Future; +use std::ops::BitOrAssign; +use std::pin::Pin; +use std::sync::{Arc, OnceLock, RwLock}; +use std::task::{Context, Poll}; + +use futures::channel::oneshot; +use futures::future::join_all; +use futures::{StreamExt, TryStreamExt}; +use roaring::RoaringTreemap; + +use crate::arrow::ArrowReader; +use crate::expr::Predicate::AlwaysTrue; +use crate::expr::{Bind, BoundPredicate, Predicate}; +use crate::io::FileIO; +use crate::scan::{ArrowRecordBatchStream, FileScanTask, FileScanTaskDeleteFile}; +use crate::spec::DataContentType; +use crate::{Error, ErrorKind, Result}; + +// Equality deletes may apply to more than one DataFile in a scan, and so +// the same equality delete file may be present in more than one invocation of +// DeleteFileManager::load_deletes in the same scan. We want to deduplicate these +// to avoid having to load them twice, so we immediately store cloneable futures in the +// state that can be awaited upon to get te EQ deletes. That way we can check to see if +// a load of each Eq delete file is already in progress and avoid starting another one. +#[derive(Debug, Clone)] +struct EqDelFuture { + result: OnceLock<Predicate>, +} + +impl EqDelFuture { + pub fn new() -> (oneshot::Sender<Predicate>, Self) { + let (tx, rx) = oneshot::channel(); + let result = OnceLock::new(); + + crate::runtime::spawn({ + let result = result.clone(); + async move { result.set(rx.await.unwrap()) } + }); + + (tx, Self { result }) + } +} + +impl Future for EqDelFuture { + type Output = Predicate; + + fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> { + match self.result.get() { + None => Poll::Pending, + Some(predicate) => Poll::Ready(predicate.clone()), + } + } +} + +#[derive(Debug, Default)] +struct DeleteFileManagerState { + // delete vectors and positional deletes get merged when loaded into a single delete vector + // per data file + delete_vectors: HashMap<String, RoaringTreemap>, + + // equality delete files are parsed into unbound `Predicate`s. We store them here as + // cloneable futures (see note below) + equality_deletes: HashMap<String, EqDelFuture>, +} + +type StateRef = Arc<RwLock<DeleteFileManagerState>>; + +#[derive(Clone, Debug)] +pub(crate) struct DeleteFileManager { + state: Arc<RwLock<DeleteFileManagerState>>, +} + +// Intermediate context during processing of a delete file task. +enum DeleteFileContext { + // TODO: Delete Vector loader from Puffin files + InProgEqDel(EqDelFuture), + PosDels(ArrowRecordBatchStream), + FreshEqDel { + batch_stream: ArrowRecordBatchStream, + sender: oneshot::Sender<Predicate>, + }, +} + +// Final result of the processing of a delete file task before +// results are fully merged into the DeleteFileManager's state +enum ParsedDeleteFileContext { + InProgEqDel(EqDelFuture), + DelVecs(HashMap<String, RoaringTreemap>), + EqDel, +} + +#[allow(unused_variables)] +impl DeleteFileManager { + pub(crate) fn new() -> DeleteFileManager { + Self { + state: Default::default(), + } + } + + pub(crate) async fn load_deletes( + &self, + delete_file_entries: &[FileScanTaskDeleteFile], + file_io: FileIO, + concurrency_limit_data_files: usize, + ) -> Result<()> { + /* + * Create a single stream of all delete file tasks irrespective of type, Review Comment: Done! -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org