Skip to content

Commit 0c3afcb

Browse files
committed
Remove selection mask
Signed-off-by: Nicholas Gates <[email protected]>
1 parent 475582e commit 0c3afcb

File tree

5 files changed

+87
-0
lines changed

5 files changed

+87
-0
lines changed

encodings/sequence/src/array.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
use std::hash::Hash;
55
use std::ops::Range;
66

7+
use num_traits::One;
78
use num_traits::cast::FromPrimitive;
89
use vortex_array::arrays::PrimitiveArray;
10+
use vortex_array::execution::ExecutionCtx;
911
use vortex_array::serde::ArrayChildren;
1012
use vortex_array::stats::{ArrayStats, StatsSetRef};
1113
use vortex_array::vtable::{
@@ -24,6 +26,8 @@ use vortex_dtype::{
2426
use vortex_error::{VortexExpect, VortexResult, vortex_bail, vortex_err};
2527
use vortex_mask::Mask;
2628
use vortex_scalar::{PValue, Scalar, ScalarValue};
29+
use vortex_vector::Vector;
30+
use vortex_vector::primitive::PVector;
2731

2832
vtable!(Sequence);
2933

@@ -242,6 +246,26 @@ impl VTable for SequenceVTable {
242246
len,
243247
))
244248
}
249+
250+
fn execute(array: &Self::Array, _ctx: &mut dyn ExecutionCtx) -> VortexResult<Vector> {
251+
Ok(match_each_native_ptype!(array.ptype(), |P| {
252+
let base = array.base().cast::<P>();
253+
let multiplier = array.multiplier().cast::<P>();
254+
255+
let values = if multiplier == <P>::one() {
256+
BufferMut::from_iter(
257+
(0..array.len()).map(|i| base + <P>::from_usize(i).vortex_expect("must fit")),
258+
)
259+
} else {
260+
BufferMut::from_iter(
261+
(0..array.len())
262+
.map(|i| base + <P>::from_usize(i).vortex_expect("must fit") * multiplier),
263+
)
264+
};
265+
266+
PVector::<P>::new(values.freeze(), Mask::new_true(array.len())).into()
267+
}))
268+
}
245269
}
246270

247271
impl ArrayVTable<SequenceVTable> for SequenceVTable {

vortex-array/src/expr/exprs/get_item/mod.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ use std::fmt::Formatter;
77
use std::ops::Not;
88

99
use prost::Message;
10+
use vortex_compute::mask::MaskValidity;
1011
use vortex_dtype::{DType, FieldName, FieldPath, Nullability};
1112
use vortex_error::{VortexResult, vortex_bail, vortex_err};
1213
use vortex_proto::expr as pb;
14+
use vortex_vector::{Vector, VectorOps};
1315

1416
use crate::compute::mask;
1517
use crate::expr::exprs::root::root;
@@ -96,6 +98,29 @@ impl VTable for GetItem {
9698
}
9799
}
98100

101+
fn execute(
102+
&self,
103+
expr: &ExpressionView<Self>,
104+
vector: &Vector,
105+
dtype: &DType,
106+
) -> VortexResult<Vector> {
107+
let child_dtype = expr.child(0).return_dtype(dtype)?;
108+
let struct_dtype = child_dtype
109+
.as_struct_fields_opt()
110+
.ok_or_else(|| vortex_err!("Expected struct dtype for child of GetItem expression"))?;
111+
let field_idx = struct_dtype
112+
.find(expr.data())
113+
.ok_or_else(|| vortex_err!("Field {} not found in struct dtype", expr.data()))?;
114+
115+
let struct_vector = expr.child(0).execute(vector, dtype)?.into_struct();
116+
117+
// We must intersect the validity with that of the parent struct
118+
let field = struct_vector.fields()[field_idx].clone();
119+
let field = MaskValidity::mask_validity(field, struct_vector.validity());
120+
121+
Ok(field)
122+
}
123+
99124
fn stat_max(
100125
&self,
101126
expr: &ExpressionView<Self>,

vortex-array/src/expr/exprs/is_null.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use std::ops::Not;
77
use vortex_dtype::{DType, Nullability};
88
use vortex_error::{VortexResult, vortex_bail};
99
use vortex_mask::Mask;
10+
use vortex_vector::bool::BoolVector;
11+
use vortex_vector::{Vector, VectorOps};
1012

1113
use crate::arrays::{BoolArray, ConstantArray};
1214
use crate::expr::exprs::binary::eq;
@@ -69,6 +71,20 @@ impl VTable for IsNull {
6971
}
7072
}
7173

74+
fn execute(
75+
&self,
76+
expr: &ExpressionView<Self>,
77+
vector: &Vector,
78+
dtype: &DType,
79+
) -> VortexResult<Vector> {
80+
let child = expr.child(0).execute(vector, dtype)?;
81+
Ok(BoolVector::new(
82+
child.validity().to_bit_buffer().not(),
83+
Mask::new_true(child.len()),
84+
)
85+
.into())
86+
}
87+
7288
fn stat_falsification(
7389
&self,
7490
expr: &ExpressionView<Self>,

vortex-array/src/expr/exprs/not.rs

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

44
use std::fmt::Formatter;
55

6+
use vortex_compute::logical::LogicalNot;
67
use vortex_dtype::DType;
78
use vortex_error::{VortexResult, vortex_bail};
9+
use vortex_vector::Vector;
810

911
use crate::ArrayRef;
1012
use crate::compute::invert;
@@ -66,6 +68,16 @@ impl VTable for Not {
6668
let child_result = expr.child(0).evaluate(scope)?;
6769
invert(&child_result)
6870
}
71+
72+
fn execute(
73+
&self,
74+
expr: &ExpressionView<Self>,
75+
vector: &Vector,
76+
dtype: &DType,
77+
) -> VortexResult<Vector> {
78+
let child = expr.child(0).execute(vector, dtype)?;
79+
Ok(child.into_bool().not().into())
80+
}
6981
}
7082

7183
/// Creates an expression that logically inverts boolean values.

vortex-array/src/expr/exprs/root.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::fmt::Formatter;
55

66
use vortex_dtype::{DType, FieldPath};
77
use vortex_error::{VortexExpect, VortexResult, vortex_bail};
8+
use vortex_vector::Vector;
89

910
use crate::ArrayRef;
1011
use crate::expr::expression::Expression;
@@ -59,6 +60,15 @@ impl VTable for Root {
5960
Ok(scope.clone())
6061
}
6162

63+
fn execute(
64+
&self,
65+
_expr: &ExpressionView<Self>,
66+
vector: &Vector,
67+
_dtype: &DType,
68+
) -> VortexResult<Vector> {
69+
Ok(vector.clone())
70+
}
71+
6272
fn stat_max(
6373
&self,
6474
expr: &ExpressionView<Root>,

0 commit comments

Comments
 (0)