Skip to main content

reifydb_function/is/
some.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Copyright (c) 2025 ReifyDB
3
4use reifydb_core::value::column::data::ColumnData;
5use reifydb_type::value::r#type::Type;
6
7use crate::{
8	ScalarFunction, ScalarFunctionContext,
9	error::{ScalarFunctionError, ScalarFunctionResult},
10};
11
12pub struct IsSome;
13
14impl IsSome {
15	pub fn new() -> Self {
16		Self
17	}
18}
19
20impl ScalarFunction for IsSome {
21	fn scalar(&self, ctx: ScalarFunctionContext) -> ScalarFunctionResult<ColumnData> {
22		let columns = ctx.columns;
23		let row_count = ctx.row_count;
24
25		if columns.len() != 1 {
26			return Err(ScalarFunctionError::ArityMismatch {
27				function: ctx.fragment.clone(),
28				expected: 1,
29				actual: columns.len(),
30			});
31		}
32
33		let column = columns.get(0).unwrap();
34		let data: Vec<bool> = (0..row_count).map(|i| column.data().is_defined(i)).collect();
35
36		Ok(ColumnData::bool(data))
37	}
38
39	fn return_type(&self, _input_types: &[Type]) -> Type {
40		Type::Boolean
41	}
42}