szehon-ho opened a new pull request, #60559: URL: https://github.com/apache/spark/pull/60559
### What changes were proposed in this pull request? Treat the children of `MergeRows.Instruction` as conditional during constant folding. Successful folds still produce literals; evaluation failures are deferred to runtime using the existing conditional-expression handling. ### Why are the changes needed? MERGE evaluates only the applicable clause list and stops at the first matching clause. Constant folding can currently evaluate an expression in a skipped clause and fail the entire command. For example, with ANSI mode enabled and a positive source salary, this MERGE should use the second action: ```sql MERGE INTO target t USING source s ON t.pk = s.pk WHEN MATCHED AND s.salary < 0 THEN UPDATE SET salary = 1 DIV 0 WHEN MATCHED THEN UPDATE SET salary = s.salary ``` Instead, optimization raises `DIVIDE_BY_ZERO` before any action is selected. The same issue affects conditions in later clauses and expressions in unmatched clause types. ### Does this PR introduce _any_ user-facing change? Yes. MERGE commands can complete when a failing constant expression belongs to a clause that is never evaluated. The expression still raises an error if execution reaches it. ### How was this patch tested? Added SQL regressions for skipped actions, skipped conditions, and a selected invalid action. The SQL tests are shared by the group-based, delta-based, and split-update MERGE suites. Confirmed both SQL regressions fail with `DIVIDE_BY_ZERO` on unpatched master. With the fix: - Both new MERGE tests across seven suites: 14 tests passed, covering group-based and delta-based writes, split updates, codegen disabled, and tables without metadata columns. - `catalyst/scalastyle`, `catalyst/Test/scalastyle`, and `sql/Test/scalastyle`: passed. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: OpenAI Codex (GPT-6) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
