Skip to content

Commit 6a0f257

Browse files
committed
Allow nullable children of MaskedArray
Signed-off-by: Nicholas Gates <nick@nickgates.com>
1 parent 168982b commit 6a0f257

File tree

18 files changed

+122
-271
lines changed

18 files changed

+122
-271
lines changed

vortex-array/src/arrays/bool/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ pub use array::*;
99
pub mod compute;
1010

1111
mod vtable;
12-
pub use vtable::BoolMaskedValidityRule;
1312
pub use vtable::BoolVTable;
1413

1514
#[cfg(feature = "test-harness")]

vortex-array/src/arrays/bool/vtable/mod.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33

44
use vortex_buffer::BufferHandle;
55
use vortex_dtype::DType;
6+
use vortex_error::vortex_bail;
67
use vortex_error::VortexExpect;
78
use vortex_error::VortexResult;
8-
use vortex_error::vortex_bail;
9-
use vortex_vector::Vector;
109
use vortex_vector::bool::BoolVector;
10+
use vortex_vector::Vector;
1111

12-
use crate::DeserializeMetadata;
13-
use crate::ProstMetadata;
14-
use crate::SerializeMetadata;
1512
use crate::arrays::BoolArray;
1613
use crate::execution::ExecutionCtx;
1714
use crate::serde::ArrayChildren;
@@ -21,16 +18,16 @@ use crate::vtable::ArrayVTableExt;
2118
use crate::vtable::NotSupported;
2219
use crate::vtable::VTable;
2320
use crate::vtable::ValidityVTableFromValidityHelper;
21+
use crate::DeserializeMetadata;
22+
use crate::ProstMetadata;
23+
use crate::SerializeMetadata;
2424

2525
mod array;
2626
mod canonical;
2727
mod operations;
28-
pub mod operator;
2928
mod validity;
3029
mod visitor;
3130

32-
pub use operator::BoolMaskedValidityRule;
33-
3431
use crate::vtable::ArrayId;
3532
use crate::vtable::ArrayVTable;
3633

vortex-array/src/arrays/bool/vtable/operator.rs

Lines changed: 0 additions & 48 deletions
This file was deleted.

vortex-array/src/arrays/decimal/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ pub use array::DecimalArray;
77
mod compute;
88

99
mod vtable;
10-
pub use vtable::DecimalMaskedValidityRule;
1110
pub use vtable::DecimalVTable;
1211

1312
mod utils;

vortex-array/src/arrays/decimal/vtable/mod.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,17 @@
44
use vortex_buffer::Alignment;
55
use vortex_buffer::Buffer;
66
use vortex_buffer::BufferHandle;
7+
use vortex_dtype::match_each_decimal_value_type;
78
use vortex_dtype::DType;
89
use vortex_dtype::NativeDecimalType;
910
use vortex_dtype::PrecisionScale;
10-
use vortex_dtype::match_each_decimal_value_type;
11-
use vortex_error::VortexResult;
1211
use vortex_error::vortex_bail;
1312
use vortex_error::vortex_ensure;
13+
use vortex_error::VortexResult;
1414
use vortex_scalar::DecimalType;
15-
use vortex_vector::Vector;
1615
use vortex_vector::decimal::DVector;
16+
use vortex_vector::Vector;
1717

18-
use crate::DeserializeMetadata;
19-
use crate::ProstMetadata;
20-
use crate::SerializeMetadata;
2118
use crate::arrays::DecimalArray;
2219
use crate::execution::ExecutionCtx;
2320
use crate::serde::ArrayChildren;
@@ -27,16 +24,16 @@ use crate::vtable::ArrayVTableExt;
2724
use crate::vtable::NotSupported;
2825
use crate::vtable::VTable;
2926
use crate::vtable::ValidityVTableFromValidityHelper;
27+
use crate::DeserializeMetadata;
28+
use crate::ProstMetadata;
29+
use crate::SerializeMetadata;
3030

3131
mod array;
3232
mod canonical;
3333
mod operations;
34-
pub mod operator;
3534
mod validity;
3635
mod visitor;
3736

38-
pub use operator::DecimalMaskedValidityRule;
39-
4037
use crate::vtable::ArrayId;
4138
use crate::vtable::ArrayVTable;
4239

@@ -142,18 +139,18 @@ pub struct DecimalVTable;
142139

