[SPARK-53968][SQL] Store decimal precision loss conf in arithmetic expressions #52681
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.
What changes were proposed in this pull request?
Currently, arithmetic expressions such as
AddandMultiplyuse the configurationspark.sql.decimalOperations.allowPrecisionLossto determine their output type when working with decimal values. This approach is problematic because if the expression is transformed or copied, its return type could change depending on the active configuration value.This issue can happen during view resolution; we can use one value of the config during analysis and different one during query optimization. If a referenced expression changes type and that reference is reused elsewhere in the plan it will trigger a plan validation error.
Why are the changes needed?
To address this, we should follow a similar approach to what was done for ANSI mode: store the relevant context directly within the expression as part of its state. This ensures the expression remains stable and unaffected by configuration changes when it’s copied or transformed. To make this transition smooth, I’ve generalized the existing EvalMode used for ANSI so that it can be extended to multiple configuration dimensions.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Added a new unit test in SQLViewSuite which was failing with plan validation error before.
Was this patch authored or co-authored using generative AI tooling?
No.