dongjoon-hyun opened a new pull request, #60393:
URL: https://github.com/apache/spark/pull/60393
### What changes were proposed in this pull request?
This PR makes `GeneratedColumn.supportsGeneratedColumnsOnWrite(table,
columns)` treat a column as generated when either
`Column.columnGenerationExpression()` or the legacy SQL getter
`Column.generationExpression()` returns a value.
```scala
supportsGeneratedColumnsOnWrite(table) && columns.exists { col =>
// A connector can implement only the legacy SQL getter, which auto-fill
reads as well.
col.columnGenerationExpression() != null || col.generationExpression() !=
null
}
```
For tables with `GENERATE_COLUMN_VALUES_ON_WRITE`, this helper gates:
- `RewriteRowLevelCommand.checkNoGeneratedColumns`, which rejects UPDATE and
MERGE.
- `ResolveWriteToStream`, which rejects streaming writes.
- `TableConstraintResolution.buildGeneratedColumnConstraints`, which builds
the checks of provided values. It reads only `columnGenerationExpression()`
when it builds them, so it still builds none for such columns, and this PR does
not change it. That code is being changed by #60368, so validating a provided
value of such a column is left to a follow-up.
### Why are the changes needed?
A connector can define a generated column by overriding only
`Column.generationExpression()`, the SQL getter that Spark 4.0.0 already has.
`Column.columnGenerationExpression()`, added in 4.3.0, then returns `null` by
default. For such a table with `GENERATE_COLUMN_VALUES_ON_WRITE`, Spark
auto-fills the column on INSERT, because
`GeneratedColumn.attachGenerationExpressions` reads the SQL getter. But the
helper above checked only `columnGenerationExpression()`, so:
- UPDATE and MERGE were not rejected. Spark cannot recompute generated
values for rewritten rows, which is why `checkNoGeneratedColumns` rejects these
commands, so `UPDATE t SET a = 5` kept the old value of a column generated from
`a`.
- Streaming writes were not rejected.
Apache Spark 4.3.0
([v4.3.0](https://github.com/apache/spark/releases/tag/v4.3.0), 2026-10-27) has
this behavior.
### Does this PR introduce _any_ user-facing change?
Yes, for connectors that report `GENERATE_COLUMN_VALUES_ON_WRITE` and
implement only the legacy SQL getter of a generated column. UPDATE, MERGE and
streaming writes to such tables now fail with
`UNSUPPORTED_FEATURE.TABLE_OPERATION`, as they already do for columns defined
with `columnGenerationExpression()`. In Spark 4.3.0, they ran and could leave
stale generated values.
### How was this patch tested?
Pass the CIs with the newly added test cases in `GeneratedColumnWriteSuite`.
Both fail without the fix, because no exception is thrown.
- `SPARK-61550: streaming write with a legacy SQL-only generated column is
blocked`
- `SPARK-61550: UPDATE and MERGE with a legacy SQL-only generated column are
blocked`
```
$ build/sbt 'sql/testOnly *GeneratedColumnWriteSuite'
...
[info] Tests: succeeded 111, failed 0, canceled 0, ignored 0, pending 0
```
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5
--
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]