vortex_array/scalar_fn/fns/
root.rs1use std::fmt::Formatter;
5
6use vortex_error::VortexResult;
7use vortex_error::vortex_bail;
8use vortex_session::VortexSession;
9
10use crate::ArrayRef;
11use crate::ExecutionCtx;
12use crate::dtype::DType;
13use crate::dtype::FieldPath;
14use crate::expr::StatsCatalog;
15use crate::expr::expression::Expression;
16use crate::expr::stats::Stat;
17use crate::scalar_fn::Arity;
18use crate::scalar_fn::ChildName;
19use crate::scalar_fn::EmptyOptions;
20use crate::scalar_fn::ExecutionArgs;
21use crate::scalar_fn::ScalarFnId;
22use crate::scalar_fn::ScalarFnVTable;
23
24#[derive(Clone)]
27pub struct Root;
28
29impl ScalarFnVTable for Root {
30 type Options = EmptyOptions;
31
32 fn id(&self) -> ScalarFnId {
33 ScalarFnId::from("vortex.root")
34 }
35
36 fn serialize(&self, _instance: &Self::Options) -> VortexResult<Option<Vec<u8>>> {
37 Ok(Some(vec![]))
38 }
39
40 fn deserialize(
41 &self,
42 _metadata: &[u8],
43 _session: &VortexSession,
44 ) -> VortexResult<Self::Options> {
45 Ok(EmptyOptions)
46 }
47
48 fn arity(&self, _options: &Self::Options) -> Arity {
49 Arity::Exact(0)
50 }
51
52 fn child_name(&self, _instance: &Self::Options, child_idx: usize) -> ChildName {
53 unreachable!(
54 "Root expression does not have children, got index {}",
55 child_idx
56 )
57 }
58
59 fn fmt_sql(
60 &self,
61 _options: &Self::Options,
62 _expr: &Expression,
63 f: &mut Formatter<'_>,
64 ) -> std::fmt::Result {
65 write!(f, "$")
66 }
67
68 fn return_dtype(&self, _options: &Self::Options, _arg_dtypes: &[DType]) -> VortexResult<DType> {
69 vortex_bail!("Root expression does not support return_dtype")
70 }
71
72 fn execute(
73 &self,
74 _data: &Self::Options,
75 _args: &dyn ExecutionArgs,
76 _ctx: &mut ExecutionCtx,
77 ) -> VortexResult<ArrayRef> {
78 vortex_bail!("Root expression is not executable")
79 }
80
81 fn stat_expression(
82 &self,
83 _options: &Self::Options,
84 _expr: &Expression,
85 stat: Stat,
86 catalog: &dyn StatsCatalog,
87 ) -> Option<Expression> {
88 catalog.stats_ref(&FieldPath::root(), stat)
89 }
90
91 fn is_null_sensitive(&self, _options: &Self::Options) -> bool {
92 false
93 }
94
95 fn is_fallible(&self, _options: &Self::Options) -> bool {
96 false
97 }
98}