Skip to content

Commit f5c47fa

Browse files
authored
Removed Arc wrapping for AggregateFunctionExpr (#12353)
1 parent 3e1850d commit f5c47fa

File tree

14 files changed

+84
-83
lines changed

14 files changed

+84
-83
lines changed

datafusion/core/src/physical_optimizer/update_aggr_exprs.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl PhysicalOptimizerRule for OptimizeAggregateOrder {
118118
///
119119
/// # Parameters
120120
///
121-
/// * `aggr_exprs` - A vector of `Arc<AggregateFunctionExpr>` representing the
121+
/// * `aggr_exprs` - A vector of `AggregateFunctionExpr` representing the
122122
/// aggregate expressions to be optimized.
123123
/// * `prefix_requirement` - An array slice representing the ordering
124124
/// requirements preceding the aggregate expressions.
@@ -131,10 +131,10 @@ impl PhysicalOptimizerRule for OptimizeAggregateOrder {
131131
/// successfully. Any errors occurring during the conversion process are
132132
/// passed through.
133133
fn try_convert_aggregate_if_better(
134-
aggr_exprs: Vec<Arc<AggregateFunctionExpr>>,
134+
aggr_exprs: Vec<AggregateFunctionExpr>,
135135
prefix_requirement: &[PhysicalSortRequirement],
136136
eq_properties: &EquivalenceProperties,
137-
) -> Result<Vec<Arc<AggregateFunctionExpr>>> {
137+
) -> Result<Vec<AggregateFunctionExpr>> {
138138
aggr_exprs
139139
.into_iter()
140140
.map(|aggr_expr| {

datafusion/core/src/physical_planner.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1541,7 +1541,7 @@ pub fn create_window_expr(
15411541
}
15421542

15431543
type AggregateExprWithOptionalArgs = (
1544-
Arc<AggregateFunctionExpr>,
1544+
AggregateFunctionExpr,
15451545
// The filter clause, if any
15461546
Option<Arc<dyn PhysicalExpr>>,
15471547
// Ordering requirements, if any

datafusion/core/src/test_util/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ impl TestAggregate {
427427
}
428428

429429
/// Return appropriate expr depending if COUNT is for col or table (*)
430-
pub fn count_expr(&self, schema: &Schema) -> Arc<AggregateFunctionExpr> {
430+
pub fn count_expr(&self, schema: &Schema) -> AggregateFunctionExpr {
431431
AggregateExprBuilder::new(count_udaf(), vec![self.column()])
432432
.schema(Arc::new(schema.clone()))
433433
.alias(self.column_name())

datafusion/core/tests/physical_optimizer/combine_partial_final_agg.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn parquet_exec(schema: &SchemaRef) -> Arc<ParquetExec> {
8484
fn partial_aggregate_exec(
8585
input: Arc<dyn ExecutionPlan>,
8686
group_by: PhysicalGroupBy,
87-
aggr_expr: Vec<Arc<AggregateFunctionExpr>>,
87+
aggr_expr: Vec<AggregateFunctionExpr>,
8888
) -> Arc<dyn ExecutionPlan> {
8989
let schema = input.schema();
9090
let n_aggr = aggr_expr.len();
@@ -104,7 +104,7 @@ fn partial_aggregate_exec(
104104
fn final_aggregate_exec(
105105
input: Arc<dyn ExecutionPlan>,
106106
group_by: PhysicalGroupBy,
107-
aggr_expr: Vec<Arc<AggregateFunctionExpr>>,
107+
aggr_expr: Vec<AggregateFunctionExpr>,
108108
) -> Arc<dyn ExecutionPlan> {
109109
let schema = input.schema();
110110
let n_aggr = aggr_expr.len();
@@ -130,7 +130,7 @@ fn count_expr(
130130
expr: Arc<dyn PhysicalExpr>,
131131
name: &str,
132132
schema: &Schema,
133-
) -> Arc<AggregateFunctionExpr> {
133+
) -> AggregateFunctionExpr {
134134
AggregateExprBuilder::new(count_udaf(), vec![expr])
135135
.schema(Arc::new(schema.clone()))
136136
.alias(name)

datafusion/physical-expr/src/aggregate.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl AggregateExprBuilder {
8888
}
8989
}
9090

91-
pub fn build(self) -> Result<Arc<AggregateFunctionExpr>> {
91+
pub fn build(self) -> Result<AggregateFunctionExpr> {
9292
let Self {
9393
fun,
9494
args,
@@ -132,7 +132,7 @@ impl AggregateExprBuilder {
132132
Some(alias) => alias,
133133
};
134134

135-
Ok(Arc::new(AggregateFunctionExpr {
135+
Ok(AggregateFunctionExpr {
136136
fun: Arc::unwrap_or_clone(fun),
137137
args,
138138
data_type,
@@ -145,7 +145,7 @@ impl AggregateExprBuilder {
145145
input_types: input_exprs_types,
146146
is_reversed,
147147
is_nullable,
148-
}))
148+
})
149149
}
150150

151151
pub fn alias(mut self, alias: impl Into<String>) -> Self {
@@ -328,9 +328,9 @@ impl AggregateFunctionExpr {
328328
/// not implement the method, returns an error. Order insensitive and hard
329329
/// requirement aggregators return `Ok(None)`.
330330
pub fn with_beneficial_ordering(
331-
self: Arc<Self>,
331+
self,
332332
beneficial_ordering: bool,
333-
) -> Result<Option<Arc<AggregateFunctionExpr>>> {
333+
) -> Result<Option<AggregateFunctionExpr>> {
334334
let Some(updated_fn) = self
335335
.fun
336336
.clone()
@@ -457,10 +457,10 @@ impl AggregateFunctionExpr {
457457
/// Typically the "reverse" expression is itself (e.g. SUM, COUNT).
458458
/// For aggregates that do not support calculation in reverse,
459459
/// returns None (which is the default value).
460-
pub fn reverse_expr(&self) -> Option<Arc<AggregateFunctionExpr>> {
460+
pub fn reverse_expr(&self) -> Option<AggregateFunctionExpr> {
461461
match self.fun.reverse_udf() {
462462
ReversedUDAF::NotSupported => None,
463-
ReversedUDAF::Identical => Some(Arc::new(self.clone())),
463+
ReversedUDAF::Identical => Some(self.clone()),
464464
ReversedUDAF::Reversed(reverse_udf) => {
465465
let reverse_ordering_req = reverse_order_bys(&self.ordering_req);
466466
let mut name = self.name().to_string();
@@ -507,7 +507,7 @@ impl AggregateFunctionExpr {
507507
&self,
508508
_args: Vec<Arc<dyn PhysicalExpr>>,
509509
_order_by_exprs: Vec<Arc<dyn PhysicalExpr>>,
510-
) -> Option<Arc<AggregateFunctionExpr>> {
510+
) -> Option<AggregateFunctionExpr> {
511511
None
512512
}
513513

datafusion/physical-expr/src/window/aggregate.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use crate::{expressions::PhysicalSortExpr, reverse_order_bys, PhysicalExpr};
4141
/// See comments on [`WindowExpr`] for more details.
4242
#[derive(Debug)]
4343
pub struct PlainAggregateWindowExpr {
44-
aggregate: Arc<AggregateFunctionExpr>,
44+
aggregate: AggregateFunctionExpr,
4545
partition_by: Vec<Arc<dyn PhysicalExpr>>,
4646
order_by: Vec<PhysicalSortExpr>,
4747
window_frame: Arc<WindowFrame>,
@@ -50,7 +50,7 @@ pub struct PlainAggregateWindowExpr {
5050
impl PlainAggregateWindowExpr {
5151
/// Create a new aggregate window function expression
5252
pub fn new(
53-
aggregate: Arc<AggregateFunctionExpr>,
53+
aggregate: AggregateFunctionExpr,
5454
partition_by: &[Arc<dyn PhysicalExpr>],
5555
order_by: &[PhysicalSortExpr],
5656
window_frame: Arc<WindowFrame>,
@@ -64,7 +64,7 @@ impl PlainAggregateWindowExpr {
6464
}
6565

6666
/// Get aggregate expr of AggregateWindowExpr
67-
pub fn get_aggregate_expr(&self) -> &Arc<AggregateFunctionExpr> {
67+
pub fn get_aggregate_expr(&self) -> &AggregateFunctionExpr {
6868
&self.aggregate
6969
}
7070
}

datafusion/physical-expr/src/window/sliding_aggregate.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use crate::{expressions::PhysicalSortExpr, reverse_order_bys, PhysicalExpr};
4141
/// See comments on [`WindowExpr`] for more details.
4242
#[derive(Debug)]
4343
pub struct SlidingAggregateWindowExpr {
44-
aggregate: Arc<AggregateFunctionExpr>,
44+
aggregate: AggregateFunctionExpr,
4545
partition_by: Vec<Arc<dyn PhysicalExpr>>,
4646
order_by: Vec<PhysicalSortExpr>,
4747
window_frame: Arc<WindowFrame>,
@@ -50,7 +50,7 @@ pub struct SlidingAggregateWindowExpr {
5050
impl SlidingAggregateWindowExpr {
5151
/// Create a new (sliding) aggregate window function expression.
5252
pub fn new(
53-
aggregate: Arc<AggregateFunctionExpr>,
53+
aggregate: AggregateFunctionExpr,
5454
partition_by: &[Arc<dyn PhysicalExpr>],
5555
order_by: &[PhysicalSortExpr],
5656
window_frame: Arc<WindowFrame>,
@@ -64,7 +64,7 @@ impl SlidingAggregateWindowExpr {
6464
}
6565

6666
/// Get the [AggregateFunctionExpr] of this object.
67-
pub fn get_aggregate_expr(&self) -> &Arc<AggregateFunctionExpr> {
67+
pub fn get_aggregate_expr(&self) -> &AggregateFunctionExpr {
6868
&self.aggregate
6969
}
7070
}

datafusion/physical-optimizer/src/combine_partial_final_agg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl PhysicalOptimizerRule for CombinePartialFinalAggregate {
125125

126126
type GroupExprsRef<'a> = (
127127
&'a PhysicalGroupBy,
128-
&'a [Arc<AggregateFunctionExpr>],
128+
&'a [AggregateFunctionExpr],
129129
&'a [Option<Arc<dyn PhysicalExpr>>],
130130
);
131131

0 commit comments

Comments
 (0)