From 722fe1836ca2086785c2fe9338aaafa1d1a4127b Mon Sep 17 00:00:00 2001 From: Will Jones Date: Tue, 5 Mar 2024 11:51:47 -0800 Subject: [PATCH] fix: make checkout_latest force a reload (#1064) #1002 accidentally changed `checkout_latest` to do nothing if the table was already in latest mode. This PR makes sure it forces a reload of the table (if there is a newer version). --- rust/lancedb/src/table.rs | 8 ++++++++ rust/lancedb/src/table/dataset.rs | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/rust/lancedb/src/table.rs b/rust/lancedb/src/table.rs index 57df6d7e..7dc62fdb 100644 --- a/rust/lancedb/src/table.rs +++ b/rust/lancedb/src/table.rs @@ -636,9 +636,14 @@ impl NativeTable { }) } + /// Checkout the latest version of this [NativeTable]. + /// + /// This will force the table to be reloaded from disk, regardless of the + /// `read_consistency_interval` set. pub async fn checkout_latest(&self) -> Result { let mut dataset = self.dataset.duplicate().await; dataset.as_latest(self.read_consistency_interval).await?; + dataset.reload().await?; Ok(Self { dataset, ..self.clone() @@ -1943,6 +1948,9 @@ mod tests { match interval { None => { assert_eq!(table2.count_rows(None).await.unwrap(), 0); + let table2_native = + table2.as_native().unwrap().checkout_latest().await.unwrap(); + assert_eq!(table2_native.count_rows(None).await.unwrap(), 1); } Some(0) => { assert_eq!(table2.count_rows(None).await.unwrap(), 1); diff --git a/rust/lancedb/src/table/dataset.rs b/rust/lancedb/src/table/dataset.rs index 1772d5c1..322518e5 100644 --- a/rust/lancedb/src/table/dataset.rs +++ b/rust/lancedb/src/table/dataset.rs @@ -156,7 +156,7 @@ impl DatasetConsistencyWrapper { self.0.write().await.set_latest(dataset); } - async fn reload(&self) -> Result<()> { + pub async fn reload(&self) -> Result<()> { self.0.write().await.reload().await }