Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions datafusion-examples/examples/udf/advanced_udaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,6 @@ impl GroupsAccumulator for GeometricMeanGroupsAccumulator {
Arc::new(counts) as ArrayRef,
])
}

fn supports_convert_to_state(&self) -> bool {
true
}

fn size(&self) -> usize {
self.counts.capacity() * size_of::<u32>()
+ self.prods.capacity() * size_of::<Float64Type>()
Expand Down
5 changes: 0 additions & 5 deletions datafusion/core/tests/user_defined/user_defined_aggregates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -888,11 +888,6 @@ impl GroupsAccumulator for TestGroupsAccumulator {
as ArrayRef,
])
}

fn supports_convert_to_state(&self) -> bool {
true
}

fn size(&self) -> usize {
size_of::<u64>()
}
Expand Down
16 changes: 4 additions & 12 deletions datafusion/expr-common/src/groups_accumulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! Vectorized [`GroupsAccumulator`]

use arrow::array::{ArrayRef, BooleanArray};
use datafusion_common::{Result, not_impl_err, utils::split_vec_min_alloc};
use datafusion_common::{Result, utils::split_vec_min_alloc};

/// Describes how many rows should be emitted during grouping.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down Expand Up @@ -231,17 +231,9 @@ pub trait GroupsAccumulator: Send + std::any::Any {
/// [`Accumulator::state`]: crate::accumulator::Accumulator::state
fn convert_to_state(
&self,
_values: &[ArrayRef],
_opt_filter: Option<&BooleanArray>,
) -> Result<Vec<ArrayRef>> {
not_impl_err!("Input batch conversion to state not implemented")
}

/// Returns `true` if [`Self::convert_to_state`] is implemented to support
/// intermediate aggregate state conversion.
fn supports_convert_to_state(&self) -> bool {
false
}
values: &[ArrayRef],
opt_filter: Option<&BooleanArray>,
) -> Result<Vec<ArrayRef>>;

/// Amount of memory used to store the state of this accumulator,
/// in bytes.
Expand Down
8 changes: 0 additions & 8 deletions datafusion/ffi/src/udaf/groups_accumulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ pub struct FFI_GroupsAccumulator {
opt_filter: FFI_Option<WrappedArray>,
) -> FFI_Result<SVec<WrappedArray>>,

pub supports_convert_to_state: bool,

/// Release the memory of the private data when it is no longer being used.
pub release: unsafe extern "C" fn(accumulator: &mut Self),

Expand Down Expand Up @@ -247,7 +245,6 @@ impl From<Box<dyn GroupsAccumulator>> for FFI_GroupsAccumulator {
return accumulator.accumulator;
}

let supports_convert_to_state = accumulator.supports_convert_to_state();
let private_data = GroupsAccumulatorPrivateData { accumulator };

Self {
Expand All @@ -257,7 +254,6 @@ impl From<Box<dyn GroupsAccumulator>> for FFI_GroupsAccumulator {
state: state_fn_wrapper,
merge_batch: merge_batch_fn_wrapper,
convert_to_state: convert_to_state_fn_wrapper,
supports_convert_to_state,

release: release_fn_wrapper,
private_data: Box::into_raw(Box::new(private_data)) as *mut c_void,
Expand Down Expand Up @@ -421,10 +417,6 @@ impl GroupsAccumulator for ForeignGroupsAccumulator {
.collect()
}
}

fn supports_convert_to_state(&self) -> bool {
self.accumulator.supports_convert_to_state
}
}

#[repr(C)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,6 @@ where

Ok(vec![Arc::new(builder.finish())])
}

fn supports_convert_to_state(&self) -> bool {
true
}

fn size(&self) -> usize {
size_of::<Self>()
+ self.seen.capacity() * (size_of::<(usize, T::Native)>() + size_of::<u64>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,6 @@ impl GroupsAccumulator for GroupsAccumulatorAdapter {

Ok(arrays)
}

fn supports_convert_to_state(&self) -> bool {
true
}
}

/// Extension trait for [`Vec`] to account for allocations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,4 @@ where

Ok(vec![Arc::new(values_filtered)])
}

