Skip to content

Commit

Permalink
Replace Arc::try_unwrap with Arc::unwrap_or_clone where cloning anyway (
Browse files Browse the repository at this point in the history
  • Loading branch information
findepi authored Aug 26, 2024
1 parent 55a1459 commit 0f96af5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 13 deletions.
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 @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions datafusion/expr/src/expr_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions datafusion/expr/src/logical_plan/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
5 changes: 1 addition & 4 deletions datafusion/sql/src/unparser/rewrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0f96af5

Please sign in to comment.