Skip to content

Apache DataFusion SQL Query Engine

Initial changes to support using udaf min/max for statistics and opti… (#11696)

Edmondo Porcu35c2e7e7eb04
diff --git a/datafusion/expr/src/udaf.rs b/datafusion/expr/src/udaf.rs
index 3f4a99749c..af964b6154 100644
--- a/datafusion/expr/src/udaf.rs
+++ b/datafusion/expr/src/udaf.rs
@@ -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 is_descending(&self) -> Option<bool> {
+ self.inner.is_descending()
+ }
}
impl<F> From<F> for AggregateUDF
@@ -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 is_descending(&self) -> Option<bool> {
+ None
+ }
}
pub enum ReversedUDAF {
diff --git a/datafusion/physical-expr-common/src/aggregate/mod.rs b/datafusion/physical-expr-common/src/aggregate/mod.rs
index 4eede65675..aa7273648c 100644
--- a/datafusion/physical-expr-common/src/aggregate/mod.rs
+++ b/datafusion/physical-expr-common/src/aggregate/mod.rs
@@ -730,6 +730,12 @@ impl AggregateExpr for AggregateFunctionExpr {
}
}
}
+
+ fn get_minmax_desc(&self) -> Option<(Field, bool)> {
+ self.fun
+ .is_descending()
+ .and_then(|flag| self.field().ok().map(|f| (f, flag)))
+ }
}
impl PartialEq<dyn Any> for AggregateFunctionExpr {