@@ -823,6 +823,10 @@ pub fn min_batch(values: &ArrayRef) -> Result<ScalarValue> {
823823}
824824
825825/// Finds the min/max by scanning logical rows via `ScalarValue::try_from_array`.
826+ ///
827+ /// Callers are responsible for routing dictionary arrays to this helper.
828+ /// Passing `dictionary.values()` is semantically incorrect because it can
829+ /// include unreferenced dictionary entries and ignore null key positions.
826830fn min_max_batch_generic ( values : & ArrayRef , ordering : Ordering ) -> Result < ScalarValue > {
827831 let mut index = 0 ;
828832 let mut extreme = loop {
@@ -907,7 +911,7 @@ pub fn max_batch(values: &ArrayRef) -> Result<ScalarValue> {
907911#[ cfg( test) ]
908912mod tests {
909913 use super :: * ;
910- use arrow:: array:: { AsArray , DictionaryArray } ;
914+ use arrow:: array:: DictionaryArray ;
911915 use std:: sync:: Arc ;
912916
913917 #[ test]
@@ -993,12 +997,9 @@ mod tests {
993997 let keys = Int8Array :: from ( vec ! [ Some ( 1 ) , None , Some ( 1 ) , Some ( 1 ) ] ) ;
994998 let values = Arc :: new ( StringArray :: from ( vec ! [ "zzz" , "bbb" , "aaa" ] ) ) ;
995999 let array = Arc :: new ( DictionaryArray :: new ( keys, values) ) as ArrayRef ;
996- let raw_values = array. as_any_dictionary ( ) . values ( ) ;
9971000
9981001 let min = min_batch ( & array) ?;
9991002 let max = max_batch ( & array) ?;
1000- let raw_min = min_batch ( raw_values) ?;
1001- let raw_max = max_batch ( raw_values) ?;
10021003
10031004 let expected = ScalarValue :: Dictionary (
10041005 Box :: new ( DataType :: Int8 ) ,
@@ -1007,8 +1008,6 @@ mod tests {
10071008
10081009 assert_eq ! ( min, expected) ;
10091010 assert_eq ! ( max, expected) ;
1010- assert_eq ! ( raw_min, ScalarValue :: Utf8 ( Some ( "aaa" . to_string( ) ) ) ) ;
1011- assert_eq ! ( raw_max, ScalarValue :: Utf8 ( Some ( "zzz" . to_string( ) ) ) ) ;
10121011
10131012 Ok ( ( ) )
10141013 }
0 commit comments