Skip to content

Commit

Permalink
Initial changes to support using udaf min/max for statistics and opti…
Browse files Browse the repository at this point in the history
…mizations
  • Loading branch information
edmondop committed Jul 28, 2024
1 parent a721be1 commit d777951
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions datafusion/expr/src/udaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ impl AggregateUDF {
pub fn simplify(&self) -> Option<AggregateFunctionSimplification> {
self.inner.simplify()
}

/// Returns true if the function is max, false if the function is min
/// None in all other cases, used in certain optimizations or
/// or aggregate
///
pub fn get_minmax_desc(&self) -> Option<bool> {
self.inner.get_minmax_desc()
}
}

impl<F> From<F> for AggregateUDF
Expand Down Expand Up @@ -536,6 +544,16 @@ pub trait AggregateUDFImpl: Debug + Send + Sync {
self.signature().hash(hasher);
hasher.finish()
}

/// If this function is max, return true
/// if the function is min, return false
/// otherwise return None (the default)
///
///
/// Note: this is used to use special aggregate implementations in certain conditions
fn get_minmax_desc(&self) -> Option<bool> {
None
}
}

pub enum ReversedUDAF {
Expand Down
6 changes: 6 additions & 0 deletions datafusion/physical-expr-common/src/aggregate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,12 @@ impl AggregateExpr for AggregateFunctionExpr {
}
}
}

fn get_minmax_desc(&self) -> Option<(Field, bool)> {
self.fun
.get_minmax_desc()
.and_then(|flag| self.field().ok().map(|f| (f, flag)))
}
}

impl PartialEq<dyn Any> for AggregateFunctionExpr {
Expand Down

0 comments on commit d777951

Please sign in to comment.