Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions crates/integrations/datafusion/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use std::sync;

use datafusion::arrow::datatypes;
use datafusion::error;
use iceberg::table;

impl crate::IcebergTableProvider {
Expand All @@ -28,4 +29,16 @@ impl crate::IcebergTableProvider {
catalog: Some(catalog),
}
}

/// Returns table to be used in operations.
/// If the catalog implementer is provided, loads a fresh table from it, otherwise clones the inner value.
pub(crate) fn table_to_use(&self) -> error::Result<table::Table> {
match self.catalog {
Some(ref catalog) => {
futures::executor::block_on(catalog.load_table(self.table.identifier()))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loading a table from local disk or shared drive, or S3 may take some time. Using block_on would block our runtime thread for that duration. Can we instead use async to avoid blocking?

.map_err(|e| error::DataFusionError::Internal(e.to_string()))
}
None => Ok(self.table.clone()),
}
}
}
2 changes: 1 addition & 1 deletion crates/integrations/datafusion/src/table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl TableProvider for IcebergTableProvider {
_limit: Option<usize>,
) -> DFResult<Arc<dyn ExecutionPlan>> {
Ok(Arc::new(IcebergTableScan::new(
self.table.clone(),
self.table_to_use()?, // This automatically updates available snapshots when starting a scan.
self.snapshot_id,
self.schema.clone(),
projection,
Expand Down