Omega359 commented on code in PR #10000:
URL: 
https://github.com/apache/arrow-datafusion/pull/10000#discussion_r1556137751


##########
datafusion/functions/src/math/mod.rs:
##########
@@ -17,86 +17,244 @@
 
 //! "math" DataFusion functions
 
+use datafusion_expr::ScalarUDF;
+use std::sync::Arc;
+
 pub mod abs;
+pub mod cot;
 pub mod gcd;
+mod iszero;
 pub mod lcm;
 pub mod nans;
 pub mod pi;
+pub mod round;
+pub mod trunc;
 
 // Create UDFs
-make_udf_function!(nans::IsNanFunc, ISNAN, isnan);
 make_udf_function!(abs::AbsFunc, ABS, abs);
-make_udf_function!(gcd::GcdFunc, GCD, gcd);
-make_udf_function!(lcm::LcmFunc, LCM, lcm);
-make_udf_function!(pi::PiFunc, PI, pi);
-
-make_math_unary_udf!(Log2Func, LOG2, log2, log2, Some(vec![Some(true)]));
-make_math_unary_udf!(Log10Func, LOG10, log10, log10, Some(vec![Some(true)]));
-make_math_unary_udf!(LnFunc, LN, ln, ln, Some(vec![Some(true)]));
-
-make_math_unary_udf!(TanhFunc, TANH, tanh, tanh, None);
 make_math_unary_udf!(AcosFunc, ACOS, acos, acos, None);
+make_math_unary_udf!(AcoshFunc, ACOSH, acosh, acosh, Some(vec![Some(true)]));
 make_math_unary_udf!(AsinFunc, ASIN, asin, asin, None);
-make_math_unary_udf!(TanFunc, TAN, tan, tan, None);
-
-make_math_unary_udf!(AtanhFunc, ATANH, atanh, atanh, Some(vec![Some(true)]));
 make_math_unary_udf!(AsinhFunc, ASINH, asinh, asinh, Some(vec![Some(true)]));
-make_math_unary_udf!(AcoshFunc, ACOSH, acosh, acosh, Some(vec![Some(true)]));
 make_math_unary_udf!(AtanFunc, ATAN, atan, atan, Some(vec![Some(true)]));
+make_math_unary_udf!(AtanhFunc, ATANH, atanh, atanh, Some(vec![Some(true)]));
 make_math_binary_udf!(Atan2, ATAN2, atan2, atan2, Some(vec![Some(true)]));
-
+make_math_unary_udf!(CbrtFunc, CBRT, cbrt, cbrt, None);
+make_math_unary_udf!(CosFunc, COS, cos, cos, None);
+make_math_unary_udf!(CoshFunc, COSH, cosh, cosh, None);
+make_udf_function!(cot::CotFunc, COT, cot);
+make_math_unary_udf!(DegreesFunc, DEGREES, degrees, to_degrees, None);
+make_math_unary_udf!(FloorFunc, FLOOR, floor, floor, Some(vec![Some(true)]));
+make_udf_function!(gcd::GcdFunc, GCD, gcd);
+make_udf_function!(nans::IsNanFunc, ISNAN, isnan);
+make_udf_function!(iszero::IsZeroFunc, ISZERO, iszero);
+make_udf_function!(lcm::LcmFunc, LCM, lcm);
+make_math_unary_udf!(LnFunc, LN, ln, ln, Some(vec![Some(true)]));
+make_math_unary_udf!(Log2Func, LOG2, log2, log2, Some(vec![Some(true)]));
+make_math_unary_udf!(Log10Func, LOG10, log10, log10, Some(vec![Some(true)]));
+make_udf_function!(pi::PiFunc, PI, pi);
 make_math_unary_udf!(RadiansFunc, RADIANS, radians, to_radians, None);
+make_udf_function!(round::RoundFunc, ROUND, round);
 make_math_unary_udf!(SignumFunc, SIGNUM, signum, signum, None);
 make_math_unary_udf!(SinFunc, SIN, sin, sin, None);
 make_math_unary_udf!(SinhFunc, SINH, sinh, sinh, None);
 make_math_unary_udf!(SqrtFunc, SQRT, sqrt, sqrt, None);
