datafusion_functions/core/
mod.rs1use datafusion_expr::ScalarUDF;
21use std::sync::Arc;
22
23pub mod arrow_cast;
24pub mod arrowtypeof;
25pub mod coalesce;
26pub mod expr_ext;
27pub mod getfield;
28pub mod greatest;
29mod greatest_least_utils;
30pub mod least;
31pub mod named_struct;
32pub mod nullif;
33pub mod nvl;
34pub mod nvl2;
35pub mod planner;
36pub mod r#struct;
37pub mod union_extract;
38pub mod version;
39
40make_udf_function!(arrow_cast::ArrowCastFunc, arrow_cast);
42make_udf_function!(nullif::NullIfFunc, nullif);
43make_udf_function!(nvl::NVLFunc, nvl);
44make_udf_function!(nvl2::NVL2Func, nvl2);
45make_udf_function!(arrowtypeof::ArrowTypeOfFunc, arrow_typeof);
46make_udf_function!(r#struct::StructFunc, r#struct);
47make_udf_function!(named_struct::NamedStructFunc, named_struct);
48make_udf_function!(getfield::GetFieldFunc, get_field);
49make_udf_function!(coalesce::CoalesceFunc, coalesce);
50make_udf_function!(greatest::GreatestFunc, greatest);
51make_udf_function!(least::LeastFunc, least);
52make_udf_function!(union_extract::UnionExtractFun, union_extract);
53make_udf_function!(version::VersionFunc, version);
54
55pub mod expr_fn {
56 use datafusion_expr::{Expr, Literal};
57
58 export_functions!((
59 nullif,
60 "Returns NULL if value1 equals value2; otherwise it returns value1. This can be used to perform the inverse operation of the COALESCE expression",
61 arg1 arg2
62 ),(
63 arrow_cast,
64 "Returns value2 if value1 is NULL; otherwise it returns value1",
65 arg1 arg2
66 ),(
67 nvl,
68 "Returns value2 if value1 is NULL; otherwise it returns value1",
69 arg1 arg2
70 ),(
71 nvl2,
72 "Returns value2 if value1 is not NULL; otherwise, it returns value3.",
73 arg1 arg2 arg3
74 ),(
75 arrow_typeof,
76 "Returns the Arrow type of the input expression.",
77 arg1
78 ),(
79 r#struct,
80 "Returns a struct with the given arguments",
81 args,
82 ),(
83 named_struct,
84 "Returns a struct with the given names and arguments pairs",
85 args,
86 ),(
87 coalesce,
88 "Returns `coalesce(args...)`, which evaluates to the value of the first expr which is not NULL",
89 args,
90 ),(
91 greatest,
92 "Returns `greatest(args...)`, which evaluates to the greatest value in the list of expressions or NULL if all the expressions are NULL",
93 args,
94 ),(
95 least,
96 "Returns `least(args...)`, which evaluates to the smallest value in the list of expressions or NULL if all the expressions are NULL",
97 args,
98 ));
99
100 #[doc = "Returns the value of the field with the given name from the struct"]
101 pub fn get_field(arg1: Expr, arg2: impl Literal) -> Expr {
102 super::get_field().call(vec![arg1, arg2.lit()])
103 }
104
105 #[doc = "Returns the value of the field with the given name from the union when it's selected, or NULL otherwise"]
106 pub fn union_extract(arg1: Expr, arg2: impl Literal) -> Expr {
107 super::union_extract().call(vec![arg1, arg2.lit()])
108 }
109}
110
111pub fn functions() -> Vec<Arc<ScalarUDF>> {
113 vec![
114 nullif(),
115 arrow_cast(),
116 nvl(),
117 nvl2(),
118 arrow_typeof(),
119 named_struct(),
120 get_field(),
128 coalesce(),
129 greatest(),
130 least(),
131 union_extract(),
132 version(),
133 r#struct(),
134 ]
135}