szehon-ho opened a new pull request, #60560:
URL: https://github.com/apache/spark/pull/60560

   ### What changes were proposed in this pull request?
   
   Enable generated-column values in DSv2 `UPDATE` and `MERGE` for tables that 
advertise `SUPPORTS_GENERATED_COLUMNS_ON_WRITE`. Compute omitted generated 
values separately for each action from aligned assignments, and validate 
explicitly supplied generated values against the resulting row.
   
   Reuse `GeneratedColumn.ExpressionReader` from #60368 across INSERT 
auto-fill, row-level assignments, and validation. Skip generated-column checks 
for delete delta records.
   
   Depends on #60559. This branch includes that prerequisite; [the 
generated-column changes 
alone](https://github.com/szehon-ho/spark/compare/codex/merge-conditional-constant-folding...codex/generated-columns-dml)
 can be reviewed separately.
   
   ### Why are the changes needed?
   
   Spark already fills and validates generated columns on INSERT, but rejects 
UPDATE and MERGE on these tables. Row-level writes need to recompute omitted 
generated columns from the values being written while preserving simultaneous 
SET semantics.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. Supported DSv2 tables can use UPDATE and MERGE with generated columns. 
For example:
   
   ```sql
   -- g GENERATED ALWAYS AS (a * 2), initially (a=1, b=3, g=2)
   UPDATE t SET a = b + 1, b = 100;
   -- Result: (a=4, b=100, g=8)
   ```
   
   MERGE can mix actions that omit a generated column with actions that supply 
it. Star actions generate columns missing from the source and validate those 
present in the source. An explicitly supplied value that disagrees with the 
generated value still fails validation.
   
   ### How was this patch tested?
   
   Added `GeneratedColumnDMLSuite`, which runs each case with group-based 
writes, delta writes, and split updates. Coverage includes simultaneous 
assignments, assignment casts, row IDs and partitions, mixed MERGE actions, 
star actions, explicit-value validation, defaults and nulls, nested values, 
nondeterministic assignments, modeled expressions, and SQL fallback.
   
   Updated the existing generated-column write tests to exercise legacy 
SQL-only expressions with UPDATE and MERGE.
   
   Local validation on the rebased branch passed (308 tests total):
   
   - `GeneratedColumnDMLSuite` and `GeneratedColumnWriteSuite`: 262 tests.
   - `ConstantFoldingSuite`: 23 tests.
   - The two MERGE folding regression cases across seven row-level write 
suites: 14 tests.
   - The three `AcceptAnySchemaMergeIntoTable` suites: 9 tests.
   - `catalyst/scalastyle`, `catalyst/Test/scalastyle`, and 
`sql/Test/scalastyle`.
   - `git diff --check`.
   
   ### 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]

Reply via email to