Skip to content

Commit 0f96af5

Browse files
authored
Replace Arc::try_unwrap with Arc::unwrap_or_clone where cloning anyway (#12173)
1 parent 55a1459 commit 0f96af5

File tree

4 files changed

+7
-13
lines changed

4 files changed

+7
-13
lines changed

datafusion/core/src/execution/context/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ impl SessionContext {
688688
column_defaults,
689689
} = cmd;
690690

691-
let input = Arc::try_unwrap(input).unwrap_or_else(|e| e.as_ref().clone());
691+
let input = Arc::unwrap_or_clone(input);
692692
let input = self.state().optimize(&input)?;
693693
let table = self.table(name.clone()).await;
694694
match (if_not_exists, or_replace, table) {

datafusion/expr/src/expr_fn.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ pub fn create_udf(
394394
volatility: Volatility,
395395
fun: ScalarFunctionImplementation,
396396
) -> ScalarUDF {
397-
let return_type = Arc::try_unwrap(return_type).unwrap_or_else(|t| t.as_ref().clone());
397+
let return_type = Arc::unwrap_or_clone(return_type);
398398
ScalarUDF::from(SimpleScalarUDF::new(
399399
name,
400400
input_types,
@@ -476,8 +476,8 @@ pub fn create_udaf(
476476
accumulator: AccumulatorFactoryFunction,
477477
state_type: Arc<Vec<DataType>>,
478478
) -> AggregateUDF {
479-
let return_type = Arc::try_unwrap(return_type).unwrap_or_else(|t| t.as_ref().clone());
480-
let state_type = Arc::try_unwrap(state_type).unwrap_or_else(|t| t.as_ref().clone());
479+
let return_type = Arc::unwrap_or_clone(return_type);
480+
let state_type = Arc::unwrap_or_clone(state_type);
481481
let state_fields = state_type
482482
.into_iter()
483483
.enumerate()
@@ -594,7 +594,7 @@ pub fn create_udwf(
594594
volatility: Volatility,
595595
partition_evaluator_factory: PartitionEvaluatorFactory,
596596
) -> WindowUDF {
597-
let return_type = Arc::try_unwrap(return_type).unwrap_or_else(|t| t.as_ref().clone());
597+
let return_type = Arc::unwrap_or_clone(return_type);
598598
WindowUDF::from(SimpleWindowUDF::new(
599599
name,
600600
input_type,

datafusion/expr/src/logical_plan/plan.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1160,10 +1160,7 @@ impl LogicalPlan {
11601160
Ok(if let LogicalPlan::Prepare(prepare_lp) = plan_with_values {
11611161
param_values.verify(&prepare_lp.data_types)?;
11621162
// try and take ownership of the input if is not shared, clone otherwise
1163-
match Arc::try_unwrap(prepare_lp.input) {
1164-
Ok(input) => input,
1165-
Err(arc_input) => arc_input.as_ref().clone(),
1166-
}
1163+
Arc::unwrap_or_clone(prepare_lp.input)
11671164
} else {
11681165
plan_with_values
11691166
})

datafusion/sql/src/unparser/rewrite.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ pub(super) fn normalize_union_schema(plan: &LogicalPlan) -> Result<LogicalPlan>
5959

6060
let transformed_plan = plan.transform_up(|plan| match plan {
6161
LogicalPlan::Union(mut union) => {
62-
let schema = match Arc::try_unwrap(union.schema) {
63-
Ok(inner) => inner,
64-
Err(schema) => (*schema).clone(),
65-
};
62+
let schema = Arc::unwrap_or_clone(union.schema);
6663
let schema = schema.strip_qualifiers();
6764

6865
union.schema = Arc::new(schema);

0 commit comments

Comments
 (0)