This is an automated email from the ASF dual-hosted git repository.

jayzhan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new 35c2e7e7eb Initial changes to support using udaf min/max for 
statistics and opti… (#11696)
35c2e7e7eb is described below

commit 35c2e7e7eb04e80877bbbc1fa4a5b06f31a4e4bc
Author: Edmondo Porcu <[email protected]>
AuthorDate: Tue Jul 30 08:31:29 2024 -0400

    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
---
 datafusion/expr/src/udaf.rs                          | 18 ++++++++++++++++++
 datafusion/physical-expr-common/src/aggregate/mod.rs |  6 ++++++
 2 files changed, 24 insertions(+)

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 {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to