Skip to content

Commit fe268bc

Browse files
authored
Move coalesce function from math to core (#10201)
* Move coalesce function from math to core Signed-off-by: xxxuuu <[email protected]> * Make `cargo doc` happy Signed-off-by: xxxuuu <[email protected]> --------- Signed-off-by: xxxuuu <[email protected]>
1 parent 65ecfda commit fe268bc

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

datafusion/functions/src/math/coalesce.rs renamed to datafusion/functions/src/core/coalesce.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ mod test {
132132

133133
use datafusion_expr::ScalarUDFImpl;
134134

135-
use crate::math;
135+
use crate::core;
136136

137137
#[test]
138138
fn test_coalesce_return_types() {
139-
let coalesce = math::coalesce::CoalesceFunc::new();
139+
let coalesce = core::coalesce::CoalesceFunc::new();
140140
let return_type = coalesce
141141
.return_type(&[DataType::Date32, DataType::Date32])
142142
.unwrap();

datafusion/functions/src/core/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
2020
pub mod arrow_cast;
2121
pub mod arrowtypeof;
22+
pub mod coalesce;
2223
pub mod getfield;
2324
pub mod named_struct;
2425
pub mod nullif;
@@ -35,6 +36,7 @@ make_udf_function!(arrowtypeof::ArrowTypeOfFunc, ARROWTYPEOF, arrow_typeof);
3536
make_udf_function!(r#struct::StructFunc, STRUCT, r#struct);
3637
make_udf_function!(named_struct::NamedStructFunc, NAMED_STRUCT, named_struct);
3738
make_udf_function!(getfield::GetFieldFunc, GET_FIELD, get_field);
39+
make_udf_function!(coalesce::CoalesceFunc, COALESCE, coalesce);
3840

3941
// Export the functions out of this package, both as expr_fn as well as a list of functions
4042
export_functions!(
@@ -45,5 +47,6 @@ export_functions!(
4547
(arrow_typeof, arg_1, "Returns the Arrow type of the input expression."),
4648
(r#struct, args, "Returns a struct with the given arguments"),
4749
(named_struct, args, "Returns a struct with the given names and arguments pairs"),
48-
(get_field, arg_1 arg_2, "Returns the value of the field with the given name from the struct")
50+
(get_field, arg_1 arg_2, "Returns the value of the field with the given name from the struct"),
51+
(coalesce, args, "Returns `coalesce(args...)`, which evaluates to the value of the first expr which is not NULL")
4952
);

datafusion/functions/src/math/mod.rs

-8
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use datafusion_expr::ScalarUDF;
2121
use std::sync::Arc;
2222

2323
pub mod abs;
24-
pub mod coalesce;
2524
pub mod cot;
2625
pub mod factorial;
2726
pub mod gcd;
@@ -47,7 +46,6 @@ make_math_unary_udf!(AtanhFunc, ATANH, atanh, atanh, Some(vec![Some(true)]));
4746
make_math_binary_udf!(Atan2, ATAN2, atan2, atan2, Some(vec![Some(true)]));
4847
make_math_unary_udf!(CbrtFunc, CBRT, cbrt, cbrt, None);
4948
make_math_unary_udf!(CeilFunc, CEIL, ceil, ceil, Some(vec![Some(true)]));
50-
make_udf_function!(coalesce::CoalesceFunc, COALESCE, coalesce);
5149
make_math_unary_udf!(CosFunc, COS, cos, cos, None);
5250
make_math_unary_udf!(CoshFunc, COSH, cosh, cosh, None);
5351
make_udf_function!(cot::CotFunc, COT, cot);
@@ -130,11 +128,6 @@ pub mod expr_fn {
130128
super::ceil().call(vec![num])
131129
}
132130

133-
#[doc = "returns `coalesce(args...)`, which evaluates to the value of the first [Expr] which is not NULL"]
134-
pub fn coalesce(args: Vec<Expr>) -> Expr {
135-
super::coalesce().call(args)
136-
}
137-
138131
#[doc = "cosine"]
139132
pub fn cos(num: Expr) -> Expr {
140133
super::cos().call(vec![num])
@@ -289,7 +282,6 @@ pub fn functions() -> Vec<Arc<ScalarUDF>> {
289282
atanh(),
290283
cbrt(),
291284
ceil(),
292-
coalesce(),
293285
cos(),
294286
cosh(),
295287
cot(),

0 commit comments

Comments
 (0)