143140
#[cfg(test)]
144141
mod tests {
145-
use vortex_buffer::ByteBufferMut;
146142
use vortex_buffer::buffer;
143+
use vortex_buffer::ByteBufferMut;
147144
use vortex_dtype::DecimalDType;
148145

149-
use crate::ArrayContext;
150-
use crate::IntoArray;
151146
use crate::arrays::DecimalArray;
152147
use crate::arrays::DecimalVTable;
153148
use crate::serde::ArrayParts;
154149
use crate::serde::SerializeOptions;
155150
use crate::validity::Validity;
156151
use crate::vtable::ArrayVTableExt;
152+
use crate::ArrayContext;
153+
use crate::IntoArray;
157154

158155
#[test]
159156
fn test_array_serde() {

vortex-array/src/arrays/decimal/vtable/operator.rs

Lines changed: 0 additions & 58 deletions
This file was deleted.

vortex-array/src/arrays/masked/array.rs

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

4+
use std::ops::{BitAnd, Not};
45
use vortex_dtype::DType;
5-
use vortex_error::VortexResult;
66
use vortex_error::vortex_bail;
7+
use vortex_error::VortexResult;
78

8-
use crate::ArrayRef;
99
use crate::compute::mask;
1010
use crate::stats::ArrayStats;
1111
use crate::validity::Validity;
12+
use crate::{Array, ArrayRef};
1213

1314
#[derive(Clone, Debug)]
1415
pub struct MaskedArray {
@@ -20,14 +21,6 @@ pub struct MaskedArray {
2021

2122
impl MaskedArray {
2223
pub fn try_new(child: ArrayRef, validity: Validity) -> VortexResult<Self> {
23-
if matches!(validity, Validity::NonNullable) {
24-
vortex_bail!("MaskedArray must have nullable validity, got {validity:?}")
25-
}
26-
27-
if !child.all_valid() {
28-
vortex_bail!("MaskedArray children must not have nulls");
29-
}
30-
3124
if let Some(validity_len) = validity.maybe_len()
3225
&& validity_len != child.len()
3326
{
@@ -50,9 +43,16 @@ impl MaskedArray {
5043
&self.child
5144
}
5245

46+
pub fn mask(&self) -> &Validity {
47+
&self.validity
48+
}
49+
5350
pub(crate) fn masked_child(&self) -> VortexResult<ArrayRef> {
54-
// Invert the validity mask - we want to set values to null where validity is false.
55-
let inverted_mask = !self.validity.to_mask(self.len());
56-
mask(&self.child, &inverted_mask)
51+
let intersected_validity = self
52+
.child
53+
.validity_mask()
54+
.bitand(&self.validity.to_mask(self.len()));
55+
// Note: the compute function takes the validity inverted!!
56+
mask(&self.child, &intersected_validity.not())
5757
}
5858
}

vortex-array/src/arrays/masked/compute/compare.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33

44
use vortex_error::VortexResult;
55

6-
use crate::Array;
7-
use crate::ArrayRef;
8-
use crate::IntoArray;
96
use crate::arrays::BoolArray;
107
use crate::arrays::MaskedArray;
118
use crate::arrays::MaskedVTable;
129
use crate::canonical::ToCanonical;
10+
use crate::compute::compare;
1311
use crate::compute::CompareKernel;
1412
use crate::compute::CompareKernelAdapter;
1513
use crate::compute::Operator;
16-
use crate::compute::compare;
1714
use crate::register_kernel;
1815
use crate::vtable::ValidityHelper;
16+
use crate::Array;
17+
use crate::ArrayRef;
18+
use crate::IntoArray;
1919

2020
impl CompareKernel for MaskedVTable {
2121
fn compare(
@@ -29,7 +29,7 @@ impl CompareKernel for MaskedVTable {
2929

3030
// Get the boolean buffer from the comparison result
3131
let bool_array = compare_result.to_bool();
32-
let combined_validity = bool_array.validity().clone().and(lhs.validity().clone());
32+
let combined_validity = bool_array.validity().clone().and(lhs.mask().clone());
3333

3434
// Return a plain BoolArray with the combined validity
3535
Ok(Some(
@@ -47,14 +47,14 @@ mod tests {
4747
use vortex_mask::Mask;
4848
use vortex_scalar::Scalar;
4949

50-
use crate::IntoArray;
51-
use crate::ToCanonical;
5250
use crate::arrays::ConstantArray;
5351
use crate::arrays::MaskedArray;
5452
use crate::arrays::PrimitiveArray;
55-
use crate::compute::Operator;
5653
use crate::compute::compare;
54+
use crate::compute::Operator;
5755
use crate::validity::Validity;
56+
use crate::IntoArray;
57+
use crate::ToCanonical;
5858

5959
#[test]
6060
fn test_compare_value() {

vortex-array/src/arrays/masked/compute/filter.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,26 @@
44
use vortex_error::VortexResult;
55
use vortex_mask::Mask;
66

7-
use crate::ArrayRef;
8-
use crate::IntoArray;
97
use crate::arrays::MaskedArray;
108
use crate::arrays::MaskedVTable;
9+
use crate::compute::filter;
1110
use crate::compute::FilterKernel;
1211
use crate::compute::FilterKernelAdapter;
13-
use crate::compute::filter;
1412
use crate::register_kernel;
15-
use crate::vtable::ValidityHelper;
13+
use crate::ArrayRef;
14+
use crate::IntoArray;
1615

1716
impl FilterKernel for MaskedVTable {
1817
fn filter(&self, array: &MaskedArray, mask: &Mask) -> VortexResult<ArrayRef> {
1918
// Filter the validity to get the new validity
20-
let filtered_validity = array.validity().filter(mask)?;
19+
let filtered_mask = array.mask().filter(mask)?;
2120

2221
// Filter the child array
2322
// The child is guaranteed to have no nulls, so filtering it is straightforward
2423
let filtered_child = filter(&array.child, mask)?;
2524

2625
// Construct new MaskedArray
27-
Ok(MaskedArray::try_new(filtered_child, filtered_validity)?.into_array())
26+
Ok(MaskedArray::try_new(filtered_child, filtered_mask)?.into_array())
2827
}
2928
}
3029

@@ -34,11 +33,11 @@ register_kernel!(FilterKernelAdapter(MaskedVTable).lift());
3433
mod tests {
3534
use rstest::rstest;
3635

37-
use crate::IntoArray;
3836
use crate::arrays::MaskedArray;
3937
use crate::arrays::PrimitiveArray;
4038
use crate::compute::conformance::filter::test_filter_conformance;
4139
use crate::validity::Validity;
40+
use crate::IntoArray;
4241

4342
#[rstest]
4443
#[case(

0 commit comments

Comments
 (0)