Skip to main content

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