Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Jul 30, 2024
Merged
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
2 changes: 1 addition & 1 deletion datafusion/core/src/datasource/file_format/parquet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ mod tests {
.map(|i| i.to_string())
.collect();
let coll: Vec<_> = schema
.all_fields()
.flattened_fields()
.into_iter()
.map(|i| i.name().to_string())
.collect();
Expand Down
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 is_descending(&self) -> Option<bool> {
self.inner.is_descending()
}
}

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 is_descending(&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
.is_descending()
.and_then(|flag| self.field().ok().map(|f| (f, flag)))
}
}

impl PartialEq<dyn Any> for AggregateFunctionExpr {
Expand Down