From 7d959953e2ce2e8c7f3717ec31669d243a2f3ef9 Mon Sep 17 00:00:00 2001 From: Adam Gutglick Date: Wed, 21 Aug 2024 17:00:11 +0100 Subject: [PATCH] related --- vortex-array/src/array/sparse/flatten.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/vortex-array/src/array/sparse/flatten.rs b/vortex-array/src/array/sparse/flatten.rs index 73d146e8c4..2b0f6f89b2 100644 --- a/vortex-array/src/array/sparse/flatten.rs +++ b/vortex-array/src/array/sparse/flatten.rs @@ -1,4 +1,4 @@ -use arrow_buffer::{BooleanBuffer, BooleanBufferBuilder}; +use arrow_buffer::{BooleanBuffer, BooleanBufferBuilder, MutableBuffer}; use itertools::Itertools; use vortex_dtype::{match_each_native_ptype, DType, NativePType}; use vortex_error::{VortexError, VortexResult}; @@ -15,12 +15,18 @@ impl IntoCanonical for SparseArray { // Resolve our indices into a vector of usize applying the offset let indices = self.resolved_indices(); - let mut validity = BooleanBufferBuilder::new(self.len()); - validity.append_n(self.len(), false); + let boolean_buffer = + BooleanBufferBuilder::new_from_buffer(MutableBuffer::new_null(self.len()), self.len()); if matches!(self.dtype(), DType::Bool(_)) { let values = self.values().into_bool()?.boolean_buffer(); - canonicalize_sparse_bools(values, &indices, self.len(), self.fill_value(), validity) + canonicalize_sparse_bools( + values, + &indices, + self.len(), + self.fill_value(), + boolean_buffer, + ) } else { let values = self.values().into_primitive()?; match_each_native_ptype!(values.ptype(), |$P| { @@ -29,7 +35,7 @@ impl IntoCanonical for SparseArray { &indices, self.len(), self.fill_value(), - validity + boolean_buffer ) }) } @@ -41,7 +47,7 @@ fn canonicalize_sparse_bools( indices: &[usize], len: usize, fill_value: &Scalar, - mut validity: BooleanBufferBuilder, + mut boolean_buffer: BooleanBufferBuilder, ) -> VortexResult { let fill_bool: bool = if fill_value.is_null() { bool::default() @@ -51,10 +57,10 @@ fn canonicalize_sparse_bools( let mut flat_bools = vec![fill_bool; len]; for (i, idx) in indices.iter().enumerate() { flat_bools[*idx] = values.value(i); - validity.set_bit(*idx, true); + boolean_buffer.set_bit(*idx, true); } - let validity = Validity::from(validity.finish()); + let validity = Validity::from(boolean_buffer.finish()); let bool_values = BoolArray::from_vec(flat_bools, validity); Ok(Canonical::Bool(bool_values))