Skip to content

Conversation

@stefankandic
Copy link
Contributor

@stefankandic stefankandic commented Oct 21, 2025

What changes were proposed in this pull request?

Currently, arithmetic expressions such as Add and Multiply use the configuration spark.sql.decimalOperations.allowPrecisionLoss to 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.

@github-actions github-actions bot added the SQL label Oct 21, 2025
@stefankandic stefankandic marked this pull request as ready for review October 22, 2025 08:48
@cloud-fan
Copy link
Contributor

thanks, merging to master!

@cloud-fan cloud-fan closed this in a96e9ca Oct 22, 2025
huangxiaopingRD pushed a commit to huangxiaopingRD/spark that referenced this pull request Nov 25, 2025
…pressions

### What changes were proposed in this pull request?
Currently, arithmetic expressions such as `Add` and `Multiply` use the configuration `spark.sql.decimalOperations.allowPrecisionLoss` to 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.

Closes apache#52681 from stefankandic/fixViewDec.

Authored-by: Stefan Kandic <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants