vortex_array/scalar_fns/is_null/
mod.rs1use std::ops::Not;
5
6use vortex_dtype::DType;
7use vortex_dtype::Nullability::NonNullable;
8use vortex_error::VortexResult;
9use vortex_mask::Mask;
10use vortex_vector::Datum;
11use vortex_vector::ScalarOps;
12use vortex_vector::Vector;
13use vortex_vector::VectorOps;
14use vortex_vector::bool::BoolVector;
15
16use crate::expr::ChildName;
17use crate::expr::ExprId;
18use crate::expr::functions::ArgName;
19use crate::expr::functions::Arity;
20use crate::expr::functions::EmptyOptions;
21use crate::expr::functions::ExecutionArgs;
22use crate::expr::functions::VTable;
23
24pub struct IsNullFn;
25impl VTable for IsNullFn {
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::Exact(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(match args.input_datums(0) {
49 Datum::Scalar(sc) => Datum::Scalar(sc.is_invalid().into()),
50 Datum::Vector(vec) => Vector::Bool(BoolVector::new(
51 vec.validity().to_bit_buffer().not(),
52 Mask::AllTrue(vec.len()),
53 ))
54 .into(),
55 })
56 }
57}