Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Speeded up min_max_boolean for the case where all values are null #1005

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions src/compute/aggregate/min_max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,19 @@ pub fn min_string<O: Offset>(array: &Utf8Array<O>) -> Option<&str> {
/// ```
pub fn min_boolean(array: &BooleanArray) -> Option<bool> {
// short circuit if all nulls / zero length array
if array.null_count() == array.len() {
return None;
let null_count = array.null_count();
if null_count == array.len() {
None
} else if null_count == 0 {
Some(array.values().null_count() == 0)
} else {
// Note the min bool is false (0), so short circuit as soon as we see it
array
.iter()
.find(|&b| b == Some(false))
.flatten()
.or(Some(true))
}

// Note the min bool is false (0), so short circuit as soon as we see it
array
.iter()
.find(|&b| b == Some(false))
.flatten()
.or(Some(true))
}

/// Returns the maximum value in the boolean array
Expand All @@ -284,16 +287,19 @@ pub fn min_boolean(array: &BooleanArray) -> Option<bool> {
/// ```
pub fn max_boolean(array: &BooleanArray) -> Option<bool> {
// short circuit if all nulls / zero length array
if array.null_count() == array.len() {
return None;
let null_count = array.null_count();
if null_count == array.len() {
None
} else if null_count == 0 {
Some(array.values().null_count() < array.len())
} else {
// Note the max bool is true (1), so short circuit as soon as we see it
array
.iter()
.find(|&b| b == Some(true))
.flatten()
.or(Some(false))
}

// Note the max bool is true (1), so short circuit as soon as we see it
array
.iter()
.find(|&b| b == Some(true))
.flatten()
.or(Some(false))
}

macro_rules! dyn_generic {
Expand Down