Skip to content

Commit 8aa91e5

Browse files
authored
Make bool_or an alias for max_boolean (#6100)
Improves `cargo bench --bench aggregate_kernels -- "bool/or"` throughput by 68%-22366% on my machine
1 parent 658e58f commit 8aa91e5

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

arrow-arith/src/aggregate.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -674,10 +674,7 @@ pub fn bool_and(array: &BooleanArray) -> Option<bool> {
674674
///
675675
/// Returns `None` if the array is empty or only contains null values.
676676
pub fn bool_or(array: &BooleanArray) -> Option<bool> {
677-
if array.null_count() == array.len() {
678-
return None;
679-
}
680-
Some(array.true_count() != 0)
677+
max_boolean(array)
681678
}
682679

683680
/// Returns the sum of values in the primitive array.

arrow/benches/aggregate_kernels.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,35 +82,53 @@ fn add_benchmark(c: &mut Criterion) {
8282
.bench_function("max nonnull mixed", |b| {
8383
b.iter(|| max_boolean(&nonnull_bools_mixed))
8484
})
85+
.bench_function("or nonnull mixed", |b| {
86+
b.iter(|| bool_or(&nonnull_bools_mixed))
87+
})
8588
.bench_function("min nonnull false", |b| {
8689
b.iter(|| min_boolean(&nonnull_bools_all_false))
8790
})
8891
.bench_function("max nonnull false", |b| {
8992
b.iter(|| max_boolean(&nonnull_bools_all_false))
9093
})
94+
.bench_function("or nonnull false", |b| {
95+
b.iter(|| bool_or(&nonnull_bools_all_false))
96+
})
9197
.bench_function("min nonnull true", |b| {
9298
b.iter(|| min_boolean(&nonnull_bools_all_true))
9399
})
94100
.bench_function("max nonnull true", |b| {
95101
b.iter(|| max_boolean(&nonnull_bools_all_true))
96102
})
103+
.bench_function("or nonnull true", |b| {
104+
b.iter(|| bool_or(&nonnull_bools_all_true))
105+
})
97106
.bench_function("min nullable mixed", |b| {
98107
b.iter(|| min_boolean(&nullable_bool_mixed))
99108
})
100109
.bench_function("max nullable mixed", |b| {
101110
b.iter(|| max_boolean(&nullable_bool_mixed))
102111
})
112+
.bench_function("or nullable mixed", |b| {
113+
b.iter(|| bool_or(&nullable_bool_mixed))
114+
})
103115
.bench_function("min nullable false", |b| {
104116
b.iter(|| min_boolean(&nullable_bool_all_false))
105117
})
106118
.bench_function("max nullable false", |b| {
107119
b.iter(|| max_boolean(&nullable_bool_all_false))
108120
})
121+
.bench_function("or nullable false", |b| {
122+
b.iter(|| bool_or(&nullable_bool_all_false))
123+
})
109124
.bench_function("min nullable true", |b| {
110125
b.iter(|| min_boolean(&nullable_bool_all_true))
111126
})
112127
.bench_function("max nullable true", |b| {
113128
b.iter(|| max_boolean(&nullable_bool_all_true))
129+
})
130+
.bench_function("or nullable true", |b| {
131+
b.iter(|| bool_or(&nullable_bool_all_true))
114132
});
115133
}
116134
}

0 commit comments

Comments
 (0)