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