Skip to content

Commit 377fb5d

Browse files
committed
feat(min_max): add dictionary key-type validation and improve error handling
- Implemented explicit dictionary key-type validation for dictionary scalars in the macro dictionary branch - Introduced an error for mismatched dictionary key types instead of silently preserving the left key type - Updated macro comments to clarify that key types are validated before rewrapping
1 parent 7ea7cb4 commit 377fb5d

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

  • datafusion/functions-aggregate-common/src

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ macro_rules! min_max_generic {
143143

144144
// min/max of two logically compatible scalar values.
145145
// Dictionary scalars are unwrapped to their inner values for comparison,
146-
// then rewrapped with the dictionary key type when both inputs are dictionaries.
146+
// then rewrapped with the dictionary key type when both inputs are dictionaries
147+
// after validating that their key types match.
147148
macro_rules! min_max {
148149
($VALUE:expr, $DELTA:expr, $OP:ident) => {{
149150
Ok(match ($VALUE, $DELTA) {
@@ -424,8 +425,19 @@ macro_rules! min_max {
424425
let result = min_max_generic!(lhs, rhs, $OP);
425426

426427
match lhs_key_type.zip(rhs_key_type) {
427-
Some((key_type, _)) => {
428-
ScalarValue::Dictionary(Box::new(key_type.clone()), Box::new(result))
428+
Some((lhs_key_type, rhs_key_type)) => {
429+
if lhs_key_type != rhs_key_type {
430+
return internal_err!(
431+
"MIN/MAX is not expected to receive dictionary scalars with different key types ({:?} vs {:?})",
432+
lhs_key_type,
433+
rhs_key_type
434+
);
435+
}
436+
437+
ScalarValue::Dictionary(
438+
Box::new(lhs_key_type.clone()),
439+
Box::new(result),
440+
)
429441
}
430442
None => result,
431443
}

0 commit comments

Comments
 (0)