Skip to content

Commit 7c123f7

Browse files
committed
not
Signed-off-by: Joe Isaacs <[email protected]>
1 parent a82a7ea commit 7c123f7

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ use crate::expr::ExecutionArgs;
1717
use crate::expr::ExprId;
1818
use crate::expr::Expression;
1919
use crate::expr::ExpressionView;
20+
use crate::expr::ScalarFnExprExt;
2021
use crate::expr::VTable;
2122
use crate::expr::VTableExt;
23+
use crate::expr::functions::EmptyOptions;
24+
use crate::scalar_fns::not;
2225

2326
/// Expression that logically inverts boolean values.
2427
pub struct Not;
@@ -89,6 +92,10 @@ impl VTable for Not {
8992
fn is_fallible(&self, _instance: &Self::Instance) -> bool {
9093
false
9194
}
95+
96+
fn expr_v2(&self, view: &ExpressionView<Self>) -> VortexResult<Expression> {
97+
ScalarFnExprExt::try_new_expr(&not::NotFn, EmptyOptions, view.children().clone())
98+
}
9299
}
93100

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

vortex-array/src/scalar_fns/mod.rs

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

2121
pub mod cast;
2222
pub mod is_null;
23+
pub mod not;
2324

2425
/// A collection of built-in scalar functions that can be applied to expressions or arrays.
2526
pub trait BuiltinScalarFns: Sized {
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
use vortex_compute::logical::LogicalNot;
5+
use vortex_dtype::DType;
6+
use vortex_error::VortexResult;
7+
use vortex_error::vortex_bail;
8+
use vortex_vector::Datum;
9+
use vortex_vector::Scalar;
10+
use vortex_vector::Vector;
11+
use vortex_vector::bool::BoolScalar;
12+
13+
use crate::expr::ChildName;
14+
use crate::expr::functions::ArgName;
15+
use crate::expr::functions::Arity;
16+
use crate::expr::functions::EmptyOptions;
17+
use crate::expr::functions::ExecutionArgs;
18+
use crate::expr::functions::FunctionId;
19+
use crate::expr::functions::NullHandling;
20+
use crate::expr::functions::VTable;
21+
22+
pub struct NotFn;
23+
impl VTable for NotFn {
24+
type Options = EmptyOptions;
25+
26+
fn id(&self) -> FunctionId {
27+
FunctionId::from("vortex.not")
28+
}
29+
30+
fn arity(&self, _: &Self::Options) -> Arity {
31+
Arity::Fixed(1)
32+
}
33+
34+
fn null_handling(&self, _options: &Self::Options) -> NullHandling {
35+
NullHandling::Propagate
36+
}
37+
38+
fn arg_name(&self, _: &Self::Options, arg_idx: usize) -> ArgName {
39+
match arg_idx {
40+
0 => ChildName::from("input"),
41+
_ => unreachable!("Invalid child index {} for Not expression", arg_idx),
42+
}
43+
}
44+
45+
fn return_dtype(&self, _options: &Self::Options, arg_types: &[DType]) -> VortexResult<DType> {
46+
let child_dtype = &arg_types[0];
47+
if !matches!(child_dtype, DType::Bool(_)) {
48+
vortex_bail!(
49+
"Not expression expects a boolean child, got: {}",
50+
child_dtype
51+
);
52+
}
53+
Ok(child_dtype.clone())
54+
}
55+
56+
fn execute(&self, _: &Self::Options, args: &ExecutionArgs) -> VortexResult<Datum> {
57+
Ok(match args.input_datums(0) {
58+
Datum::Scalar(Scalar::Bool(sc)) => {
59+
Datum::Scalar(BoolScalar::new(sc.value().map(|v| !v)).into())
60+
}
61+
Datum::Vector(Vector::Bool(vec)) => Datum::Vector(vec.clone().not().into()),
62+
_ => unreachable!("Not expects a boolean"),
63+
})
64+
}
65+
}

0 commit comments

Comments
 (0)