datafusion_spark/function/string/
mod.rs1pub mod ascii;
19pub mod base64;
20pub mod char;
21pub mod concat;
22pub mod concat_ws;
23pub mod elt;
24pub mod format_string;
25pub mod ilike;
26pub mod is_valid_utf8;
27pub mod length;
28pub mod like;
29pub mod luhn_check;
30pub mod make_valid_utf8;
31pub mod quote;
32pub mod soundex;
33pub mod space;
34pub mod substring;
35
36use datafusion_expr::ScalarUDF;
37use datafusion_functions::make_udf_function;
38use std::sync::Arc;
39
40make_udf_function!(ascii::SparkAscii, ascii);
41make_udf_function!(base64::SparkBase64, base64);
42make_udf_function!(char::CharFunc, char);
43make_udf_function!(concat::SparkConcat, concat);
44make_udf_function!(concat_ws::SparkConcatWs, concat_ws);
45make_udf_function!(ilike::SparkILike, ilike);
46make_udf_function!(length::SparkLengthFunc, length);
47make_udf_function!(elt::SparkElt, elt);
48make_udf_function!(like::SparkLike, like);
49make_udf_function!(luhn_check::SparkLuhnCheck, luhn_check);
50make_udf_function!(format_string::FormatStringFunc, format_string);
51make_udf_function!(space::SparkSpace, space);
52make_udf_function!(substring::SparkSubstring, substring);
53make_udf_function!(base64::SparkUnBase64, unbase64);
54make_udf_function!(soundex::SparkSoundex, soundex);
55make_udf_function!(make_valid_utf8::SparkMakeValidUtf8, make_valid_utf8);
56make_udf_function!(is_valid_utf8::SparkIsValidUtf8, is_valid_utf8);
57make_udf_function!(quote::SparkQuote, quote);
58
59pub mod expr_fn {
60 use datafusion_functions::export_functions;
61
62 export_functions!((
63 ascii,
64 "Returns the ASCII code point of the first character of string.",
65 arg1
66 ));
67 export_functions!((
68 base64,
69 "Encodes the input binary `bin` into a base64 string.",
70 bin
71 ));
72 export_functions!((
73 char,
74 "Returns the ASCII character having the binary equivalent to col. If col is larger than 256 the result is equivalent to char(col % 256).",
75 arg1
76 ));
77 export_functions!((
78 concat,
79 "Concatenates multiple input strings into a single string. Returns NULL if any input is NULL.",
80 args
81 ));
82 export_functions!((
83 concat_ws,
84 "Concatenates strings with separator. Supports arrays. Null values are skipped.",
85 sep args
86 ));
87 export_functions!((
88 elt,
89 "Returns the n-th input (1-indexed), e.g. returns 2nd input when n is 2. The function returns NULL if the index is 0 or exceeds the length of the array.",
90 select_col arg1 arg2 argn
91 ));
92 export_functions!((
93 ilike,
94 "Returns true if str matches pattern (case insensitive).",
95 str pattern
96 ));
97 export_functions!((
98 length,
99 "Returns the character length of string data or number of bytes of binary data. The length of string data includes the trailing spaces. The length of binary data includes binary zeros.",
100 arg1
101 ));
102 export_functions!((
103 like,
104 "Returns true if str matches pattern (case sensitive).",
105 str pattern
106 ));
107 export_functions!((
108 luhn_check,
109 "Returns whether the input string of digits is valid according to the Luhn algorithm.",
110 arg1
111 ));
112 export_functions!((
113 format_string,
114 "Returns a formatted string from printf-style format strings.",
115 strfmt args
116 ));
117 export_functions!((space, "Returns a string consisting of n spaces.", arg1));
118 export_functions!((
119 substring,
120 "Returns the substring from string `str` starting at position `pos` with length `length.",
121 str pos length
122 ));
123 export_functions!((
124 unbase64,
125 "Decodes the input string `str` from a base64 string into binary data.",
126 str
127 ));
128 export_functions!((soundex, "Returns Soundex code of the string.", str));
129 export_functions!((
130 is_valid_utf8,
131 "Returns true if str is a valid UTF-8 string, otherwise returns false",
132 str
133 ));
134 export_functions!((
135 make_valid_utf8,
136 "Returns the original string if str is a valid UTF-8 string, otherwise returns a new string whose invalid UTF8 byte sequences are replaced using the UNICODE replacement character U+FFFD.",
137 str
138 ));
139 export_functions!((
140 quote,
141 "Returns str enclosed by single quotes and each instance of single quote in it is preceded by a backslash",
142 str
143 ));
144}
145
146pub fn functions() -> Vec<Arc<ScalarUDF>> {
147 vec![
148 ascii(),
149 base64(),
150 char(),
151 concat(),
152 concat_ws(),
153 elt(),
154 ilike(),
155 length(),
156 like(),
157 luhn_check(),
158 format_string(),
159 space(),
160 substring(),
161 unbase64(),
162 soundex(),
163 make_valid_utf8(),
164 is_valid_utf8(),
165 quote(),
166 ]
167}