From fe268bcab9e1ff93bf0f9c8ee72a252d0440b614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?x=C2=B3u=C2=B3?= Date: Wed, 24 Apr 2024 11:08:44 +0800 Subject: [PATCH] Move coalesce function from math to core (#10201) * Move coalesce function from math to core Signed-off-by: xxxuuu * Make `cargo doc` happy Signed-off-by: xxxuuu --------- Signed-off-by: xxxuuu --- datafusion/functions/src/{math => core}/coalesce.rs | 4 ++-- datafusion/functions/src/core/mod.rs | 5 ++++- datafusion/functions/src/math/mod.rs | 8 -------- 3 files changed, 6 insertions(+), 11 deletions(-) rename datafusion/functions/src/{math => core}/coalesce.rs (98%) diff --git a/datafusion/functions/src/math/coalesce.rs b/datafusion/functions/src/core/coalesce.rs similarity index 98% rename from datafusion/functions/src/math/coalesce.rs rename to datafusion/functions/src/core/coalesce.rs index cc4a921c75ef..76f2a3ed741b 100644 --- a/datafusion/functions/src/math/coalesce.rs +++ b/datafusion/functions/src/core/coalesce.rs @@ -132,11 +132,11 @@ mod test { use datafusion_expr::ScalarUDFImpl; - use crate::math; + use crate::core; #[test] fn test_coalesce_return_types() { - let coalesce = math::coalesce::CoalesceFunc::new(); + let coalesce = core::coalesce::CoalesceFunc::new(); let return_type = coalesce .return_type(&[DataType::Date32, DataType::Date32]) .unwrap(); diff --git a/datafusion/functions/src/core/mod.rs b/datafusion/functions/src/core/mod.rs index 0f6920ccffa9..753134bdfdc2 100644 --- a/datafusion/functions/src/core/mod.rs +++ b/datafusion/functions/src/core/mod.rs @@ -19,6 +19,7 @@ pub mod arrow_cast; pub mod arrowtypeof; +pub mod coalesce; pub mod getfield; pub mod named_struct; pub mod nullif; @@ -35,6 +36,7 @@ make_udf_function!(arrowtypeof::ArrowTypeOfFunc, ARROWTYPEOF, arrow_typeof); make_udf_function!(r#struct::StructFunc, STRUCT, r#struct); make_udf_function!(named_struct::NamedStructFunc, NAMED_STRUCT, named_struct); make_udf_function!(getfield::GetFieldFunc, GET_FIELD, get_field); +make_udf_function!(coalesce::CoalesceFunc, COALESCE, coalesce); // Export the functions out of this package, both as expr_fn as well as a list of functions export_functions!( @@ -45,5 +47,6 @@ export_functions!( (arrow_typeof, arg_1, "Returns the Arrow type of the input expression."), (r#struct, args, "Returns a struct with the given arguments"), (named_struct, args, "Returns a struct with the given names and arguments pairs"), - (get_field, arg_1 arg_2, "Returns the value of the field with the given name from the struct") + (get_field, arg_1 arg_2, "Returns the value of the field with the given name from the struct"), + (coalesce, args, "Returns `coalesce(args...)`, which evaluates to the value of the first expr which is not NULL") ); diff --git a/datafusion/functions/src/math/mod.rs b/datafusion/functions/src/math/mod.rs index 1d9e5d94a90d..b6e8d26b6460 100644 --- a/datafusion/functions/src/math/mod.rs +++ b/datafusion/functions/src/math/mod.rs @@ -21,7 +21,6 @@ use datafusion_expr::ScalarUDF; use std::sync::Arc; pub mod abs; -pub mod coalesce; pub mod cot; pub mod factorial; pub mod gcd; @@ -47,7 +46,6 @@ 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!(CeilFunc, CEIL, ceil, ceil, Some(vec![Some(true)])); -make_udf_function!(coalesce::CoalesceFunc, COALESCE, coalesce); 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); @@ -130,11 +128,6 @@ pub mod expr_fn { super::ceil().call(vec![num]) } - #[doc = "returns `coalesce(args...)`, which evaluates to the value of the first [Expr] which is not NULL"] - pub fn coalesce(args: Vec) -> Expr { - super::coalesce().call(args) - } - #[doc = "cosine"] pub fn cos(num: Expr) -> Expr { super::cos().call(vec![num]) @@ -289,7 +282,6 @@ pub fn functions() -> Vec> { atanh(), cbrt(), ceil(), - coalesce(), cos(), cosh(), cot(),