Skip to content

Commit 64781ba

Browse files
committed
Clarify docs in session accessors
Signed-off-by: Nicholas Gates <[email protected]>
1 parent ece11dd commit 64781ba

File tree

5 files changed

+86
-5
lines changed

5 files changed

+86
-5
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44
mod array;
55
pub use array::StructArray;
6-
76
mod compute;
7+
mod rules;
88

99
mod vtable;
10+
pub use rules::*;
1011
pub use vtable::StructVTable;
1112

1213
#[cfg(test)]
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
use vortex_error::VortexResult;
5+
6+
use crate::arrays::ConstantArray;
7+
use crate::arrays::ExactScalarFn;
8+
use crate::arrays::ScalarFnArrayExt;
9+
use crate::arrays::ScalarFnArrayView;
10+
use crate::arrays::StructArray;
11+
use crate::arrays::StructVTable;
12+
use crate::expr::EmptyOptions;
13+
use crate::expr::GetItem;
14+
use crate::expr::Mask;
15+
use crate::optimizer::rules::ArrayParentReduceRule;
16+
use crate::optimizer::rules::Exact;
17+
use crate::validity::Validity;
18+
use crate::vtable::ValidityHelper;
19+
use crate::Array;
20+
use crate::ArrayRef;
21+
use crate::IntoArray;
22+
23+
#[derive(Debug)]
24+
pub struct StructGetItemRule;
25+
impl ArrayParentReduceRule<Exact<StructVTable>, ExactScalarFn<GetItem>> for StructGetItemRule {
26+
fn child(&self) -> Exact<StructVTable> {
27+
Exact::from(&StructVTable)
28+
}
29+
30+
fn parent(&self) -> ExactScalarFn<GetItem> {
31+
ExactScalarFn::from(&GetItem)
32+
}
33+
34+
fn reduce_parent(
35+
&self,
36+
child: &StructArray,
37+
parent: ScalarFnArrayView<'_, GetItem>,
38+
_child_idx: usize,
39+
) -> VortexResult<Option<ArrayRef>> {
40+
let field_name = parent.options;
41+
let Some(field) = child.field_by_name_opt(field_name) else {
42+
return Ok(None);
43+
};
44+
45+
match child.validity() {
46+
Validity::NonNullable | Validity::AllValid => {
47+
// If the struct is non-nullable or all valid, the field's validity is unchanged
48+
Ok(Some(field.clone()))
49+
}
50+
Validity::AllInvalid => {
51+
// If everything is invalid, the field is also all invalid
52+
Ok(Some(
53+
ConstantArray::new(
54+
vortex_scalar::Scalar::null(field.dtype().clone()),
55+
field.len(),
56+
)
57+
.into_array(),
58+
))
59+
}
60+
Validity::Array(mask) => {
61+
// If the validity is an array, we need to combine it with the field's validity
62+
Mask.try_new_array(field.len(), EmptyOptions, [field.clone(), mask.clone()])
63+
.map(Some)
64+
}
65+
}
66+
}
67+
}

vortex-array/src/executor.rs

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

4-
use vortex_error::VortexResult;
54
use vortex_error::vortex_ensure;
5+
use vortex_error::VortexResult;
66
use vortex_session::VortexSession;
77
use vortex_vector::Datum;
88
use vortex_vector::Vector;
99
use vortex_vector::VectorOps;
1010

11-
use crate::Array;
12-
use crate::ArrayRef;
1311
use crate::arrays::ConstantVTable;
1412
use crate::kernel::BindCtx;
1513
use crate::session::ArraySessionExt;
14+
use crate::Array;
15+
use crate::ArrayRef;
1616

1717
/// Executor for exporting a Vortex [`Vector`] or [`Datum`] from an [`ArrayRef`].
1818
pub trait VectorExecutor {
@@ -36,6 +36,8 @@ impl VectorExecutor for ArrayRef {
3636
}
3737

3838
fn execute_datum(&self, session: &VortexSession) -> VortexResult<Datum> {
39+
log::error!("Executing array: {}", self.display_tree());
40+
3941
// Attempt to short-circuit constant arrays.
4042
if let Some(constant) = self.as_opt::<ConstantVTable>() {
4143
return Ok(Datum::Scalar(constant.scalar().to_vector_scalar()));

vortex-array/src/expr/vtable.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,15 @@ impl<V: VTable> DynExprVTable for VTableAdapter<V> {
433433
{
434434
use vortex_error::vortex_ensure;
435435
use vortex_vector::datum_matches_dtype;
436+
437+
if !datum_matches_dtype(&result, &expected_dtype) {
438+
vortex_bail!(
439+
"Expression execution returned datum of invalid dtype. Expected {}, got {:?}",
440+
expected_dtype,
441+
result
442+
);
443+
}
444+
436445
vortex_ensure!(
437446
datum_matches_dtype(&result, &expected_dtype),
438447
"Expression execution invalid for dtype {}",

vortex-array/src/session/mod.rs

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

4+
use vortex_session::registry::Registry;
45
use vortex_session::Ref;
56
use vortex_session::SessionExt;
6-
use vortex_session::registry::Registry;
77

88
use crate::arrays::BoolMaskedValidityRule;
99
use crate::arrays::BoolVTable;
@@ -19,6 +19,7 @@ use crate::arrays::MaskedVTable;
1919
use crate::arrays::NullVTable;
2020
use crate::arrays::PrimitiveMaskedValidityRule;
2121
use crate::arrays::PrimitiveVTable;
22+
use crate::arrays::StructGetItemRule;
2223
use crate::arrays::StructVTable;
2324
use crate::arrays::VarBinVTable;
2425
use crate::arrays::VarBinViewVTable;
@@ -96,6 +97,7 @@ impl Default for ArraySession {
9697
optimizer.register_parent_rule(BoolMaskedValidityRule);
9798
optimizer.register_parent_rule(PrimitiveMaskedValidityRule);
9899
optimizer.register_parent_rule(DecimalMaskedValidityRule);
100+
optimizer.register_parent_rule(StructGetItemRule);
99101

100102
session
101103
}

0 commit comments

Comments
 (0)