Skip to content

Commit 23d7fff

Browse files
alambcomphead
andauthored
Improve documentation for AggregateUDFImpl::value_from_stats (#12689)
* Improve documentation for AggregateUDFImpl::value_from_stats * Update datafusion/expr/src/udaf.rs Co-authored-by: Oleks V <[email protected]> --------- Co-authored-by: Oleks V <[email protected]>
1 parent f54712d commit 23d7fff

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

datafusion/expr/src/udaf.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,11 @@ impl fmt::Display for AggregateUDF {
9595
}
9696
}
9797

98+
/// Arguments passed to [`AggregateUDFImpl::value_from_stats`]
9899
pub struct StatisticsArgs<'a> {
100+
/// The statistics of the aggregate input
99101
pub statistics: &'a Statistics,
102+
/// The resolved return type of the aggregate function
100103
pub return_type: &'a DataType,
101104
/// Whether the aggregate function is distinct.
102105
///
@@ -251,13 +254,16 @@ impl AggregateUDF {
251254
}
252255

253256
/// Returns true if the function is max, false if the function is min
254-
/// None in all other cases, used in certain optimizations or
257+
/// None in all other cases, used in certain optimizations for
255258
/// or aggregate
256-
///
257259
pub fn is_descending(&self) -> Option<bool> {
258260
self.inner.is_descending()
259261
}
260262

263+
/// Return the value of this aggregate function if it can be determined
264+
/// entirely from statistics and arguments.
265+
///
266+
/// See [`AggregateUDFImpl::value_from_stats`] for more details.
261267
pub fn value_from_stats(
262268
&self,
263269
statistics_args: &StatisticsArgs,
@@ -577,7 +583,15 @@ pub trait AggregateUDFImpl: Debug + Send + Sync {
577583
fn is_descending(&self) -> Option<bool> {
578584
None
579585
}
580-
// Return the value of the current UDF from the statistics
586+
587+
/// Return the value of this aggregate function if it can be determined
588+
/// entirely from statistics and arguments.
589+
///
590+
/// Using a [`ScalarValue`] rather than a runtime computation can significantly
591+
/// improving query performance.
592+
///
593+
/// For example, if the minimum value of column `x` is known to be `42` from
594+
/// statistics, then the aggregate `MIN(x)` should return `Some(ScalarValue(42))`
581595
fn value_from_stats(&self, _statistics_args: &StatisticsArgs) -> Option<ScalarValue> {
582596
None
583597
}

0 commit comments

Comments
 (0)