Skip to content

Commit 77a518e

Browse files
committed
feat: reintroduce min_max_batch_generic function for dictionary array handling
1 parent ccbff59 commit 77a518e

1 file changed

Lines changed: 32 additions & 32 deletions

File tree

  • datafusion/functions-aggregate-common/src

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

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -476,38 +476,6 @@ fn min_max_scalar(
476476
}
477477
}
478478

479-
/// Finds the min/max by scanning logical rows via `ScalarValue::try_from_array`.
480-
///
481-
/// This path is required for dictionary arrays because comparing
482-
/// `dictionary.values()` is not semantically correct: it can include
483-
/// unreferenced values and ignore null key positions.
484-
fn min_max_batch_generic(values: &ArrayRef, ordering: Ordering) -> Result<ScalarValue> {
485-
let mut index = 0;
486-
let mut extreme = loop {
487-
if index == values.len() {
488-
return ScalarValue::try_from(values.data_type());
489-
}
490-
491-
let current = ScalarValue::try_from_array(values, index)?;
492-
index += 1;
493-
494-
if !current.is_null() {
495-
break current;
496-
}
497-
};
498-
499-
while index < values.len() {
500-
let current = ScalarValue::try_from_array(values, index)?;
501-
index += 1;
502-
503-
if !current.is_null() && extreme.try_cmp(&current)? == ordering {
504-
extreme = current;
505-
}
506-
}
507-
508-
Ok(extreme)
509-
}
510-
511479
/// An accumulator to compute the maximum value
512480
#[derive(Debug, Clone)]
513481
pub struct MaxAccumulator {
@@ -854,6 +822,38 @@ pub fn min_batch(values: &ArrayRef) -> Result<ScalarValue> {
854822
})
855823
}
856824

825+
/// Finds the min/max by scanning logical rows via `ScalarValue::try_from_array`.
826+
///
827+
/// This path is required for dictionary arrays because comparing
828+
/// `dictionary.values()` is not semantically correct: it can include
829+
/// unreferenced values and ignore null key positions.
830+
fn min_max_batch_generic(values: &ArrayRef, ordering: Ordering) -> Result<ScalarValue> {
831+
let mut index = 0;
832+
let mut extreme = loop {
833+
if index == values.len() {
834+
return ScalarValue::try_from(values.data_type());
835+
}
836+
837+
let current = ScalarValue::try_from_array(values, index)?;
838+
index += 1;
839+
840+
if !current.is_null() {
841+
break current;
842+
}
843+
};
844+
845+
while index < values.len() {
846+
let current = ScalarValue::try_from_array(values, index)?;
847+
index += 1;
848+
849+
if !current.is_null() && extreme.try_cmp(&current)? == ordering {
850+
extreme = current;
851+
}
852+
}
853+
854+
Ok(extreme)
855+
}
856+
857857
/// dynamically-typed max(array) -> ScalarValue
858858
pub fn max_batch(values: &ArrayRef) -> Result<ScalarValue> {
859859
Ok(match values.data_type() {

0 commit comments

Comments
 (0)