From 5f02c8a0658d9ed012ca4ca91f0417a967fe094a Mon Sep 17 00:00:00 2001 From: Heran Lin Date: Wed, 26 Jun 2024 07:17:50 +0800 Subject: [PATCH] Return `&Arc` reference to inner trait object (#11103) * Return `&Arc` reference to inner trait object * Format code --- datafusion-cli/src/catalog.rs | 9 +++++---- 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, 17 insertions(+), 16 deletions(-) diff --git a/datafusion-cli/src/catalog.rs b/datafusion-cli/src/catalog.rs index faa657da6511..c11eb3280c20 100644 --- a/datafusion-cli/src/catalog.rs +++ b/datafusion-cli/src/catalog.rs @@ -236,13 +236,14 @@ 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()) - 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(); 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 52fc31de7850..ac85dd95afbf 100644 --- a/datafusion/core/src/execution/context/mod.rs +++ b/datafusion/core/src/execution/context/mod.rs @@ -1856,7 +1856,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 60f67a5b239d..16d850859708 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 @@ -840,8 +840,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