File tree Expand file tree Collapse file tree
datafusion/functions-aggregate-common/src Expand file tree Collapse file tree Original file line number Diff line number Diff 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.
147148macro_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 }
You can’t perform that action at this time.
0 commit comments