From 9000bd42746a7eaf21faf85091b6656982316f7b Mon Sep 17 00:00:00 2001 From: QP Hou Date: Sat, 9 Oct 2021 00:03:19 -0700 Subject: [PATCH] return lazy iterator in get tombstone methods (#452) --- rust/src/checkpoints.rs | 2 +- rust/src/delta.rs | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/rust/src/checkpoints.rs b/rust/src/checkpoints.rs index 1f3e93336c..60b1be7e80 100644 --- a/rust/src/checkpoints.rs +++ b/rust/src/checkpoints.rs @@ -168,7 +168,7 @@ fn parquet_bytes_from_state(state: &DeltaTableState) -> Result, Checkpoi let mut stats_conversions: Vec<(SchemaPath, SchemaDataType)> = Vec::new(); collect_stats_conversions(&mut stats_conversions, current_metadata.schema.get_fields()); - let mut tombstones = state.unexpired_tombstones(); + let mut tombstones = state.unexpired_tombstones().cloned().collect::>(); // if any, tombstones do not include extended file metadata, we must omit the extended metadata fields from the remove schema // See https://github.com/delta-io/delta/blob/master/PROTOCOL.md#add-file-and-remove-file diff --git a/rust/src/delta.rs b/rust/src/delta.rs index 42f1a081c6..4f8701ca28 100644 --- a/rust/src/delta.rs +++ b/rust/src/delta.rs @@ -392,13 +392,11 @@ impl DeltaTableState { /// List of unexpired tombstones (remove actions) representing files removed from table state. /// The retention period is set by `deletedFileRetentionDuration` with default value of 1 week. - pub fn unexpired_tombstones(&self) -> Vec { + pub fn unexpired_tombstones(&self) -> impl Iterator { let retention_timestamp = Utc::now().timestamp_millis() - self.tombstone_retention_millis; self.tombstones .iter() - .filter(|t| t.deletion_timestamp.unwrap_or(0) > retention_timestamp) - .cloned() - .collect() + .filter(move |t| t.deletion_timestamp.unwrap_or(0) > retention_timestamp) } /// Full list of add actions representing all parquet files that are part of the current @@ -1086,7 +1084,7 @@ impl DeltaTable { } /// Returns a vector of active tombstones (i.e. `Remove` actions present in the current delta log). - pub fn get_tombstones(&self) -> Vec { + pub fn get_tombstones(&self) -> impl Iterator { self.state.unexpired_tombstones() }