Skip to content

Commit

Permalink
Return &Arc reference to inner trait object (#11103)
Browse files Browse the repository at this point in the history
* Return `&Arc` reference to inner trait object

* Format code
  • Loading branch information
linhr authored Jun 25, 2024
1 parent db64743 commit 5f02c8a
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 16 deletions.
9 changes: 5 additions & 4 deletions datafusion-cli/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,14 @@ mod tests {
fn setup_context() -> (SessionContext, Arc<dyn SchemaProvider>) {
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();
Expand Down
2 changes: 1 addition & 1 deletion datafusion-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion datafusion/core/src/execution/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions datafusion/core/src/execution/session_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,8 +807,8 @@ impl SessionState {
}

/// Return catalog list
pub fn catalog_list(&self) -> Arc<dyn CatalogProviderList> {
self.catalog_list.clone()
pub fn catalog_list(&self) -> &Arc<dyn CatalogProviderList> {
&self.catalog_list
}

/// set the catalog list
Expand Down Expand Up @@ -840,8 +840,8 @@ impl SessionState {
}

/// Return [SerializerRegistry] for extensions
pub fn serializer_registry(&self) -> Arc<dyn SerializerRegistry> {
self.serializer_registry.clone()
pub fn serializer_registry(&self) -> &Arc<dyn SerializerRegistry> {
&self.serializer_registry
}

/// Return version of the cargo package that produced this query
Expand Down
4 changes: 2 additions & 2 deletions datafusion/expr/src/udaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ impl AggregateUDF {
}

/// Return the underlying [`AggregateUDFImpl`] trait object for this function
pub fn inner(&self) -> Arc<dyn AggregateUDFImpl> {
self.inner.clone()
pub fn inner(&self) -> &Arc<dyn AggregateUDFImpl> {
&self.inner
}

/// Adds additional names that can be used to invoke this function, in
Expand Down
4 changes: 2 additions & 2 deletions datafusion/expr/src/udf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ impl ScalarUDF {
}

/// Return the underlying [`ScalarUDFImpl`] trait object for this function
pub fn inner(&self) -> Arc<dyn ScalarUDFImpl> {
self.inner.clone()
pub fn inner(&self) -> &Arc<dyn ScalarUDFImpl> {
&self.inner
}

/// Adds additional names that can be used to invoke this function, in
Expand Down
4 changes: 2 additions & 2 deletions datafusion/expr/src/udwf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ impl WindowUDF {
}

/// Return the underlying [`WindowUDFImpl`] trait object for this function
pub fn inner(&self) -> Arc<dyn WindowUDFImpl> {
self.inner.clone()
pub fn inner(&self) -> &Arc<dyn WindowUDFImpl> {
&self.inner
}

/// Adds additional names that can be used to invoke this function, in
Expand Down

0 comments on commit 5f02c8a

Please sign in to comment.