+make_math_unary_udf!(TanFunc, TAN, tan, tan, None);
+make_math_unary_udf!(TanhFunc, TANH, tanh, tanh, None);
+make_udf_function!(trunc::TruncFunc, TRUNC, trunc);
 
-make_math_unary_udf!(CbrtFunc, CBRT, cbrt, cbrt, None);
-make_math_unary_udf!(CosFunc, COS, cos, cos, None);
-make_math_unary_udf!(CoshFunc, COSH, cosh, cosh, None);
-make_math_unary_udf!(DegreesFunc, DEGREES, degrees, to_degrees, None);
+pub mod expr_fn {
+    use datafusion_expr::Expr;
 
-make_math_unary_udf!(FloorFunc, FLOOR, floor, floor, Some(vec![Some(true)]));
+    #[doc = "returns the absolute value of a given number"]
+    pub fn abs(num: Expr) -> Expr {
+        super::abs().call(vec![num])
+    }
+
+    #[doc = "returns the arc cosine or inverse cosine of a number"]
+    pub fn acos(num: Expr) -> Expr {
+        super::acos().call(vec![num])
+    }
+
+    #[doc = "returns inverse hyperbolic cosine"]
+    pub fn acosh(num: Expr) -> Expr {
+        super::acosh().call(vec![num])
+    }
+
+    #[doc = "returns the arc sine or inverse sine of a number"]
+    pub fn asin(num: Expr) -> Expr {
+        super::asin().call(vec![num])
+    }
+
+    #[doc = "returns inverse hyperbolic sine"]
+    pub fn asinh(num: Expr) -> Expr {
+        super::asinh().call(vec![num])
+    }
+
+    #[doc = "returns inverse tangent"]
+    pub fn atan(num: Expr) -> Expr {
+        super::atan().call(vec![num])
+    }
+
+    #[doc = "returns inverse tangent of a division given in the argument"]
+    pub fn atan2(y: Expr, x: Expr) -> Expr {
+        super::atan2().call(vec![y, x])
+    }
+
+    #[doc = "returns inverse hyperbolic tangent"]
+    pub fn atanh(num: Expr) -> Expr {
+        super::atanh().call(vec![num])
+    }
+
+    #[doc = "cube root of a number"]
+    pub fn cbrt(num: Expr) -> Expr {
+        super::cbrt().call(vec![num])
+    }
+
+    #[doc = "cosine"]
+    pub fn cos(num: Expr) -> Expr {
+        super::cos().call(vec![num])
+    }
+
+    #[doc = "hyperbolic cosine"]
+    pub fn cosh(num: Expr) -> Expr {
+        super::cosh().call(vec![num])
+    }
+
+    #[doc = "cotangent of a number"]
+    pub fn cot(num: Expr) -> Expr {
+        super::cot().call(vec![num])
+    }
+
+    #[doc = "converts radians to degrees"]
+    pub fn degrees(num: Expr) -> Expr {
+        super::degrees().call(vec![num])
+    }
+
+    #[doc = "nearest integer less than or equal to argument"]
+    pub fn floor(num: Expr) -> Expr {
+        super::floor().call(vec![num])
+    }
+
+    #[doc = "greatest common divisor"]
+    pub fn gcd(x: Expr, y: Expr) -> Expr {
+        super::gcd().call(vec![x, y])
+    }
+
+    #[doc = "returns true if a given number is +NaN or -NaN otherwise returns 
false"]
+    pub fn isnan(num: Expr) -> Expr {
+        super::isnan().call(vec![num])
+    }
+
+    #[doc = "returns true if a given number is +0.0 or -0.0 otherwise returns 
false"]
+    pub fn iszero(num: Expr) -> Expr {
+        super::iszero().call(vec![num])
+    }
+
+    #[doc = "least common multiple"]
+    pub fn lcm(x: Expr, y: Expr) -> Expr {
+        super::lcm().call(vec![x, y])
+    }
+
+    #[doc = "natural logarithm (base e) of a number"]
+    pub fn ln(num: Expr) -> Expr {
+        super::ln().call(vec![num])
+    }
+
+    #[doc = "base 2 logarithm of a number"]
+    pub fn log2(num: Expr) -> Expr {
+        super::log2().call(vec![num])
+    }
+
+    #[doc = "base 10 logarithm of a number"]
+    pub fn log10(num: Expr) -> Expr {
+        super::log10().call(vec![num])
+    }
+
+    #[doc = "Returns an approximate value of π"]
+    pub fn pi() -> Expr {
+        super::pi().call(vec![])
+    }
+
+    #[doc = "converts degrees to radians"]
+    pub fn radians(num: Expr) -> Expr {
+        super::radians().call(vec![num])
+    }
+
+    #[doc = "round to nearest integer"]
+    pub fn round(args: Vec<Expr>) -> Expr {
+        super::round().call(args)
+    }
+
+    #[doc = "sign of the argument (-1, 0, +1)"]
+    pub fn signum(num: Expr) -> Expr {
+        super::signum().call(vec![num])
+    }
+
+    #[doc = "sine"]
+    pub fn sin(num: Expr) -> Expr {
+        super::sin().call(vec![num])
+    }
+
+    #[doc = "hyperbolic sine"]
+    pub fn sinh(num: Expr) -> Expr {
+        super::sinh().call(vec![num])
+    }
+
+    #[doc = "square root of a number"]
+    pub fn sqrt(num: Expr) -> Expr {
+        super::sqrt().call(vec![num])
+    }
+
+    #[doc = "returns the tangent of a number"]
+    pub fn tan(num: Expr) -> Expr {
+        super::tan().call(vec![num])
+    }
+
+    #[doc = "returns the hyperbolic tangent of a number"]
+    pub fn tanh(num: Expr) -> Expr {
+        super::tanh().call(vec![num])
+    }
+
+    #[doc = "truncate toward zero, with optional precision"]
+    pub fn trunc(args: Vec<Expr>) -> Expr {
+        super::trunc().call(args)
+    }
+}
 
