Skip to content

Commit

Permalink
Replacing pattern matching through downcast with trait method
Browse files Browse the repository at this point in the history
  • Loading branch information
edmondop committed Jul 3, 2024
1 parent 6993561 commit 970a7d2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions datafusion/physical-expr-common/src/aggregate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,17 @@ pub trait AggregateExpr: Send + Sync + Debug + PartialEq<dyn Any> {
) -> Option<Arc<dyn AggregateExpr>> {
None
}

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

/// Stores the physical expressions used inside the `AggregateExpr`.
Expand Down
4 changes: 4 additions & 0 deletions datafusion/physical-expr/src/aggregate/min_max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ impl AggregateExpr for Max {
fn create_sliding_accumulator(&self) -> Result<Box<dyn Accumulator>> {
Ok(Box::new(SlidingMaxAccumulator::try_new(&self.data_type)?))
}

fn get_minmax_desc(&self) -> Option<(Field, bool)> {
Some((self.field().ok()?, true))
}
}

impl PartialEq<dyn Any> for Max {
Expand Down

0 comments on commit 970a7d2

Please sign in to comment.