Skip to content
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

refactor: simplify the make_udf_function macro #13712

Merged
merged 1 commit into from
Dec 11, 2024

Conversation

jonahgao
Copy link
Member

@jonahgao jonahgao commented Dec 10, 2024

Which issue does this PR close?

Follow-up of #13674 (comment)

Rationale for this change

By limiting the ScalarUDF singleton to the function scope, we can remove $GNAME from the make_udf_function macro. Macro callers no longer need to provide a unique singleton name.

Before:

make_udf_function!(random::RandomFunc, RANDOM, random);

After:

make_udf_function!(random::RandomFunc, random);

What changes are included in this PR?

Are these changes tested?

Yes.

Are there any user-facing changes?

No. Those macros are not exported and are not public APIs.

($UDF:ty, $GNAME:ident, $NAME:ident) => {
#[doc = "Return a [`ScalarUDF`](datafusion_expr::ScalarUDF) implementation "]
#[doc = stringify!($UDF)]
($UDF:ty, $NAME:ident) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the main change.

pub fn $NAME() -> std::sync::Arc<datafusion_expr::ScalarUDF> {
// Singleton instance of the function
static $GNAME: std::sync::LazyLock<
static INSTANCE: std::sync::LazyLock<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we go where lazy lock shines

Copy link
Contributor

@comphead comphead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm thanks @jonahgao

@jayzhan211
Copy link
Contributor

Thanks @jonahgao @comphead

@jayzhan211 jayzhan211 merged commit 0f5634e into apache:main Dec 11, 2024
26 checks passed
@jonahgao jonahgao deleted the simplify_macro branch December 11, 2024 01:30
@jonahgao
Copy link
Member Author

Thanks @comphead @jayzhan211 for the review

zhuliquan pushed a commit to zhuliquan/datafusion that referenced this pull request Dec 11, 2024
zhuliquan pushed a commit to zhuliquan/datafusion that referenced this pull request Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants