From a965c979dc2d2d7f78528b9195d9b535adf5704a Mon Sep 17 00:00:00 2001 From: Heran Lin Date: Mon, 24 Jun 2024 21:19:13 +0800 Subject: [PATCH 1/2] Return `&Arc` reference to inner trait object --- datafusion-cli/src/catalog.rs | 4 ++-- datafusion-cli/src/main.rs | 2 +- datafusion/core/src/execution/context/mod.rs | 2 +- datafusion/core/src/execution/session_state.rs | 8 ++++---- datafusion/expr/src/udaf.rs | 4 ++-- datafusion/expr/src/udf.rs | 4 ++-- datafusion/expr/src/udwf.rs | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/datafusion-cli/src/catalog.rs b/datafusion-cli/src/catalog.rs index faa657da6511..0ccbb85ad611 100644 --- a/datafusion-cli/src/catalog.rs +++ b/datafusion-cli/src/catalog.rs @@ -236,12 +236,12 @@ mod tests { fn setup_context() -> (SessionContext, Arc) { let mut ctx = SessionContext::new(); ctx.register_catalog_list(Arc::new(DynamicFileCatalog::new( - ctx.state().catalog_list(), + ctx.state().catalog_list().clone(), ctx.state_weak_ref(), ))); let provider = - &DynamicFileCatalog::new(ctx.state().catalog_list(), ctx.state_weak_ref()) + &DynamicFileCatalog::new(ctx.state().catalog_list().clone(), ctx.state_weak_ref()) as &dyn CatalogProviderList; let catalog = provider .catalog(provider.catalog_names().first().unwrap()) diff --git a/datafusion-cli/src/main.rs b/datafusion-cli/src/main.rs index f469fda4f960..6266ae6f561a 100644 --- a/datafusion-cli/src/main.rs +++ b/datafusion-cli/src/main.rs @@ -180,7 +180,7 @@ async fn main_inner() -> Result<()> { ctx.refresh_catalogs().await?; // install dynamic catalog provider that knows how to open files ctx.register_catalog_list(Arc::new(DynamicFileCatalog::new( - ctx.state().catalog_list(), + ctx.state().catalog_list().clone(), ctx.state_weak_ref(), ))); // register `parquet_metadata` table function to get metadata from parquet files diff --git a/datafusion/core/src/execution/context/mod.rs b/datafusion/core/src/execution/context/mod.rs index 57e94cad0626..8755f6fbe3fb 100644 --- a/datafusion/core/src/execution/context/mod.rs +++ b/datafusion/core/src/execution/context/mod.rs @@ -1831,7 +1831,7 @@ mod tests { let catalog_list_weak = { let state = ctx.state.read(); - Arc::downgrade(&state.catalog_list()) + Arc::downgrade(state.catalog_list()) }; drop(ctx); diff --git a/datafusion/core/src/execution/session_state.rs b/datafusion/core/src/execution/session_state.rs index 4173a8dcc403..5c87ec709c26 100644 --- a/datafusion/core/src/execution/session_state.rs +++ b/datafusion/core/src/execution/session_state.rs @@ -807,8 +807,8 @@ impl SessionState { } /// Return catalog list - pub fn catalog_list(&self) -> Arc { - self.catalog_list.clone() + pub fn catalog_list(&self) -> &Arc { + &self.catalog_list } /// set the catalog list @@ -835,8 +835,8 @@ impl SessionState { } /// Return [SerializerRegistry] for extensions - pub fn serializer_registry(&self) -> Arc { - self.serializer_registry.clone() + pub fn serializer_registry(&self) -> &Arc { + &self.serializer_registry } /// Return version of the cargo package that produced this query diff --git a/datafusion/expr/src/udaf.rs b/datafusion/expr/src/udaf.rs index a248518c2d94..c8362691452b 100644 --- a/datafusion/expr/src/udaf.rs +++ b/datafusion/expr/src/udaf.rs @@ -124,8 +124,8 @@ impl AggregateUDF { } /// Return the underlying [`AggregateUDFImpl`] trait object for this function - pub fn inner(&self) -> Arc { - self.inner.clone() + pub fn inner(&self) -> &Arc { + &self.inner } /// Adds additional names that can be used to invoke this function, in diff --git a/datafusion/expr/src/udf.rs b/datafusion/expr/src/udf.rs index e14b62f1c841..03650b1d4748 100644 --- a/datafusion/expr/src/udf.rs +++ b/datafusion/expr/src/udf.rs @@ -105,8 +105,8 @@ impl ScalarUDF { } /// Return the underlying [`ScalarUDFImpl`] trait object for this function - pub fn inner(&self) -> Arc { - self.inner.clone() + pub fn inner(&self) -> &Arc { + &self.inner } /// Adds additional names that can be used to invoke this function, in diff --git a/datafusion/expr/src/udwf.rs b/datafusion/expr/src/udwf.rs index ce28b444adbc..a17bb0ade8e3 100644 --- a/datafusion/expr/src/udwf.rs +++ b/datafusion/expr/src/udwf.rs @@ -108,8 +108,8 @@ impl WindowUDF { } /// Return the underlying [`WindowUDFImpl`] trait object for this function - pub fn inner(&self) -> Arc { - self.inner.clone() + pub fn inner(&self) -> &Arc { + &self.inner } /// Adds additional names that can be used to invoke this function, in From 643cffc3dd9867142231da79cece6fbbade78b36 Mon Sep 17 00:00:00 2001 From: Heran Lin Date: Tue, 25 Jun 2024 08:59:01 +0800 Subject: [PATCH 2/2] Format code --- datafusion-cli/src/catalog.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/datafusion-cli/src/catalog.rs b/datafusion-cli/src/catalog.rs index 0ccbb85ad611..c11eb3280c20 100644 --- a/datafusion-cli/src/catalog.rs +++ b/datafusion-cli/src/catalog.rs @@ -240,9 +240,10 @@ mod tests { ctx.state_weak_ref(), ))); - let provider = - &DynamicFileCatalog::new(ctx.state().catalog_list().clone(), ctx.state_weak_ref()) - as &dyn CatalogProviderList; + let provider = &DynamicFileCatalog::new( + ctx.state().catalog_list().clone(), + ctx.state_weak_ref(), + ) as &dyn CatalogProviderList; let catalog = provider .catalog(provider.catalog_names().first().unwrap()) .unwrap();