Skip to content

Commit 641048d

Browse files
authored
perf: Use sum compute function (#4207)
This patch finishes two todo items to replace with `SUM` compute function in `Validity`'s `all_valid` and `all_invalid` functions. Signed-off-by: Liang-Chi Hsieh <[email protected]>
1 parent 094d981 commit 641048d

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

vortex-array/src/validity.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,27 @@ impl Validity {
9191
Ok(match self {
9292
Validity::NonNullable | Validity::AllValid => true,
9393
Validity::AllInvalid => false,
94-
Validity::Array(array) => {
95-
// TODO(ngates): replace with SUM compute function
96-
array.to_bool()?.boolean_buffer().count_set_bits() == array.len()
97-
}
94+
Validity::Array(array) => sum(array)
95+
.map(|v| {
96+
v.as_primitive()
97+
.typed_value::<u64>()
98+
.map(|count| count == array.len() as u64)
99+
})?
100+
.ok_or_else(|| vortex_err!("Failed to compute sum for validity array"))?,
98101
})
99102
}
100103

101104
pub fn all_invalid(&self) -> VortexResult<bool> {
102105
Ok(match self {
103106
Validity::NonNullable | Validity::AllValid => false,
104107
Validity::AllInvalid => true,
105-
Validity::Array(array) => {
106-
// TODO(ngates): replace with SUM compute function
107-
array.to_bool()?.boolean_buffer().count_set_bits() == 0
108-
}
108+
Validity::Array(array) => sum(array)
109+
.map(|v| {
110+
v.as_primitive()
111+
.typed_value::<u64>()
112+
.map(|count| count == 0u64)
113+
})?
114+
.ok_or_else(|| vortex_err!("Failed to compute sum for validity array"))?,
109115
})
110116
}
111117

0 commit comments

Comments
 (0)