datafusion_spark/function/string/
mod.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18pub mod ascii;
19pub mod char;
20pub mod concat;
21pub mod elt;
22pub mod format_string;
23pub mod ilike;
24pub mod length;
25pub mod like;
26pub mod luhn_check;
27
28use datafusion_expr::ScalarUDF;
29use datafusion_functions::make_udf_function;
30use std::sync::Arc;
31
32make_udf_function!(ascii::SparkAscii, ascii);
33make_udf_function!(char::CharFunc, char);
34make_udf_function!(concat::SparkConcat, concat);
35make_udf_function!(ilike::SparkILike, ilike);
36make_udf_function!(length::SparkLengthFunc, length);
37make_udf_function!(elt::SparkElt, elt);
38make_udf_function!(like::SparkLike, like);
39make_udf_function!(luhn_check::SparkLuhnCheck, luhn_check);
40make_udf_function!(format_string::FormatStringFunc, format_string);
41
42pub mod expr_fn {
43    use datafusion_functions::export_functions;
44
45    export_functions!((
46        ascii,
47        "Returns the ASCII code point of the first character of string.",
48        arg1
49    ));
50    export_functions!((
51        char,
52        "Returns the ASCII character having the binary equivalent to col. If col is larger than 256 the result is equivalent to char(col % 256).",
53        arg1
54    ));
55    export_functions!((
56        concat,
57        "Concatenates multiple input strings into a single string. Returns NULL if any input is NULL.",
58        args
59    ));
60    export_functions!((
61        elt,
62        "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.",
63        select_col arg1 arg2 argn
64    ));
65    export_functions!((
66        ilike,
67        "Returns true if str matches pattern (case insensitive).",
68        str pattern
69    ));
70    export_functions!((
71        length,
72        "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.",
73        arg1
74    ));
75    export_functions!((
76        like,
77        "Returns true if str matches pattern (case sensitive).",
78        str pattern
79    ));
80    export_functions!((
81        luhn_check,
82        "Returns whether the input string of digits is valid according to the Luhn algorithm.",
83        arg1
84    ));
85    export_functions!((
86        format_string,
87        "Returns a formatted string from printf-style format strings.",
88        strfmt args
89    ));
90}
91
92pub fn functions() -> Vec<Arc<ScalarUDF>> {
93    vec![
94        ascii(),
95        char(),
96        concat(),
97        elt(),
98        ilike(),
99        length(),
100        like(),
101        luhn_check(),
102        format_string(),
103    ]
104}