MohamedAbdeen21 commented on code in PR #10700:
URL: https://github.com/apache/datafusion/pull/10700#discussion_r1617618779
##########
datafusion/functions/src/core/mod.rs:
##########
@@ -41,70 +38,40 @@ 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
-pub mod expr_fn {
- use datafusion_expr::{Expr, Literal};
-
- /// returns NULL if value1 equals value2; otherwise it returns value1. This
- /// can be used to perform the inverse operation of the COALESCE expression
- pub fn nullif(arg1: Expr, arg2: Expr) -> Expr {
- super::nullif().call(vec![arg1, arg2])
- }
-
- /// returns value1 cast to the `arrow_type` given the second argument. This
- /// can be used to cast to a specific `arrow_type`.
- pub fn arrow_cast(arg1: Expr, arg2: Expr) -> Expr {
- super::arrow_cast().call(vec![arg1, arg2])
- }
-
- /// Returns value2 if value1 is NULL; otherwise it returns value1
- pub fn nvl(arg1: Expr, arg2: Expr) -> Expr {
- super::nvl().call(vec![arg1, arg2])
- }
-
- /// Returns value2 if value1 is not NULL; otherwise, it returns value3.
- pub fn nvl2(arg1: Expr, arg2: Expr, arg3: Expr) -> Expr {
- super::nvl2().call(vec![arg1, arg2, arg3])
- }
-
- /// Returns the Arrow type of the input expression.
- pub fn arrow_typeof(arg1: Expr) -> Expr {
- super::arrow_typeof().call(vec![arg1])
- }
-
- /// Returns a struct with the given arguments
- pub fn r#struct(args: Vec<Expr>) -> Expr {
- super::r#struct().call(args)
- }
-
- /// Returns a struct with the given names and arguments pairs
- pub fn named_struct(args: Vec<Expr>) -> Expr {
- super::named_struct().call(args)
- }
-
- /// Returns the value of the field with the given name from the struct
- pub fn get_field(arg1: Expr, field_name: impl Literal) -> Expr {
- super::get_field().call(vec![arg1, field_name.lit()])
- }
-
- /// Returns `coalesce(args...)`, which evaluates to the value of the first
expr which is not NULL
- pub fn coalesce(args: Vec<Expr>) -> Expr {
- super::coalesce().call(args)
- }
-}
-
-/// Return a list of all functions in this package
-pub fn functions() -> Vec<Arc<ScalarUDF>> {
- vec![
- nullif(),
- arrow_cast(),
- nvl(),
- nvl2(),
- arrow_typeof(),
- r#struct(),
- named_struct(),
- get_field(),
- coalesce(),
- ]
-}
+export_functions!((
+ nullif,
+ "Returns NULL if value1 equals value2; otherwise it returns value1. This
can be used to perform the inverse operation of the COALESCE expression",
+ arg1 arg2
+),(
+ arrow_cast,
+ "Returns value2 if value1 is NULL; otherwise it returns value1",
+ arg1 arg2
+),(
+ nvl,
+ "Returns value2 if value1 is NULL; otherwise it returns value1",
+ arg1 arg2
+),(
+ nvl2,
+ "Returns value2 if value1 is not NULL; otherwise, it returns value3.",
+ arg1 arg2 arg3
+),(
+ arrow_typeof,
+ "Returns the Arrow type of the input expression.",
+ arg1
+),(
+ r#struct,
+ "Returns a struct with the given arguments",
+ args,
+),(
+ named_struct,
+ "Returns a struct with the given names and arguments pairs",
+ args,
+),(
+ get_field,
+ "Returns the value of the field with the given name from the struct",
+ arg1, field_name
+),(
+ coalesce,
+ "Returns `coalesce(args...)`, which evaluates to the value of the first
expr which is not NULL",
+ args,
Review Comment:
Single arguments followed by a single comma indicate a vector argument. The
only downside here is that rust-analyzer is unable to identify the type of
`args` and the dev is expected to read the doc of `export_functions!` to notice
that `args` is a vector and not an Expr.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]