Skip to main content

reifydb_routine/function/is/
none.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2025 ReifyDB
3
4use reifydb_core::value::column::{Column, columns::Columns, data::ColumnData};
5use reifydb_type::value::r#type::Type;
6
7use crate::function::{Function, FunctionCapability, FunctionContext, FunctionInfo, error::FunctionError};
8
9pub struct IsNone {
10	info: FunctionInfo,
11}
12
13impl Default for IsNone {
14	fn default() -> Self {
15		Self::new()
16	}
17}
18
19impl IsNone {
20	pub fn new() -> Self {
21		Self {
22			info: FunctionInfo::new("is::none"),
23		}
24	}
25}
26
27impl Function for IsNone {
28	fn info(&self) -> &FunctionInfo {
29		&self.info
30	}
31
32	fn capabilities(&self) -> &[FunctionCapability] {
33		&[FunctionCapability::Scalar]
34	}
35
36	fn return_type(&self, _input_types: &[Type]) -> Type {
37		Type::Boolean
38	}
39
40	fn propagates_options(&self) -> bool {
41		false
42	}
43
44	fn execute(&self, ctx: &FunctionContext, args: &Columns) -> Result<Columns, FunctionError> {
45		if args.len() != 1 {
46			return Err(FunctionError::ArityMismatch {
47				function: ctx.fragment.clone(),
48				expected: 1,
49				actual: args.len(),
50			});
51		}
52
53		let column = &args[0];
54		let row_count = column.data().len();
55		let data: Vec<bool> = (0..row_count).map(|i| !column.data().is_defined(i)).collect();
56
57		Ok(Columns::new(vec![Column::new(ctx.fragment.clone(), ColumnData::bool(data))]))
58	}
59}