sdd commented on code in PR #652:
URL: https://github.com/apache/iceberg-rust/pull/652#discussion_r1893620855


##########
crates/iceberg/src/delete_file_index.rs:
##########
@@ -0,0 +1,95 @@
+use std::future::Future;
+use std::pin::Pin;
+use std::sync::{Arc, RwLock};
+use std::task::{Context, Poll};
+
+use futures::channel::mpsc::Receiver;
+use futures::{StreamExt, TryStreamExt};
+
+use crate::runtime::spawn;
+use crate::scan::FileScanTaskDeleteFile;
+use crate::spec::DataFile;
+use crate::{Error, Result};
+
+type DeleteFileIndexResult = Result<Option<Arc<Vec<FileScanTaskDeleteFile>>>>;
+
+/// Safely shareable on-demand-populated delete file index.
+///
+/// Constructed during the file plan phase of a table scan from a channel that 
will
+/// receive the details of all delete files that can possibly apply to a scan.
+/// Asynchronously retrieves and lazily processes of all the delete files from 
FileIO
+/// concurrently whilst the plan proceeds with collating all of the applicable 
data files.
+/// Awaited on when constructing the resulting FileScanTask for each selected 
data file
+/// in order to populate the list of delete files to include in each 
`FileScanTask`.
+#[derive(Debug, Clone)]
+pub(crate) struct DeleteFileIndex {
+    files: Arc<RwLock<Option<DeleteFileIndexResult>>>,
+}
+
+#[derive(Debug, Clone)]
+pub(crate) struct DeleteFileIndexFuture {
+    files: Arc<RwLock<Option<DeleteFileIndexResult>>>,
+}
+
+impl Future for DeleteFileIndexFuture {
+    type Output = DeleteFileIndexResult;
+
+    fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> 
{
+        let Ok(guard) = self.files.try_read() else {
+            return Poll::Pending;
+        };
+
+        if let Some(value) = guard.as_ref() {
+            Poll::Ready(match value.as_ref() {
+                Ok(deletes) => Ok(deletes.clone()),
+                Err(err) => Err(Error::new(err.kind(), err.message())),
+            })
+        } else {
+            Poll::Pending
+        }
+    }
+}
+
+impl DeleteFileIndex {
+    pub(crate) fn from_receiver(receiver: 
Receiver<Result<FileScanTaskDeleteFile>>) -> Self {
+        let delete_file_stream = receiver.boxed();
+        let files = Arc::new(RwLock::new(None));
+
+        // spawn a task to handle accumulating all the DeleteFiles that are 
streamed into the
+        // index through the receiver channel. Update the `None` inside the 
`RwLock` to a `Some`
+        // once the stream has been exhausted so that any consumers awaiting 
on the Future returned
+        // by DeleteFileIndex::get_deletes_for_data_file can proceed
+        spawn({

Review Comment:
   Sure, will take a look! 



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

Reply via email to