use vortex_error::VortexResult;
use vortex_error::vortex_ensure;
use crate::ArrayRef;
use crate::DynArray;
use crate::dtype::DType;
use crate::scalar_fn::ScalarFnRef;
use crate::stats::ArrayStats;
#[derive(Clone, Debug)]
pub struct ScalarFnArray {
pub(super) scalar_fn: ScalarFnRef,
pub(super) dtype: DType,
pub(super) len: usize,
pub(super) children: Vec<ArrayRef>,
pub(super) stats: ArrayStats,
}
impl ScalarFnArray {
pub fn try_new(bound: ScalarFnRef, children: Vec<ArrayRef>, len: usize) -> VortexResult<Self> {
let arg_dtypes: Vec<_> = children.iter().map(|c| c.dtype().clone()).collect();
let dtype = bound.return_dtype(&arg_dtypes)?;
vortex_ensure!(
children.iter().all(|c| c.len() == len),
"ScalarFnArray must have children equal to the array length"
);
Ok(Self {
scalar_fn: bound,
dtype,
len,
children,
stats: Default::default(),
})
}
#[allow(clippy::same_name_method)]
pub fn scalar_fn(&self) -> &ScalarFnRef {
&self.scalar_fn
}
pub fn children(&self) -> &[ArrayRef] {
&self.children
}
}