From 87483b40a284b2775d61b7712e4bee92d24a2a96 Mon Sep 17 00:00:00 2001 From: Alon Agmon <54080741+a-agmon@users.noreply.github.com> Date: Fri, 27 Sep 2024 04:40:08 +0300 Subject: [PATCH] making table provider pub (#650) Co-authored-by: Alon Agmon --- crates/integrations/datafusion/src/lib.rs | 1 + crates/integrations/datafusion/src/table.rs | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/integrations/datafusion/src/lib.rs b/crates/integrations/datafusion/src/lib.rs index c40290116..b64f8fb8e 100644 --- a/crates/integrations/datafusion/src/lib.rs +++ b/crates/integrations/datafusion/src/lib.rs @@ -24,3 +24,4 @@ pub use error::*; mod physical_plan; mod schema; mod table; +pub use table::*; diff --git a/crates/integrations/datafusion/src/table.rs b/crates/integrations/datafusion/src/table.rs index 016c6c00f..f12d41eec 100644 --- a/crates/integrations/datafusion/src/table.rs +++ b/crates/integrations/datafusion/src/table.rs @@ -33,7 +33,7 @@ use crate::physical_plan::scan::IcebergTableScan; /// Represents a [`TableProvider`] for the Iceberg [`Catalog`], /// managing access to a [`Table`]. -pub(crate) struct IcebergTableProvider { +pub struct IcebergTableProvider { /// A table in the catalog. table: Table, /// A reference-counted arrow `Schema`. @@ -56,6 +56,13 @@ impl IcebergTableProvider { Ok(IcebergTableProvider { table, schema }) } + + /// Asynchronously tries to construct a new [`IcebergTableProvider`] + /// using the given table. Can be used to create a table provider from an existing table regardless of the catalog implementation. + pub async fn try_new_from_table(table: Table) -> Result { + let schema = Arc::new(schema_to_arrow_schema(table.metadata().current_schema())?); + Ok(IcebergTableProvider { table, schema }) + } } #[async_trait]