Skip to content

Commit ccbff59

Browse files
committed
feat: refactor min_max to utilize choose_min_max for improved internal matching
- Removed the call to min_max_scalar within min_max function. - Implemented internal matching using choose_min_max!($OP). - Updated return values to provide Ok with min or max based on Ordering result. - Added unreachable!() for Ordering::Equal case for error handling.
1 parent bca94be commit ccbff59

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

  • datafusion/functions-aggregate-common/src

datafusion/functions-aggregate-common/src/min_max.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,18 @@ macro_rules! min_max_generic {
141141
}};
142142
}
143143

144+
macro_rules! min_max {
145+
($VALUE:expr, $DELTA:expr, $OP:ident) => {{
146+
match choose_min_max!($OP) {
147+
Ordering::Greater => Ok(min_max_scalar_impl!($VALUE, $DELTA, min)),
148+
Ordering::Less => Ok(min_max_scalar_impl!($VALUE, $DELTA, max)),
149+
Ordering::Equal => {
150+
unreachable!("min/max comparisons do not use equal ordering")
151+
}
152+
}
153+
}};
154+
}
155+
144156
// min/max of two logically compatible scalar values.
145157
// Dictionary scalars participate by comparing their inner logical values.
146158
// When both inputs are dictionaries, matching key types are preserved in the
@@ -464,10 +476,6 @@ fn min_max_scalar(
464476
}
465477
}
466478

467-
macro_rules! min_max {
468-
($VALUE:expr, $DELTA:expr, $OP:ident) => {{ min_max_scalar($VALUE, $DELTA, choose_min_max!($OP)) }};
469-
}
470-
471479
/// Finds the min/max by scanning logical rows via `ScalarValue::try_from_array`.
472480
///
473481
/// This path is required for dictionary arrays because comparing

0 commit comments

Comments
 (0)