Skip to content

Commit f871f56

Browse files
committed
Remove RowAccumulators
1 parent c6891cb commit f871f56

File tree

10 files changed

+1
-1318
lines changed

10 files changed

+1
-1318
lines changed

datafusion/core/src/physical_plan/aggregates/mod.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use datafusion_common::{DataFusionError, Result};
3333
use datafusion_execution::TaskContext;
3434
use datafusion_expr::Accumulator;
3535
use datafusion_physical_expr::{
36-
aggregate::row_accumulator::RowAccumulator,
3736
equivalence::project_equivalence_properties,
3837
expressions::{Avg, CastExpr, Column, Sum},
3938
normalize_out_expr_with_columns_map, reverse_order_bys,
@@ -1084,7 +1083,6 @@ fn merge_expressions(
10841083
}
10851084

10861085
pub(crate) type AccumulatorItem = Box<dyn Accumulator>;
1087-
pub(crate) type RowAccumulatorItem = Box<dyn RowAccumulator>;
10881086

10891087
fn create_accumulators(
10901088
aggr_expr: &[Arc<dyn AggregateExpr>],
@@ -1095,21 +1093,6 @@ fn create_accumulators(
10951093
.collect::<Result<Vec<_>>>()
10961094
}
10971095

1098-
#[allow(dead_code)]
1099-
fn create_row_accumulators(
1100-
aggr_expr: &[Arc<dyn AggregateExpr>],
1101-
) -> Result<Vec<RowAccumulatorItem>> {
1102-
let mut state_index = 0;
1103-
aggr_expr
1104-
.iter()
1105-
.map(|expr| {
1106-
let result = expr.create_row_accumulator(state_index);
1107-
state_index += expr.state_fields().unwrap().len();
1108-
result
1109-
})
1110-
.collect::<Result<Vec<_>>>()
1111-
}
1112-
11131096
/// returns a vector of ArrayRefs, where each entry corresponds to either the
11141097
/// final value (mode = Final, FinalPartitioned and Single) or states (mode = Partial)
11151098
fn finalize_aggregation(

datafusion/core/src/physical_plan/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use arrow::record_batch::RecordBatch;
3232
use datafusion_common::utils::DataPtr;
3333
pub use datafusion_expr::Accumulator;
3434
pub use datafusion_expr::ColumnarValue;
35-
pub use datafusion_physical_expr::aggregate::row_accumulator::RowAccumulator;
3635
use datafusion_physical_expr::equivalence::OrderingEquivalenceProperties;
3736
pub use display::{DefaultDisplay, DisplayAs, DisplayFormatType, VerboseDisplay};
3837
use futures::stream::{Stream, TryStreamExt};

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

Lines changed: 0 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ use std::convert::TryFrom;
2525
use std::sync::Arc;
2626

2727
use crate::aggregate::groups_accumulator::accumulate::NullState;
28-
use crate::aggregate::row_accumulator::{
29-
is_row_accumulator_support_dtype, RowAccumulator,
30-
};
3128
use crate::aggregate::sum;
3229
use crate::aggregate::sum::sum_batch;
3330
use crate::aggregate::utils::calculate_result_decimal_for_avg;
@@ -46,7 +43,6 @@ use arrow_array::{
4643
use datafusion_common::{downcast_value, ScalarValue};
4744
use datafusion_common::{DataFusionError, Result};
4845
use datafusion_expr::Accumulator;
49-
use datafusion_row::accessor::RowAccessor;
5046

5147
use super::groups_accumulator::EmitTo;
5248
use super::utils::{adjust_output_array, Decimal128Averager};
@@ -139,21 +135,6 @@ impl AggregateExpr for Avg {
139135
&self.name
140136
}
141137

142-
fn row_accumulator_supported(&self) -> bool {
143-
is_row_accumulator_support_dtype(&self.sum_data_type)
144-
}
145-
146-
fn create_row_accumulator(
147-
&self,
148-
start_index: usize,
149-
) -> Result<Box<dyn RowAccumulator>> {
150-
Ok(Box::new(AvgRowAccumulator::new(
151-
start_index,
152-
&self.sum_data_type,
153-
&self.rt_data_type,
154-
)))
155-
}
156-
157138
fn reverse_expr(&self) -> Option<Arc<dyn AggregateExpr>> {
158139
Some(Arc::new(self.clone()))
159140
}
@@ -321,121 +302,6 @@ impl Accumulator for AvgAccumulator {
321302
}
322303
}
323304

324-
#[derive(Debug)]
325-
struct AvgRowAccumulator {
326-
state_index: usize,
327-
sum_datatype: DataType,
328-
return_data_type: DataType,
329-
}
330-
331-
impl AvgRowAccumulator {
332-
pub fn new(
333-
start_index: usize,
334-
sum_datatype: &DataType,
335-
return_data_type: &DataType,
336-
) -> Self {
337-
Self {
338-
state_index: start_index,
339-
sum_datatype: sum_datatype.clone(),
340-
return_data_type: return_data_type.clone(),
341-
}
342-
}
343-
}
344-
345-
impl RowAccumulator for AvgRowAccumulator {
346-
fn update_batch(
347-
&mut self,
348-
values: &[ArrayRef],
349-
accessor: &mut RowAccessor,
350-
) -> Result<()> {
351-
let values = &values[0];
352-
// count
353-
let delta = (values.len() - values.null_count()) as u64;
354-
accessor.add_u64(self.state_index(), delta);
355-
356-
// sum
357-
sum::add_to_row(
358-
self.state_index() + 1,
359-
accessor,
360-
&sum::sum_batch(values, &self.sum_datatype)?,
361-
)
362-
}
363-
364-
fn update_scalar_values(
365-
&mut self,
366-
values: &[ScalarValue],
367-
accessor: &mut RowAccessor,
368-
) -> Result<()> {
369-
let value = &values[0];
370-
sum::update_avg_to_row(self.state_index(), accessor, value)
371-
}
372-
373-
fn update_scalar(
374-
&mut self,
375-
value: &ScalarValue,
376-
accessor: &mut RowAccessor,
377-
) -> Result<()> {
378-
sum::update_avg_to_row(self.state_index(), accessor, value)
379-
}
380-
381-
fn merge_batch(
382-
&mut self,
383-
states: &[ArrayRef],
384-
accessor: &mut RowAccessor,
385-
) -> Result<()> {
386-
let counts = downcast_value!(states[0], UInt64Array);
387-
// count
388-
let delta = compute::sum(counts).unwrap_or(0);
389-
accessor.add_u64(self.state_index(), delta);
390-
391-
// sum
392-
let difference = sum::sum_batch(&states[1], &self.sum_datatype)?;
393-
sum::add_to_row(self.state_index() + 1, accessor, &difference)
394-
}
395-
396-
fn evaluate(&self, accessor: &RowAccessor) -> Result<ScalarValue> {
397-
match self.sum_datatype {
398-
DataType::Decimal128(p, s) => {
399-
match accessor.get_u64_opt(self.state_index()) {
400-
None => Ok(ScalarValue::Decimal128(None, p, s)),
401-
Some(0) => Ok(ScalarValue::Decimal128(None, p, s)),
402-
Some(n) => {
403-
// now the sum_type and return type is not the same, need to convert the sum type to return type
404-
accessor.get_i128_opt(self.state_index() + 1).map_or_else(
405-
|| Ok(ScalarValue::Decimal128(None, p, s)),
406-
|f| {
407-
calculate_result_decimal_for_avg(
408-
f,
409-
n as i128,
410-
s,
411-
&self.return_data_type,
412-
)
413-
},
414-
)
415-
}
416-
}
417-
}
418-
DataType::Float64 => Ok(match accessor.get_u64_opt(self.state_index()) {
419-
None => ScalarValue::Float64(None),
420-
Some(0) => ScalarValue::Float64(None),
421-
Some(n) => ScalarValue::Float64(
422-
accessor
423-
.get_f64_opt(self.state_index() + 1)
424-
.map(|f| f / n as f64),
425-
),
426-
}),
427-
_ => Err(DataFusionError::Internal(
428-
"Sum should be f64 or decimal128 on average".to_string(),
429-
)),
430-
}
431-
}
432-
433-
#[inline(always)]
434-
fn state_index(&self) -> usize {
435-
self.state_index
436-
}
437-
}
438-
439305
/// An accumulator to compute the average of `[PrimitiveArray<T>]`.
440306
/// Stores values as native types, and does overflow checking
441307
///

0 commit comments

Comments
 (0)