fn supports_convert_to_state(&self) -> bool {
true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,6 @@ where

Ok(vec![Arc::new(state_values)])
}

fn supports_convert_to_state(&self) -> bool {
true
}

fn size(&self) -> usize {
self.values.capacity() * size_of::<T::Native>() + self.null_state.size()
}
Expand Down
5 changes: 0 additions & 5 deletions datafusion/functions-aggregate/src/approx_distinct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,11 +615,6 @@ impl GroupsAccumulator for HllGroupsAccumulator {

Ok(vec![Arc::new(builder.finish())])
}

fn supports_convert_to_state(&self) -> bool {
true
}

fn size(&self) -> usize {
self.groups.capacity() * size_of::<GroupHll>()
+ self.allocated_bytes
Expand Down
5 changes: 0 additions & 5 deletions datafusion/functions-aggregate/src/array_agg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,11 +793,6 @@ impl GroupsAccumulator for ArrayAggGroupsAccumulator {

Ok(vec![Arc::new(list_array)])
}

fn supports_convert_to_state(&self) -> bool {
true
}

fn size(&self) -> usize {
self.batches
.iter()
Expand Down
5 changes: 0 additions & 5 deletions datafusion/functions-aggregate/src/average.rs
Original file line number Diff line number Diff line change
Expand Up @@ -964,11 +964,6 @@ where

Ok(vec![Arc::new(counts) as ArrayRef, Arc::new(sums)])
}

fn supports_convert_to_state(&self) -> bool {
true
}

fn size(&self) -> usize {
// Heap buffers
self.counts.capacity() * size_of::<u64>()
Expand Down
5 changes: 0 additions & 5 deletions datafusion/functions-aggregate/src/correlation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,11 +539,6 @@ impl GroupsAccumulator for CorrelationGroupsAccumulator {
Arc::new(Float64Array::from(sum_yy)),
])
}

fn supports_convert_to_state(&self) -> bool {
true
}

fn merge_batch(
&mut self,
values: &[ArrayRef],
Expand Down
5 changes: 0 additions & 5 deletions datafusion/functions-aggregate/src/count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,11 +763,6 @@ impl GroupsAccumulator for CountGroupsAccumulator {

Ok(vec![state_array])
}

fn supports_convert_to_state(&self) -> bool {
true
}

fn size(&self) -> usize {
self.counts.capacity() * size_of::<usize>()
}
Expand Down
5 changes: 0 additions & 5 deletions datafusion/functions-aggregate/src/first_last.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,11 +712,6 @@ impl<S: ValueState + 'static> GroupsAccumulator for FirstLastGroupsAccumulator<S
+ self.extreme_of_each_group_buf.0.capacity() * size_of::<usize>()
+ self.extreme_of_each_group_buf.1.capacity() / 8
}

fn supports_convert_to_state(&self) -> bool {
true
}

fn convert_to_state(
&self,
values: &[ArrayRef],
Expand Down
5 changes: 0 additions & 5 deletions datafusion/functions-aggregate/src/median.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,11 +535,6 @@ impl<T: ArrowNumericType + Send> GroupsAccumulator for MedianGroupsAccumulator<T

Ok(vec![Arc::new(converted_list_array)])
}

fn supports_convert_to_state(&self) -> bool {
true
}

fn size(&self) -> usize {
self.group_values
.iter()
Expand Down
5 changes: 0 additions & 5 deletions datafusion/functions-aggregate/src/min_max/min_max_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,6 @@ impl GroupsAccumulator for MinMaxBytesAccumulator {
let output = apply_filter_as_nulls(&values[0], opt_filter)?;
Ok(vec![output])
}

fn supports_convert_to_state(&self) -> bool {
true
}

fn size(&self) -> usize {
self.inner.size()
}
Expand Down
5 changes: 0 additions & 5 deletions datafusion/functions-aggregate/src/min_max/min_max_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,6 @@ impl GroupsAccumulator for MinMaxStructAccumulator {
let output = apply_filter_as_nulls(&values[0], opt_filter)?;
Ok(vec![output])
}

fn supports_convert_to_state(&self) -> bool {
true
}

fn size(&self) -> usize {
self.inner.size()
}
Expand Down
5 changes: 0 additions & 5 deletions datafusion/functions-aggregate/src/percentile_cont.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,11 +652,6 @@ where

Ok(vec![Arc::new(converted_list_array)])
}

