Skip to content

Commit 79580a7

Browse files
committed
is-null
Signed-off-by: Joe Isaacs <[email protected]>
1 parent 89b236b commit 79580a7

File tree

6 files changed

+100
-10
lines changed

6 files changed

+100
-10
lines changed

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,32 @@ use std::ops::Not;
66

77
use vortex_dtype::DType;
88
use vortex_dtype::Nullability;
9+
use vortex_error::vortex_bail;
910
use vortex_error::VortexExpect;
1011
use vortex_error::VortexResult;
11-
use vortex_error::vortex_bail;
1212
use vortex_mask::Mask;
13+
use vortex_vector::bool::BoolVector;
1314
use vortex_vector::Vector;
1415
use vortex_vector::VectorOps;
15-
use vortex_vector::bool::BoolVector;
1616

17-
use crate::Array;
18-
use crate::ArrayRef;
19-
use crate::IntoArray;
2017
use crate::arrays::BoolArray;
2118
use crate::arrays::ConstantArray;
22-
use crate::expr::ChildName;
19+
use crate::expr::exprs::binary::eq;
20+
use crate::expr::exprs::literal::lit;
21+
use crate::expr::functions::EmptyOptions;
22+
use crate::expr::stats::Stat;
2323
use crate::expr::ExecutionArgs;
2424
use crate::expr::ExprId;
2525
use crate::expr::Expression;
2626
use crate::expr::ExpressionView;
2727
use crate::expr::StatsCatalog;
2828
use crate::expr::VTable;
2929
use crate::expr::VTableExt;
30-
use crate::expr::exprs::binary::eq;
31-
use crate::expr::exprs::literal::lit;
32-
use crate::expr::stats::Stat;
30+
use crate::expr::{ChildName, ScalarFnExprExt};
31+
use crate::scalar_fns::is_null;
32+
use crate::Array;
33+
use crate::ArrayRef;
34+
use crate::IntoArray;
3335

3436
/// Expression that checks for null values.
3537
pub struct IsNull;
@@ -110,6 +112,10 @@ impl VTable for IsNull {
110112
fn is_fallible(&self, _instance: &Self::Instance) -> bool {
111113
false
112114
}
115+
116+
fn expr_v2(&self, view: &ExpressionView<Self>) -> VortexResult<Expression> {
117+
ScalarFnExprExt::try_new_expr(&is_null::IsNull, EmptyOptions, view.children().clone())
118+
}
113119
}
114120

115121
/// Creates an expression that checks for null values.
@@ -138,7 +144,6 @@ mod tests {
138144
use vortex_utils::aliases::hash_set::HashSet;
139145

140146
use super::is_null;
141-
use crate::IntoArray;
142147
use crate::arrays::PrimitiveArray;
143148
use crate::arrays::StructArray;
144149
use crate::expr::exprs::binary::eq;
@@ -149,6 +154,7 @@ mod tests {
149154
use crate::expr::pruning::checked_pruning_expr;
150155
use crate::expr::stats::Stat;
151156
use crate::expr::test_harness;
157+
use crate::IntoArray;
152158

153159
#[test]
154160
fn dtype() {

vortex-array/src/expr/vtable.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::fmt::Display;
88
use std::fmt::Formatter;
99
use std::hash::Hash;
1010
use std::hash::Hasher;
11+
use std::ops::Deref;
1112
use std::sync::Arc;
1213

1314
use arcref::ArcRef;
@@ -152,6 +153,12 @@ pub trait VTable: 'static + Sized + Send + Sync {
152153
_ = instance;
153154
true
154155
}
156+
157+
/// **For internal usage**. This will return an Expression that is part of the
158+
/// expression -> new_expression migration.
159+
fn expr_v2(&self, expr: &ExpressionView<Self>) -> VortexResult<Expression> {
160+
Ok(expr.deref().clone())
161+
}
155162
}
156163

157164
/// Arguments for expression execution.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
use vortex_dtype::DType;
5+
use vortex_dtype::Nullability::NonNullable;
6+
use vortex_error::VortexResult;
7+
use vortex_mask::Mask;
8+
use vortex_vector::Datum;
9+
use vortex_vector::Scalar;
10+
use vortex_vector::ScalarOps;
11+
use vortex_vector::Vector;
12+
use vortex_vector::VectorOps;
13+
use vortex_vector::bool::BoolScalar;
14+
use vortex_vector::bool::BoolVector;
15+
16+
use crate::expr::ChildName;
17+
use crate::expr::ExprId;
18+
use crate::expr::functions::ArgName;
19+
use crate::expr::functions::Arity;
20+
use crate::expr::functions::EmptyOptions;
21+
use crate::expr::functions::ExecutionArgs;
22+
use crate::expr::functions::VTable;
23+
24+
pub struct IsNull;
25+
impl VTable for IsNull {
26+
type Options = EmptyOptions;
27+
28+
fn id(&self) -> ExprId {
29+
ExprId::new_ref("is_null")
30+
}
31+
32+
fn arity(&self, _: &Self::Options) -> Arity {
33+
Arity::Fixed(1)
34+
}
35+
36+
fn arg_name(&self, _: &Self::Options, arg_idx: usize) -> ArgName {
37+
match arg_idx {
38+
0 => ChildName::from("input"),
39+
_ => unreachable!("Invalid child index {} for IsNull expression", arg_idx),
40+
}
41+
}
42+
43+
fn return_dtype(&self, _options: &Self::Options, _arg_types: &[DType]) -> VortexResult<DType> {
44+
Ok(DType::Bool(NonNullable))
45+
}
46+
47+
fn execute(&self, _: &Self::Options, args: &ExecutionArgs) -> VortexResult<Datum> {
48+
Ok(args.input_datums(0).as_ref().map2(
49+
|sc| sc.is_invalid().into(),
50+
|arr| {
51+
Vector::Bool(BoolVector::new(
52+
arr.validity().to_bit_buffer(),
53+
Mask::AllTrue(arr.len()),
54+
))
55+
},
56+
))
57+
}
58+
}

vortex-array/src/scalar_fns/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::expr::Expression;
1919
use crate::expr::ScalarFnExprExt;
2020

2121
pub mod cast;
22+
pub mod is_null;
2223

2324
/// A collection of built-in scalar functions that can be applied to expressions or arrays.
2425
pub trait BuiltinScalarFns: Sized {

vortex-vector/src/bool/scalar.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,9 @@ impl From<BoolScalar> for Scalar {
4343
Scalar::Bool(val)
4444
}
4545
}
46+
47+
impl From<bool> for Scalar {
48+
fn from(value: bool) -> Self {
49+
BoolScalar::new(Some(value)).into()
50+
}
51+
}

vortex-vector/src/datum.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ impl Datum {
8181
Datum::Vector(vector) => Some(vector),
8282
}
8383
}
84+
85+
/// Maps over the scalar or vector value, applying the appropriate function based on the variant.
86+
pub fn map2(
87+
self,
88+
sc_fn: impl FnOnce(Scalar) -> Scalar,
89+
arr_fn: impl FnOnce(Vector) -> Vector,
90+
) -> Datum {
91+
match self {
92+
Datum::Scalar(scalar) => Datum::Scalar(sc_fn(scalar)),
93+
Datum::Vector(vector) => Datum::Vector(arr_fn(vector)),
94+
}
95+
}
8496
}
8597

8698
impl Datum {

0 commit comments

Comments
 (0)