Skip casting result array for binary numerical operators result between array and scalar if possible #6438
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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