datafusion_functions/string/
mod.rs1use std::sync::Arc;
21
22use datafusion_expr::ScalarUDF;
23
24pub mod ascii;
25pub mod bit_length;
26pub mod btrim;
27pub mod chr;
28pub mod common;
29pub mod concat;
30pub mod concat_ws;
31pub mod contains;
32pub mod ends_with;
33pub mod levenshtein;
34pub mod lower;
35pub mod ltrim;
36pub mod octet_length;
37pub mod overlay;
38pub mod repeat;
39pub mod replace;
40pub mod rtrim;
41pub mod split_part;
42pub mod starts_with;
43pub mod to_hex;
44pub mod upper;
45pub mod uuid;
46make_udf_function!(ascii::AsciiFunc, ascii);
48make_udf_function!(bit_length::BitLengthFunc, bit_length);
49make_udf_function!(btrim::BTrimFunc, btrim);
50make_udf_function!(chr::ChrFunc, chr);
51make_udf_function!(concat::ConcatFunc, concat);
52make_udf_function!(concat_ws::ConcatWsFunc, concat_ws);
53make_udf_function!(ends_with::EndsWithFunc, ends_with);
54make_udf_function!(levenshtein::LevenshteinFunc, levenshtein);
55make_udf_function!(ltrim::LtrimFunc, ltrim);
56make_udf_function!(lower::LowerFunc, lower);
57make_udf_function!(octet_length::OctetLengthFunc, octet_length);
58make_udf_function!(overlay::OverlayFunc, overlay);
59make_udf_function!(repeat::RepeatFunc, repeat);
60make_udf_function!(replace::ReplaceFunc, replace);
61make_udf_function!(rtrim::RtrimFunc, rtrim);
62make_udf_function!(starts_with::StartsWithFunc, starts_with);
63make_udf_function!(split_part::SplitPartFunc, split_part);
64make_udf_function!(to_hex::ToHexFunc, to_hex);
65make_udf_function!(upper::UpperFunc, upper);
66make_udf_function!(uuid::UuidFunc, uuid);
67make_udf_function!(contains::ContainsFunc, contains);
68pub mod expr_fn {
69 use datafusion_expr::Expr;
70
71 export_functions!((
72 ascii,
73 "Returns the numeric code of the first character of the argument.",
74 arg1
75 ),(
76 bit_length,
77 "Returns the number of bits in the `string`",
78 arg1
79 ),(
80 btrim,
81 "Removes all characters, spaces by default, from both sides of a string",
82 args,
83 ),(
84 chr,
85 "Converts the Unicode code point to a UTF8 character",
86 arg1
87 ),(
88 concat,
89 "Concatenates the text representations of all the arguments. NULL arguments are ignored",
90 args,
91 ),(
92 ends_with,
93 "Returns true if the `string` ends with the `suffix`, false otherwise.",
94 string suffix
95 ),(
96 levenshtein,
97 "Returns the Levenshtein distance between the two given strings",
98 arg1 arg2
99 ),(
100 lower,
101 "Converts a string to lowercase.",
102 arg1
103 ),(
104 ltrim,
105 "Removes all characters, spaces by default, from the beginning of a string",
106 args,
107 ),(
108 octet_length,
109 "returns the number of bytes of a string",
110 args
111 ),(
112 overlay,
113 "replace the substring of string that starts at the start'th character and extends for count characters with new substring",
114 args,
115 ),(
116 repeat,
117 "Repeats the `string` to `n` times",
118 string n
119 ),(
120 replace,
121 "Replaces all occurrences of `from` with `to` in the `string`",
122 string from to
123 ),(
124 rtrim,
125 "Removes all characters, spaces by default, from the end of a string",
126 args,
127 ),(
128 split_part,
129 "Splits a string based on a delimiter and picks out the desired field based on the index.",
130 string delimiter index
131 ),(
132 starts_with,
133 "Returns true if string starts with prefix.",
134 arg1 arg2
135 ),(
136 to_hex,
137 "Converts an integer to a hexadecimal string.",
138 arg1
139 ),(
140 upper,
141 "Converts a string to uppercase.",
142 arg1
143 ),(
144 uuid,
145 "returns uuid v4 as a string value",
146 ), (
147 contains,
148 "Return true if search_string is found within string.",
149 ));
150
151 #[doc = "Removes all characters, spaces by default, from both sides of a string"]
152 pub fn trim(args: Vec<Expr>) -> Expr {
153 super::btrim().call(args)
154 }
155
156 #[doc = "Concatenates all but the first argument, with separators. The first argument is used as the separator string, and should not be NULL. Other NULL arguments are ignored."]
157 pub fn concat_ws(delimiter: Expr, args: Vec<Expr>) -> Expr {
158 let mut args = args;
159 args.insert(0, delimiter);
160 super::concat_ws().call(args)
161 }
162}
163
164pub fn functions() -> Vec<Arc<ScalarUDF>> {
166 vec![
167 ascii(),
168 bit_length(),
169 btrim(),
170 chr(),
171 concat(),
172 concat_ws(),
173 ends_with(),
174 levenshtein(),
175 lower(),
176 ltrim(),
177 octet_length(),
178 repeat(),
179 replace(),
180 rtrim(),
181 split_part(),
182 starts_with(),
183 to_hex(),
184 upper(),
185 uuid(),
186 contains(),
187 ]
188}