Skip to content

Commit 3973099

Browse files
committed
refactor drop method
1 parent 644bac4 commit 3973099

7 files changed

Lines changed: 12 additions & 38 deletions

File tree

crates/catalog/glue/src/catalog.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -677,12 +677,7 @@ impl Catalog for GlueCatalog {
677677
async fn purge_table(&self, table: &TableIdent) -> Result<()> {
678678
let table_info = self.load_table(table).await?;
679679
self.drop_table(table).await?;
680-
iceberg::drop_table_data(
681-
table_info.file_io(),
682-
table_info.metadata(),
683-
table_info.metadata_location(),
684-
)
685-
.await
680+
iceberg::drop_table_data(table_info).await
686681
}
687682

688683
/// Asynchronously checks the existence of a specified table

crates/catalog/hms/src/catalog.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -624,12 +624,7 @@ impl Catalog for HmsCatalog {
624624
async fn purge_table(&self, table: &TableIdent) -> Result<()> {
625625
let table_info = self.load_table(table).await?;
626626
self.drop_table(table).await?;
627-
iceberg::drop_table_data(
628-
table_info.file_io(),
629-
table_info.metadata(),
630-
table_info.metadata_location(),
631-
)
632-
.await
627+
iceberg::drop_table_data(table_info).await
633628
}
634629

635630
/// Asynchronously checks the existence of a specified table

crates/catalog/sql/src/catalog.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -774,12 +774,7 @@ impl Catalog for SqlCatalog {
774774
async fn purge_table(&self, table: &TableIdent) -> Result<()> {
775775
let table_info = self.load_table(table).await?;
776776
self.drop_table(table).await?;
777-
iceberg::drop_table_data(
778-
table_info.file_io(),
779-
table_info.metadata(),
780-
table_info.metadata_location(),
781-
)
782-
.await
777+
iceberg::drop_table_data(table_info).await
783778
}
784779

785780
async fn load_table(&self, identifier: &TableIdent) -> Result<Table> {

crates/iceberg/src/catalog/memory/catalog.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,7 @@ impl Catalog for MemoryCatalog {
343343
async fn purge_table(&self, table_ident: &TableIdent) -> Result<()> {
344344
let table_info = self.load_table(table_ident).await?;
345345
self.drop_table(table_ident).await?;
346-
crate::catalog::utils::drop_table_data(
347-
table_info.file_io(),
348-
table_info.metadata(),
349-
table_info.metadata_location(),
350-
)
351-
.await
346+
crate::catalog::utils::drop_table_data(table_info).await
352347
}
353348

354349
/// Check if a table exists in the catalog.

crates/iceberg/src/catalog/utils.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use futures::{TryStreamExt, stream};
2323

2424
use crate::Result;
2525
use crate::io::FileIO;
26-
use crate::spec::{ManifestListReader, TableMetadata, TableMetadataRef};
26+
use crate::table::Table;
2727

2828
const DELETE_CONCURRENCY: usize = 10;
2929

@@ -36,22 +36,16 @@ const DELETE_CONCURRENCY: usize = 10;
3636
/// Data files within manifests are only deleted if the `gc.enabled` table
3737
/// property is `true` (the default), to avoid corrupting other tables that
3838
/// may share the same data files.
39-
pub async fn drop_table_data(
40-
io: &FileIO,
41-
metadata: &TableMetadata,
42-
metadata_location: Option<&str>,
43-
) -> Result<()> {
39+
pub async fn drop_table_data(table_info: Table) -> Result<()> {
4440
let mut manifest_lists_to_delete: HashSet<String> = HashSet::new();
4541
let mut manifests_to_delete: HashSet<String> = HashSet::new();
4642

47-
let metadata_ref = TableMetadataRef::new(metadata.clone());
43+
let metadata = table_info.metadata_ref();
44+
let io = table_info.file_io();
4845
// Load all manifest lists concurrently
4946
let results: Vec<_> =
5047
futures::future::try_join_all(metadata.snapshots().map(|snapshot| async {
51-
let manifest_list =
52-
ManifestListReader::new(snapshot.clone(), io.clone(), metadata_ref.clone())
53-
.load()
54-
.await?;
48+
let manifest_list = table_info.manifest_list_reader(snapshot).load().await?;
5549
Ok::<_, crate::Error>((snapshot.manifest_list().to_string(), manifest_list))
5650
}))
5751
.await?;
@@ -101,7 +95,7 @@ pub async fn drop_table_data(
10195
.await?;
10296

10397
// Delete the current metadata file
104-
if let Some(location) = metadata_location {
98+
if let Some(location) = table_info.metadata_location() {
10599
io.delete(location).await?;
106100
}
107101

crates/iceberg/src/spec/manifest_list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl ManifestList {
9292

9393
/// A manifest list reader that encapsulates the logic for loading and parsing a [`ManifestList`]
9494
/// from a snapshot.
95-
pub struct ManifestListReader {
95+
pub(crate) struct ManifestListReader {
9696
snapshot: SnapshotRef,
9797
file_io: FileIO,
9898
table_metadata: TableMetadataRef,

crates/iceberg/src/table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl Table {
265265
}
266266

267267
/// Creates a [`ManifestListReader`] for the given snapshot.
268-
pub fn manifest_list_reader(&self, snapshot: &SnapshotRef) -> ManifestListReader {
268+
pub(crate) fn manifest_list_reader(&self, snapshot: &SnapshotRef) -> ManifestListReader {
269269
ManifestListReader::new(
270270
snapshot.clone(),
271271
self.file_io.clone(),

0 commit comments

Comments
 (0)