datafusion_functions/unicode/
mod.rs1use std::sync::Arc;
21
22use datafusion_expr::ScalarUDF;
23
24pub mod character_length;
25pub mod common;
26pub mod find_in_set;
27pub mod initcap;
28pub mod left;
29pub mod lpad;
30pub mod planner;
31pub mod reverse;
32pub mod right;
33pub mod rpad;
34pub mod strpos;
35pub mod substr;
36pub mod substrindex;
37pub mod translate;
38
39make_udf_function!(character_length::CharacterLengthFunc, character_length);
41make_udf_function!(find_in_set::FindInSetFunc, find_in_set);
42make_udf_function!(initcap::InitcapFunc, initcap);
43make_udf_function!(left::LeftFunc, left);
44make_udf_function!(lpad::LPadFunc, lpad);
45make_udf_function!(right::RightFunc, right);
46make_udf_function!(reverse::ReverseFunc, reverse);
47make_udf_function!(rpad::RPadFunc, rpad);
48make_udf_function!(strpos::StrposFunc, strpos);
49make_udf_function!(substr::SubstrFunc, substr);
50make_udf_function!(substr::SubstrFunc, substring);
51make_udf_function!(substrindex::SubstrIndexFunc, substr_index);
52make_udf_function!(translate::TranslateFunc, translate);
53
54pub mod expr_fn {
55 use datafusion_expr::Expr;
56
57 export_functions!((
58 character_length,
59 "the number of characters in the `string`",
60 string
61 ),(
62 lpad,
63 "fill up a string to the length by prepending the characters",
64 args,
65 ),(
66 rpad,
67 "fill up a string to the length by appending the characters",
68 args,
69 ),(
70 reverse,
71 "reverses the `string`",
72 string
73 ),(
74 substr,
75 "substring from the `position` to the end",
76 string position
77 ),(
78 substr_index,
79 "Returns the substring from str before count occurrences of the delimiter",
80 string delimiter count
81 ),(
82 strpos,
83 "finds the position from where the `substring` matches the `string`",
84 string substring
85 ),(
86 substring,
87 "substring from the `position` with `length` characters",
88 string position length
89 ),(
90 translate,
91 "replaces the characters in `from` with the counterpart in `to`",
92 string from to
93 ),(
94 right,
95 "returns the last `n` characters in the `string`",
96 string n
97 ),(
98 left,
99 "returns the first `n` characters in the `string`",
100 string n
101 ),(
102 initcap,
103 "converts the first letter of each word in `string` in uppercase and the remaining characters in lowercase",
104 string
105 ),(
106 find_in_set,
107 "Returns a value in the range of 1 to N if the string `str` is in the string list `strlist` consisting of N substrings",
108 string strlist
109 ));
110
111 #[doc = "the number of characters in the `string`"]
112 pub fn char_length(string: Expr) -> Expr {
113 character_length(string)
114 }
115
116 #[doc = "finds the position from where the `substring` matches the `string`"]
117 pub fn instr(string: Expr, substring: Expr) -> Expr {
118 strpos(string, substring)
119 }
120
121 #[doc = "the number of characters in the `string`"]
122 pub fn length(string: Expr) -> Expr {
123 character_length(string)
124 }
125
126 #[doc = "finds the position from where the `substring` matches the `string`"]
127 pub fn position(string: Expr, substring: Expr) -> Expr {
128 strpos(string, substring)
129 }
130}
131
132pub fn functions() -> Vec<Arc<ScalarUDF>> {
134 vec![
135 character_length(),
136 find_in_set(),
137 initcap(),
138 left(),
139 lpad(),
140 reverse(),
141 right(),
142 rpad(),
143 strpos(),
144 substr(),
145 substr_index(),
146 translate(),
147 ]
148}