Skip to content

Commit 0c35747

Browse files
committed
Arrays to require validity
Signed-off-by: Nicholas Gates <[email protected]>
1 parent 61271b4 commit 0c35747

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

encodings/sparse/src/lib.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,24 @@ impl ValidityVTable<SparseVTable> for SparseVTable {
412412
}
413413

414414
fn validity(array: &SparseArray) -> VortexResult<Validity> {
415-
// TODO(ngates): should this be able to execute arrays?
416-
Ok(Validity::from_mask(
417-
Self::validity_mask(array),
418-
Nullability::Nullable,
415+
let patches = unsafe {
416+
Patches::new_unchecked(
417+
array.patches.array_len(),
418+
array.patches.offset().clone(),
419+
array.patches.indices().clone(),
420+
array
421+
.patches
422+
.values()
423+
.validity()?
424+
.to_array(array.patches.values().len()),
425+
array.patches.chunk_offsets().clone(),
426+
array.patches.offset_within_chunk(),
427+
)
428+
};
429+
430+
Ok(Validity::Array(
431+
unsafe { SparseArray::new_unchecked(patches, array.fill_value.is_valid().into()) }
432+
.into_array(),
419433
))
420434
}
421435

vortex-array/src/arrow/array.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::hash::Hash;
66
use std::ops::Range;
77

88
use arrow_array::ArrayRef as ArrowArrayRef;
9+
use vortex_buffer::BitBuffer;
910
use vortex_buffer::BufferHandle;
1011
use vortex_dtype::DType;
1112
use vortex_dtype::Nullability;
@@ -25,6 +26,7 @@ use crate::Canonical;
2526
use crate::EmptyMetadata;
2627
use crate::IntoArray;
2728
use crate::Precision;
29+
use crate::arrays::BoolArray;
2830
use crate::arrow::FromArrowArray;
2931
use crate::serde::ArrayChildren;
3032
use crate::stats::ArrayStats;
@@ -185,10 +187,20 @@ impl ValidityVTable<ArrowVTable> for ArrowVTable {
185187
}
186188

187189
fn validity(array: &ArrowArray) -> VortexResult<Validity> {
188-
Ok(Validity::from_mask(
189-
Self::validity_mask(array),
190-
Nullability::Nullable,
191-
))
190+
Ok(match array.inner.logical_nulls() {
191+
None => Validity::AllValid,
192+
Some(null_buffer) => match null_buffer.null_count() {
193+
0 => Validity::AllValid,
194+
n if n == array.inner.len() => Validity::AllInvalid,
195+
_ => Validity::Array(
196+
BoolArray::new(
197+
BitBuffer::from(null_buffer.inner().clone()),
198+
Validity::NonNullable,
199+
)
200+
.into_array(),
201+
),
202+
},
203+
})
192204
}
193205

194206
fn validity_mask(array: &ArrowArray) -> Mask {

0 commit comments

Comments
 (0)