Skip to content

Commit 35c2e7e

Browse files
authored
Initial changes to support using udaf min/max for statistics and opti… (#11696)
* Initial changes to support using udaf min/max for statistics and optimizations * Listening to Clippy on CI * Implementing feedback from PR
1 parent 2f5e73c commit 35c2e7e

File tree

2 files changed

+24
-0
lines changed
  • datafusion

2 files changed

+24
-0
lines changed

datafusion/expr/src/udaf.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,14 @@ impl AggregateUDF {
249249
pub fn simplify(&self) -> Option<AggregateFunctionSimplification> {
250250
self.inner.simplify()
251251
}
252+
253+
/// Returns true if the function is max, false if the function is min
254+
/// None in all other cases, used in certain optimizations or
255+
/// or aggregate
256+
///
257+
pub fn is_descending(&self) -> Option<bool> {
258+
self.inner.is_descending()
259+
}
252260
}
253261

254262
impl<F> From<F> for AggregateUDF
@@ -536,6 +544,16 @@ pub trait AggregateUDFImpl: Debug + Send + Sync {
536544
self.signature().hash(hasher);
537545
hasher.finish()
538546
}
547+
548+
/// If this function is max, return true
549+
/// if the function is min, return false
550+
/// otherwise return None (the default)
551+
///
552+
///
553+
/// Note: this is used to use special aggregate implementations in certain conditions
554+
fn is_descending(&self) -> Option<bool> {
555+
None
556+
}
539557
}
540558

541559
pub enum ReversedUDAF {

datafusion/physical-expr-common/src/aggregate/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,12 @@ impl AggregateExpr for AggregateFunctionExpr {
730730
}
731731
}
732732
}
733+
734+
fn get_minmax_desc(&self) -> Option<(Field, bool)> {
735+
self.fun
736+
.is_descending()
737+
.and_then(|flag| self.field().ok().map(|f| (f, flag)))
738+
}
733739
}
734740

735741
impl PartialEq<dyn Any> for AggregateFunctionExpr {

0 commit comments

Comments
 (0)