Skip to main content

vortex_expr/
scalar_fn_ext.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use vortex_array::scalar_fn::ScalarFnVTable;
5use vortex_array::scalar_fn::ScalarFnVTableExt;
6use vortex_error::VortexExpect;
7use vortex_error::VortexResult;
8
9use crate::BoundExpression;
10use crate::Expression;
11
12/// Expression constructors for scalar function vtables.
13pub trait ScalarFnExprExt: ScalarFnVTable {
14    /// Create a new expression with this vtable and the given options and children.
15    fn new_expr(
16        &self,
17        options: Self::Options,
18        children: impl IntoIterator<Item = Expression>,
19    ) -> Expression {
20        Self::try_new_expr(self, options, children).vortex_expect("Failed to create expression")
21    }
22
23    /// Try to create a new expression with this vtable and the given options and children.
24    fn try_new_expr(
25        &self,
26        options: Self::Options,
27        children: impl IntoIterator<Item = Expression>,
28    ) -> VortexResult<Expression> {
29        Expression::try_new(self.bind(options), children)
30    }
31
32    /// Try to create a bound expression with this vtable, the given options, and bound children.
33    fn try_new_bound_expr(
34        &self,
35        options: Self::Options,
36        children: impl IntoIterator<Item = BoundExpression>,
37    ) -> VortexResult<BoundExpression> {
38        BoundExpression::try_new(self.bind(options), children)
39    }
40}
41impl<V: ScalarFnVTable> ScalarFnExprExt for V {}