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

minor: revert parsing precedence between Aggr and UDAF #7682

Merged
merged 2 commits into from
Sep 29, 2023

Conversation

waynexia
Copy link
Member

Which issue does this PR close?

Closes #.

Rationale for this change

Just came across these lines that UDF is parsed before scalar function:

https://github.com/apache/arrow-datafusion/blob/bcc2acd8d10204b32b64fa3b77372655eaee8f06/datafusion/sql/src/expr/function.rs#L49-L61

And then find this rule doesn't hold for Aggr/UDAF

What changes are included in this PR?

After this patch, UDAF can shadow builtin AggrFn if they have the same name.

Are these changes tested?

n/a

Are there any user-facing changes?

It is... I think

@github-actions github-actions bot added the sql SQL Planner label Sep 28, 2023
Copy link
Contributor

@ozankabak ozankabak left a comment

Choose a reason for hiding this comment

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

Makes sense, thank you

@alamb
Copy link
Contributor

alamb commented Sep 28, 2023

I agree it makes sense to allow UDAF to shadow built in aggregate functions (so that users can redefine the meaning of aggregates if they wanted)

Is there any way we can add a test to document this behavior? Perhaps in https://github.com/apache/arrow-datafusion/blob/3f8c51222fa0aa5bb4ef7fa5cab55875bfde0a63/datafusion/core/tests/user_defined/user_defined_aggregates.rs 🤔

Signed-off-by: Ruihang Xia <[email protected]>
@github-actions github-actions bot added the core Core DataFusion crate label Sep 29, 2023
@waynexia
Copy link
Member Author

Thanks for reviewing!

Is there any way we can add a test to document this behavior

Good suggestion 👍 I've added one in that file, reusing the existing time_sum to shadow the builtin sum, please take a look

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks @waynexia

];
assert_batches_eq!(expected, &execute(&ctx, sql).await.unwrap());

// Register `TimeSum` with name `sum`. This will shadow the builtin one
Copy link
Contributor

Choose a reason for hiding this comment

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

💯

@alamb alamb merged commit 2d6e768 into apache:main Sep 29, 2023
22 checks passed
@waynexia waynexia deleted the udaf-prio branch September 29, 2023 17:15
Ted-Jiang pushed a commit to Ted-Jiang/arrow-datafusion that referenced this pull request Oct 7, 2023
* minor: revert parsing precedence between Aggr and UDAF

Signed-off-by: Ruihang Xia <[email protected]>

* add unit test

Signed-off-by: Ruihang Xia <[email protected]>

---------

Signed-off-by: Ruihang Xia <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core DataFusion crate sql SQL Planner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants