datafusion_spark/function/math/
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 expm1;
19pub mod factorial;
20pub mod hex;
21pub mod modulus;
22pub mod rint;
23pub mod width_bucket;
24
25use datafusion_expr::ScalarUDF;
26use datafusion_functions::make_udf_function;
27use std::sync::Arc;
28
29make_udf_function!(expm1::SparkExpm1, expm1);
30make_udf_function!(factorial::SparkFactorial, factorial);
31make_udf_function!(hex::SparkHex, hex);
32make_udf_function!(modulus::SparkMod, modulus);
33make_udf_function!(modulus::SparkPmod, pmod);
34make_udf_function!(rint::SparkRint, rint);
35make_udf_function!(width_bucket::SparkWidthBucket, width_bucket);
36
37pub mod expr_fn {
38    use datafusion_functions::export_functions;
39
40    export_functions!((expm1, "Returns exp(expr) - 1 as a Float64.", arg1));
41    export_functions!((
42        factorial,
43        "Returns the factorial of expr. expr is [0..20]. Otherwise, null.",
44        arg1
45    ));
46    export_functions!((hex, "Computes hex value of the given column.", arg1));
47    export_functions!((modulus, "Returns the remainder of division of the first argument by the second argument.", arg1 arg2));
48    export_functions!((pmod, "Returns the positive remainder of division of the first argument by the second argument.", arg1 arg2));
49    export_functions!((rint, "Returns the double value that is closest in value to the argument and is equal to a mathematical integer.", arg1));
50    export_functions!((width_bucket, "Returns the bucket number into which the value of this expression would fall after being evaluated.", arg1 arg2 arg3 arg4));
51}
52
53pub fn functions() -> Vec<Arc<ScalarUDF>> {
54    vec![
55        expm1(),
56        factorial(),
57        hex(),
58        modulus(),
59        pmod(),
60        rint(),
61        width_bucket(),
62    ]
63}