@@ -26,6 +26,7 @@ use arrow::{
2626} ;
2727use arrow_schema:: { Schema , SchemaRef , SortOptions } ;
2828use datafusion_common:: NullEquality ;
29+ use datafusion_common:: utils:: normalize_float_zero;
2930use datafusion_common:: { Result , ScalarValue , internal_err} ;
3031use datafusion_execution:: { RecordBatchStream , SendableRecordBatchStream } ;
3132use datafusion_expr:: { ColumnarValue , JoinType , Operator } ;
@@ -591,9 +592,14 @@ fn build_matched_indices_and_mark_buffered(
591592// NULLs sort first, so the last key is NULL only when every buffered key is.
592593fn buffered_extreme ( values : & ArrayRef ) -> Result < Option < ColumnarValue > > {
593594 Ok ( match values. len ( ) . checked_sub ( 1 ) {
594- Some ( last) if values. is_valid ( last) => Some ( ColumnarValue :: Scalar (
595- ScalarValue :: try_from_array ( values, last) ?,
596- ) ) ,
595+ // `apply_cmp` normalizes `-0.0` only in flat float scalars, not inside a
596+ // `ScalarValue::Dictionary`, so normalize the key before taking it.
597+ Some ( last) if values. is_valid ( last) => {
598+ let extreme = normalize_float_zero ( & values. slice ( last, 1 ) ) ;
599+ Some ( ColumnarValue :: Scalar ( ScalarValue :: try_from_array (
600+ & extreme, 0 ,
601+ ) ?) )
602+ }
597603 _ => None ,
598604 } )
599605}
@@ -1347,6 +1353,30 @@ mod tests {
13471353 . collect:: <DictionaryArray <Int32Type >>( ) ,
13481354 ) ,
13491355 ) ,
1356+ (
1357+ // `-0.0` as the buffered extreme inside a dictionary: the smallest
1358+ // key for `<`/`<=`, the largest for `>`/`>=`.
1359+ "dictionary_float64_neg_zero_min" ,
1360+ Arc :: new( DictionaryArray :: <Int32Type >:: new(
1361+ Int32Array :: from( vec![ 0 , 1 ] ) ,
1362+ Arc :: new( Float64Array :: from( vec![ -0.0 , 0.5 ] ) ) ,
1363+ ) ) ,
1364+ Arc :: new( DictionaryArray :: <Int32Type >:: new(
1365+ Int32Array :: from( vec![ 0 , 1 , 2 ] ) ,
1366+ Arc :: new( Float64Array :: from( vec![ 0.0 , -0.0 , 0.25 ] ) ) ,
1367+ ) ) ,
1368+ ) ,
1369+ (
1370+ "dictionary_float64_neg_zero_max" ,
1371+ Arc :: new( DictionaryArray :: <Int32Type >:: new(
1372+ Int32Array :: from( vec![ 0 , 1 ] ) ,
1373+ Arc :: new( Float64Array :: from( vec![ -1.0 , -0.0 ] ) ) ,
1374+ ) ) ,
1375+ Arc :: new( DictionaryArray :: <Int32Type >:: new(
1376+ Int32Array :: from( vec![ 0 , 1 , 2 ] ) ,
1377+ Arc :: new( Float64Array :: from( vec![ 0.0 , -0.0 , -0.5 ] ) ) ,
1378+ ) ) ,
1379+ ) ,
13501380 (
13511381 "decimal128" ,
13521382 Arc :: new(
0 commit comments