Skip to content

Commit 333c65f

Browse files
committed
Split out load_table util to make it reusable with locked namespace states
Signed-off-by: DerGut <jannik.steinmann@gmx.de>
1 parent b4bc6dd commit 333c65f

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

crates/catalog/memory/src/catalog.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use std::collections::HashMap;
2121

2222
use async_trait::async_trait;
23-
use futures::lock::Mutex;
23+
use futures::lock::{Mutex, MutexGuard};
2424
use iceberg::io::FileIO;
2525
use iceberg::spec::{TableMetadata, TableMetadataBuilder};
2626
use iceberg::table::Table;
@@ -53,6 +53,23 @@ impl MemoryCatalog {
5353
warehouse_location,
5454
}
5555
}
56+
57+
/// Loads a table from the locked namespace state.
58+
async fn load_table_from_locked_namespace_state(
59+
&self,
60+
table_ident: &TableIdent,
61+
root_namespace_state: &MutexGuard<'_, NamespaceState>,
62+
) -> Result<Table> {
63+
let metadata_location = root_namespace_state.get_existing_table_location(table_ident)?;
64+
let metadata = self.read_metadata(&metadata_location).await?;
65+
66+
Table::builder()
67+
.identifier(table_ident.clone())
68+
.metadata(metadata)
69+
.metadata_location(metadata_location.to_string())
70+
.file_io(self.file_io.clone())
71+
.build()
72+
}
5673
}
5774

5875
#[async_trait]
@@ -223,17 +240,8 @@ impl Catalog for MemoryCatalog {
223240
async fn load_table(&self, table_ident: &TableIdent) -> Result<Table> {
224241
let root_namespace_state = self.root_namespace_state.lock().await;
225242

226-
let metadata_location = root_namespace_state.get_existing_table_location(table_ident)?;
227-
let input_file = self.file_io.new_input(metadata_location)?;
228-
let metadata_content = input_file.read().await?;
229-
let metadata = serde_json::from_slice::<TableMetadata>(&metadata_content)?;
230-
231-
Table::builder()
232-
.file_io(self.file_io.clone())
233-
.metadata_location(metadata_location.clone())
234-
.metadata(metadata)
235-
.identifier(table_ident.clone())
236-
.build()
243+
self.load_table_from_locked_namespace_state(table_ident, &root_namespace_state)
244+
.await
237245
}
238246

239247
/// Drop a table from the catalog.

0 commit comments

Comments
 (0)