Apache DataFusion SQL Query Engine
Replace Arc::try_unwrap with Arc::unwrap_or_clone where cloning anyway (#12173)
Piotr Findeisen0f96af5b500e
diff --git a/datafusion/core/src/execution/context/mod.rs b/datafusion/core/src/execution/context/mod.rsindex 49cbf9ebde..c2a072eef7 100644--- a/datafusion/core/src/execution/context/mod.rs+++ b/datafusion/core/src/execution/context/mod.rs@@ -688,7 +688,7 @@ impl SessionContext {column_defaults,} = cmd;- let input = Arc::try_unwrap(input).unwrap_or_else(|e| e.as_ref().clone());+ let input = Arc::unwrap_or_clone(input);let input = self.state().optimize(&input)?;let table = self.table(name.clone()).await;match (if_not_exists, or_replace, table) {diff --git a/datafusion/expr/src/expr_fn.rs b/datafusion/expr/src/expr_fn.rsindex 4e60223996..1e0b601146 100644--- a/datafusion/expr/src/expr_fn.rs+++ b/datafusion/expr/src/expr_fn.rs@@ -394,7 +394,7 @@ pub fn create_udf(volatility: Volatility,fun: ScalarFunctionImplementation,) -> ScalarUDF {- let return_type = Arc::try_unwrap(return_type).unwrap_or_else(|t| t.as_ref().clone());+ let return_type = Arc::unwrap_or_clone(return_type);ScalarUDF::from(SimpleScalarUDF::new(name,input_types,@@ -476,8 +476,8 @@ pub fn create_udaf(accumulator: AccumulatorFactoryFunction,state_type: Arc<Vec<DataType>>,) -> AggregateUDF {- let return_type = Arc::try_unwrap(return_type).unwrap_or_else(|t| t.as_ref().clone());- let state_type = Arc::try_unwrap(state_type).unwrap_or_else(|t| t.as_ref().clone());+ let return_type = Arc::unwrap_or_clone(return_type);+ let state_type = Arc::unwrap_or_clone(state_type);let state_fields = state_type.into_iter().enumerate()@@ -594,7 +594,7 @@ pub fn create_udwf(volatility: Volatility,partition_evaluator_factory: PartitionEvaluatorFactory,) -> WindowUDF {- let return_type = Arc::try_unwrap(return_type).unwrap_or_else(|t| t.as_ref().clone());+ let return_type = Arc::unwrap_or_clone(return_type);WindowUDF::from(SimpleWindowUDF::new(name,input_type,diff --git a/datafusion/expr/src/logical_plan/plan.rs b/datafusion/expr/src/logical_plan/plan.rsindex d6574040c5..096b65896b 100644--- a/datafusion/expr/src/logical_plan/plan.rs+++ b/datafusion/expr/src/logical_plan/plan.rs@@ -1160,10 +1160,7 @@ impl LogicalPlan {Ok(if let LogicalPlan::Prepare(prepare_lp) = plan_with_values {param_values.verify(&prepare_lp.data_types)?;// try and take ownership of the input if is not shared, clone otherwise- match Arc::try_unwrap(prepare_lp.input) {- Ok(input) => input,- Err(arc_input) => arc_input.as_ref().clone(),- }+ Arc::unwrap_or_clone(prepare_lp.input)} else {plan_with_values})diff --git a/datafusion/sql/src/unparser/rewrite.rs b/datafusion/sql/src/unparser/rewrite.rsindex f6725485f9..fed3f2c39f 100644--- a/datafusion/sql/src/unparser/rewrite.rs+++ b/datafusion/sql/src/unparser/rewrite.rs@@ -59,10 +59,7 @@ pub(super) fn normalize_union_schema(plan: &LogicalPlan) -> Result<LogicalPlan>let transformed_plan = plan.transform_up(|plan| match plan {LogicalPlan::Union(mut union) => {- let schema = match Arc::try_unwrap(union.schema) {- Ok(inner) => inner,- Err(schema) => (*schema).clone(),- };+ let schema = Arc::unwrap_or_clone(union.schema);let schema = schema.strip_qualifiers();union.schema = Arc::new(schema);