-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce code repetition in datafusion/functions
mod files
#10700
Reduce code repetition in datafusion/functions
mod files
#10700
Conversation
datafusion/functions/src/core/mod.rs
Outdated
),( | ||
coalesce, | ||
"Returns `coalesce(args...)`, which evaluates to the value of the first expr which is not NULL", | ||
args, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
($(($FUNC:ident, $DOC:expr, $($arg:tt)*)),*) => { | ||
$( | ||
// switch to single-function cases below | ||
export_functions!(single $FUNC, $DOC, $($arg)*); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little hack to avoid making a separate macro.
datafusion/functions
mod files
4fc8a18
to
15bfd36
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jayzhan211 and @MohamedAbdeen21
)* | ||
}; | ||
|
||
// single vector argument (a single argument followed by a comma) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is pretty fancy 👍
Thanks for the review! @jayzhan211 @alamb |
Which issue does this PR close?
Possibly closes #10397.
Rationale for this change
Extending the
export_function!
macro to be used in math and core functions modules, reducing code repetition.Some functions expect a single
Expr
arg and others expect a singleVec<Expr>
args. I took a page from Python's 1-tuples (where(1)
is evaluated toint(1)
, but(1,)
is evaluated totuple(1)
and now single args followed by a comma are treated as aVec<Expr>
but single args without trailing commas are treated asExpr
.Variadic functions are unchanged
arg1 arg2 ...
, but should not contain commas.I left a comment regarding the special case of
get_field
.What changes are included in this PR?
Extending the
export_function!
macro to accept both variadic functions and functions that take singleVec<Expr>
argument. Uses the rust forums link made by @jayzhan211 https://users.rust-lang.org/t/macro-repetition-with-multiple-rules/110816/2?u=jayzhanAre these changes tested?
Passes existing tests
Are there any user-facing changes?
No