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