Skip to main content

reifydb_function/math/scalar/
pi.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::{ScalarFunction, ScalarFunctionContext, error::ScalarFunctionError, propagate_options};
8
9pub struct Pi;
10
11impl Pi {
12	pub fn new() -> Self {
13		Self
14	}
15}
16
17impl ScalarFunction for Pi {
18	fn scalar(&self, ctx: ScalarFunctionContext) -> crate::error::ScalarFunctionResult<ColumnData> {
19		if let Some(result) = propagate_options(self, &ctx) {
20			return result;
21		}
22		if !ctx.columns.is_empty() {
23			return Err(ScalarFunctionError::ArityMismatch {
24				function: ctx.fragment.clone(),
25				expected: 0,
26				actual: ctx.columns.len(),
27			});
28		}
29
30		Ok(ColumnData::float8_with_bitvec(vec![std::f64::consts::PI], vec![true]))
31	}
32
33	fn return_type(&self, _input_types: &[Type]) -> Type {
34		Type::Float8
35	}
36}