vortex_functions/
builtins.rs1use vortex_array::ArrayRef;
9use vortex_array::IntoArray;
10use vortex_array::scalar_fn::EmptyOptions;
11use vortex_error::VortexResult;
12use vortex_expr::Expression;
13use vortex_expr::ScalarFnExprExt;
14
15use crate::between::Between;
16use crate::between::BetweenOptions;
17use crate::is_null::IsNull;
18use crate::list_contains::ListContains;
19use crate::list_contains::ListContainsOptions;
20use crate::zip::Zip;
21
22pub trait ExprFunctions: Sized {
24 fn zip(&self, if_true: Expression, if_false: Expression) -> VortexResult<Expression>;
26
27 fn list_contains(&self, value: Expression) -> VortexResult<Expression>;
29
30 fn is_null(&self) -> VortexResult<Expression>;
32}
33
34impl ExprFunctions for Expression {
35 fn zip(&self, if_true: Expression, if_false: Expression) -> VortexResult<Expression> {
36 Zip.try_new_expr(EmptyOptions, [if_true, if_false, self.clone()])
37 }
38
39 fn list_contains(&self, value: Expression) -> VortexResult<Expression> {
40 ListContains.try_new_expr(ListContainsOptions::default(), [self.clone(), value])
41 }
42
43 fn is_null(&self) -> VortexResult<Expression> {
44 IsNull.try_new_expr(EmptyOptions, [self.clone()])
45 }
46}
47
48pub trait ArrayFunctions: Sized {
50 fn zip(&self, if_true: ArrayRef, if_false: ArrayRef) -> VortexResult<ArrayRef>;
52
53 fn list_contains(&self, value: ArrayRef) -> VortexResult<ArrayRef>;
55
56 fn is_null(&self) -> VortexResult<ArrayRef>;
58
59 fn between(
61 self,
62 lower: ArrayRef,
63 upper: ArrayRef,
64 options: BetweenOptions,
65 ) -> VortexResult<ArrayRef>;
66}
67
68impl ArrayFunctions for ArrayRef {
69 fn zip(&self, if_true: ArrayRef, if_false: ArrayRef) -> VortexResult<ArrayRef> {
70 Ok(Zip::try_new(if_true, if_false, self.clone())?.into_array())
71 }
72
73 fn list_contains(&self, value: ArrayRef) -> VortexResult<ArrayRef> {
74 Ok(ListContains::try_new(self.clone(), value)?.into_array())
75 }
76
77 fn is_null(&self) -> VortexResult<ArrayRef> {
78 Ok(IsNull::new(self.clone()).into_array())
79 }
80
81 fn between(
82 self,
83 lower: ArrayRef,
84 upper: ArrayRef,
85 options: BetweenOptions,
86 ) -> VortexResult<ArrayRef> {
87 Ok(Between::try_new(self, lower, upper, options)?.into_array())
88 }
89}