Skip to content

Commit 31026ce

Browse files
authored
Arrays must return Validity (#5785)
Signed-off-by: Nicholas Gates <[email protected]>
1 parent db44ca6 commit 31026ce

File tree

23 files changed

+231
-28
lines changed

23 files changed

+231
-28
lines changed

encodings/alp/src/alp/array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ impl ALPArray {
432432
}
433433

434434
impl ValidityChild<ALPVTable> for ALPVTable {
435-
fn validity_child(array: &ALPArray) -> &dyn Array {
435+
fn validity_child(array: &ALPArray) -> &ArrayRef {
436436
array.encoded()
437437
}
438438
}

encodings/alp/src/alp_rd/array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ impl ALPRDArray {
368368
}
369369

370370
impl ValidityChild<ALPRDVTable> for ALPRDVTable {
371-
fn validity_child(array: &ALPRDArray) -> &dyn Array {
371+
fn validity_child(array: &ALPRDArray) -> &ArrayRef {
372372
array.left_parts()
373373
}
374374
}

encodings/datetime-parts/src/array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ impl BaseArrayVTable<DateTimePartsVTable> for DateTimePartsVTable {
288288
}
289289

290290
impl ValidityChild<DateTimePartsVTable> for DateTimePartsVTable {
291-
fn validity_child(array: &DateTimePartsArray) -> &dyn Array {
291+
fn validity_child(array: &DateTimePartsArray) -> &ArrayRef {
292292
array.days()
293293
}
294294
}

encodings/decimal-byte-parts/src/decimal_byte_parts/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ impl OperationsVTable<DecimalBytePartsVTable> for DecimalBytePartsVTable {
269269
}
270270

271271
impl ValidityChild<DecimalBytePartsVTable> for DecimalBytePartsVTable {
272-
fn validity_child(array: &DecimalBytePartsArray) -> &dyn Array {
272+
fn validity_child(array: &DecimalBytePartsArray) -> &ArrayRef {
273273
// validity stored in 0th child
274-
array.msp.as_ref()
274+
&array.msp
275275
}
276276
}
277277

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4-
use vortex_array::Array;
4+
use vortex_array::ArrayRef;
55
use vortex_array::vtable::ValidityChild;
66

77
use super::FoRVTable;
88
use crate::FoRArray;
99

1010
impl ValidityChild<FoRVTable> for FoRVTable {
11-
fn validity_child(array: &FoRArray) -> &dyn Array {
12-
array.encoded().as_ref()
11+
fn validity_child(array: &FoRArray) -> &ArrayRef {
12+
array.encoded()
1313
}
1414
}

encodings/fastlanes/src/rle/vtable/validity.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4-
use vortex_array::Array;
54
use vortex_array::ArrayRef;
65
use vortex_array::vtable::ValidityChild;
76
use vortex_array::vtable::ValidityChildSliceHelper;
@@ -10,8 +9,8 @@ use super::RLEVTable;
109
use crate::RLEArray;
1110

1211
impl ValidityChild<RLEVTable> for RLEVTable {
13-
fn validity_child(array: &RLEArray) -> &dyn Array {
14-
array.indices().as_ref()
12+
fn validity_child(array: &RLEArray) -> &ArrayRef {
13+
array.indices()
1514
}
1615
}
1716

encodings/fsst/src/array.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ pub struct FSSTArray {
198198
symbols: Buffer<Symbol>,
199199
symbol_lengths: Buffer<u8>,
200200
codes: VarBinArray,
201+
/// NOTE(ngates): this === codes, but is stored as an ArrayRef so we can return &ArrayRef!
202+
codes_array: ArrayRef,
201203
/// Lengths of the original values before compression, can be compressed.
202204
uncompressed_lengths: ArrayRef,
203205
stats_set: ArrayStats,
@@ -283,12 +285,14 @@ impl FSSTArray {
283285
Compressor::rebuild_from(symbols2.as_slice(), symbol_lengths2.as_slice())
284286
})
285287
as Box<dyn Fn() -> Compressor + Send>));
288+
let codes_array = codes.to_array();
286289

287290
Self {
288291
dtype,
289292
symbols,
290293
symbol_lengths,
291294
codes,
295+
codes_array,
292296
uncompressed_lengths,
293297
stats_set: Default::default(),
294298
compressor,
@@ -377,8 +381,8 @@ impl BaseArrayVTable<FSSTVTable> for FSSTVTable {
377381
}
378382

379383
impl ValidityChild<FSSTVTable> for FSSTVTable {
380-
fn validity_child(array: &FSSTArray) -> &dyn Array {
381-
array.codes().as_ref()
384+
fn validity_child(array: &FSSTArray) -> &ArrayRef {
385+
&array.codes_array
382386
}
383387
}
384388

encodings/runend/src/array.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use vortex_array::search_sorted::SearchSortedSide;
2121
use vortex_array::serde::ArrayChildren;
2222
use vortex_array::stats::ArrayStats;
2323
use vortex_array::stats::StatsSetRef;
24+
use vortex_array::validity::Validity;
2425
use vortex_array::vtable;
2526
use vortex_array::vtable::ArrayId;
2627
use vortex_array::vtable::ArrayVTable;
@@ -427,6 +428,22 @@ impl ValidityVTable<RunEndVTable> for RunEndVTable {
427428
array.values().all_invalid()
428429
}
429430

431+
fn validity(array: &RunEndArray) -> VortexResult<Validity> {
432+
Ok(match array.values().validity()? {
433+
Validity::NonNullable | Validity::AllValid => Validity::AllValid,
434+
Validity::AllInvalid => Validity::AllInvalid,
435+
Validity::Array(values_validity) => Validity::Array(unsafe {
436+
RunEndArray::new_unchecked(
437+
array.ends().clone(),
438+
values_validity,
439+
array.offset(),
440+
array.len(),
441+
)
442+
.into_array()
443+
}),
444+
})
445+
}
446+
430447
fn validity_mask(array: &RunEndArray) -> Mask {
431448
match array.values().validity_mask() {
432449
Mask::AllTrue(_) => Mask::AllTrue(array.len()),

encodings/sequence/src/array.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use vortex_array::arrays::PrimitiveArray;
1919
use vortex_array::serde::ArrayChildren;
2020
use vortex_array::stats::ArrayStats;
2121
use vortex_array::stats::StatsSetRef;
22+
use vortex_array::validity::Validity;
2223
use vortex_array::vtable;
2324
use vortex_array::vtable::ArrayId;
2425
use vortex_array::vtable::ArrayVTable;
@@ -413,6 +414,10 @@ impl ValidityVTable<SequenceVTable> for SequenceVTable {
413414
false
414415
}
415416

417+
fn validity(_array: &SequenceArray) -> VortexResult<Validity> {
418+
Ok(Validity::AllValid)
419+
}
420+
416421
fn validity_mask(array: &SequenceArray) -> Mask {
417422
Mask::AllTrue(array.len())
418423
}

encodings/sparse/src/lib.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use vortex_array::patches::PatchesMetadata;
2929
use vortex_array::serde::ArrayChildren;
3030
use vortex_array::stats::ArrayStats;
3131
use vortex_array::stats::StatsSetRef;
32+
use vortex_array::validity::Validity;
3233
use vortex_array::vtable;
3334
use vortex_array::vtable::ArrayId;
3435
use vortex_array::vtable::ArrayVTable;
@@ -410,6 +411,28 @@ impl ValidityVTable<SparseVTable> for SparseVTable {
410411
array.patches().values().all_invalid()
411412
}
412413

414+
fn validity(array: &SparseArray) -> VortexResult<Validity> {
415+
let patches = unsafe {
416+
Patches::new_unchecked(
417+
array.patches.array_len(),
418+
array.patches.offset(),
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(),
433+
))
434+
}
435+
413436
fn validity_mask(array: &SparseArray) -> Mask {
414437
let fill_is_valid = array.fill_scalar().is_valid();
415438
let values_validity = array.patches().values().validity_mask();

0 commit comments

Comments
 (0)