-// Export the functions out of this package, both as expr_fn as well as a list 
of functions
-export_functions!(
-    (
-        isnan,
-        num,
-        "returns true if a given number is +NaN or -NaN otherwise returns 
false"
-    ),
-    (abs, num, "returns the absolute value of a given number"),
-    (log2, num, "base 2 logarithm of a number"),
-    (log10, num, "base 10 logarithm of a number"),
-    (ln, num, "natural logarithm (base e) of a number"),
-    (
-        acos,
-        num,
-        "returns the arc cosine or inverse cosine of a number"
-    ),
-    (
-        asin,
-        num,
-        "returns the arc sine or inverse sine of a number"
-    ),
-    (tan, num, "returns the tangent of a number"),
-    (tanh, num, "returns the hyperbolic tangent of a number"),
-    (atanh, num, "returns inverse hyperbolic tangent"),
-    (asinh, num, "returns inverse hyperbolic sine"),
-    (acosh, num, "returns inverse hyperbolic cosine"),
-    (atan, num, "returns inverse tangent"),
-    (atan2, y x, "returns inverse tangent of a division given in the 
argument"),
-    (radians, num, "converts degrees to radians"),
-    (signum, num, "sign of the argument (-1, 0, +1)"),
-    (sin, num, "sine"),
-    (sinh, num, "hyperbolic sine"),
-    (sqrt, num, "square root of a number"),
-    (cbrt, num, "cube root of a number"),
-    (cos, num, "cosine"),
-    (cosh, num, "hyperbolic cosine"),
-    (degrees, num, "converts radians to degrees"),
-    (gcd, x y, "greatest common divisor"),
-    (lcm, x y, "least common multiple"),
-    (floor, num, "nearest integer less than or equal to argument"),
-    (pi, , "Returns an approximate value of π")
-);
+///   Return a list of all functions in this package

Review Comment:
   I had to replace the export_functions macro usage here because it doesn't 
handle Vec<Expr> args such as is used by trunc function.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to