fn supports_convert_to_state(&self) -> bool {
true
}

fn size(&self) -> usize {
self.group_values
.iter()
Expand Down
5 changes: 0 additions & 5 deletions datafusion/functions-aggregate/src/stddev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,6 @@ impl GroupsAccumulator for StddevGroupsAccumulator {
) -> Result<Vec<ArrayRef>> {
self.variance.convert_to_state(values, opt_filter)
}

fn supports_convert_to_state(&self) -> bool {
true
}

fn size(&self) -> usize {
self.variance.size()
}
Expand Down
5 changes: 0 additions & 5 deletions datafusion/functions-aggregate/src/string_agg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,6 @@ impl GroupsAccumulator for StringAggGroupsAccumulator {
};
Ok(vec![result])
}

fn supports_convert_to_state(&self) -> bool {
true
}

fn size(&self) -> usize {
self.total_data_bytes
+ self.values.capacity() * size_of::<Option<String>>()
Expand Down
5 changes: 0 additions & 5 deletions datafusion/functions-aggregate/src/variance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,11 +613,6 @@ impl GroupsAccumulator for VarianceGroupsAccumulator {
Arc::new(Float64Array::new(m2s.into(), None)),
])
}

fn supports_convert_to_state(&self) -> bool {
true
}

fn size(&self) -> usize {
self.m2s.capacity() * size_of::<f64>()
+ self.means.capacity() * size_of::<f64>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,6 @@ impl HashAggregateAccumulator {
self.accumulator.state(emit_to)
}

pub(super) fn supports_convert_to_state(&self) -> bool {
self.accumulator.supports_convert_to_state()
}

pub(super) fn convert_to_state(
&mut self,
values: &EvaluatedAccumulatorArgs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@ impl AggregateHashTable<PartialMarker> {
self.next_output_batch_inner(HashAggregateAccumulator::state)
}

pub(in crate::aggregates) fn can_skip_aggregation(&self) -> bool {
self.state
.building()
.accumulators
.iter()
.all(|acc| acc.supports_convert_to_state())
}

/// In skip-partial-aggregation optimization, when a decision has been made to skip
/// partial stage, build a typed hash table only for aggregation state conversion
/// row-by-row.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ enum OutOfMemoryMode {
/// aggregator must store the intermediate state for each group.
///
/// If the ratio of the number of groups to the number of input rows exceeds a
/// threshold, and [`GroupsAccumulator::supports_convert_to_state`] is
/// supported, this operator will stop applying Partial aggregation and directly
/// threshold, this operator will stop applying Partial aggregation and directly
/// pass the input rows to the next aggregation phase.
///
/// [`Accumulator::state`]: datafusion_expr::Accumulator::state
Expand Down Expand Up @@ -545,14 +544,9 @@ impl GroupedHashAggregateStream {
// - aggregation mode is Partial
// - input is not ordered by GROUP BY expressions,
// since Final mode expects unique group values as its input
// - all accumulators support input batch to intermediate
// aggregate state conversion
// - there is only one GROUP BY expressions set
let skip_aggregation_probe = if agg.mode == AggregateMode::Partial
&& matches!(group_ordering, GroupOrdering::None)
&& accumulators
.iter()
.all(|acc| acc.supports_convert_to_state())
&& agg_group_by.is_single()
{
let options = &context.session_config().options().execution;
Expand Down
4 changes: 1 addition & 3 deletions datafusion/physical-plan/src/aggregates/hash_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,7 @@ impl PartialHashAggregateStream {
Arc::clone(&schema),
batch_size,
)?;
let can_skip_aggregation =
agg.group_by.is_single() && hash_table.can_skip_aggregation();
let skip_aggregation_probe = if can_skip_aggregation {
let skip_aggregation_probe = if agg.group_by.is_single() {
let options = &context.session_config().options().execution;
let probe_ratio_threshold =
options.skip_partial_aggregation_probe_ratio_threshold;
Expand Down
Loading
Loading