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

Skip casting result array for binary numerical operators result between array and scalar if possible #6438

Merged
merged 3 commits into from
May 26, 2023

Conversation

viirya
Copy link
Member

@viirya viirya commented May 25, 2023

Which issue does this PR close?

Closes #.

Rationale for this change

This is a follow up to #6269.

As we try on upgrading to latest DataFusion 25.0.0 internally, just found this issue. In DataFusion, for numerical operators between Dictionary array (lhs) and literal (rhs), the type of rhs literal will be coerced to Scalar::Dictionary. Although the operation is still between array and literal, the result datatype can be aligned with the operation between array and array.

That's why #6269 is proposed to convert the result between array and literal to match the one between array and array.

But in our case, we don't rely on query analysis and optimization of DataFusion but directly go for physical execution, our query doesn't go through the coercion phase. So the operation is between Dictionary array and original literal (without coerced to Scalar::Dictionary). This leads to different result type as Dictionary array. In such case, we don't need to cast the result array. We can skip casting for the result array if its datatype is already same as binary operator's result type.

What changes are included in this PR?

Are these changes tested?

Tested internally. This is not the case that DataFusion queries could hit actually.

Are there any user-facing changes?

No

@github-actions github-actions bot added the physical-expr Changes to the physical-expr crates label May 25, 2023
@viirya
Copy link
Member Author

viirya commented May 25, 2023

cc @alamb

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.

Makes sense to me -- thank you @viirya

It might be worth a test so this doesn't accidentally get broken on you in the future

@viirya
Copy link
Member Author

viirya commented May 25, 2023

It might be worth a test so this doesn't accidentally get broken on you in the future

Added a unit test just for the function to make sure it won't be broken.

@viirya viirya merged commit 0c7a3b6 into apache:main May 26, 2023
@viirya
Copy link
Member Author

viirya commented May 26, 2023

Thanks @alamb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
physical-expr Changes to the physical-expr crates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants