szehon-ho opened a new pull request, #60368: URL: https://github.com/apache/spark/pull/60368
### What changes were proposed in this pull request? Use modeled DSv2 generation expressions for both auto-filling missing generated columns and validating supplied generated values. Prefer the modeled expression and fall back to SQL text when it is absent or cannot be converted to Catalyst, matching default values and CHECK constraints. Analysis and evaluation errors after conversion are reported without switching to SQL. Read generation expressions directly from the table's V2 columns during write resolution and share the converter with generated-column validation. Compute generated values from stored input values after assignment casts. Preserve support for connectors that override the legacy SQL-only getter. ### Why are the changes needed? https://issues.apache.org/jira/browse/SPARK-61495 Connectors can already declare generated columns with modeled expressions, but Spark only auto-fills missing values from SQL text. The generated-column validation path also prefers SQL, while default values and CHECK constraints prefer modeled expressions. Supporting the modeled form consistently lets connectors use the portable expression API and gives auto-fill and validation the same expression semantics. ### Does this PR introduce _any_ user-facing change? Yes. For a connector table with `a INT` and `b INT` generated by a modeled `a + 1` expression, inserting only `a = 1` now stores `(1, 2)`. Tables must advertise `GENERATE_COLUMN_VALUES_ON_WRITE` to use this behavior. When both representations are present, a convertible modeled expression now takes precedence over SQL text for both auto-fill and validation. This can change results when the two forms differ. For example, `coalesce(s, 1)` defined under a non-ANSI session produces a modeled expression with a string fallback, so `s = '007'` generates `'007'` and validates against that value, including under an ANSI writer. Previously the SQL text was reparsed under the stored-expression settings and generated `'7'`. These changes affect generated-column write support in the unreleased 4.3.0 line. ### How was this patch tested? Added regression coverage in `GeneratedColumnWriteSuite` for SQL inserts and overwrite, DataFrame append and overwrite, mixed SQL/modeled columns, assignment casts, nested and dotted references, ANSI behavior, explicit-value validation, model precedence, unsupported-model SQL fallback, invalid SQL ignored by convertible models, analysis/evaluation errors without SQL fallback, capability handling, missing input columns, and streaming rejection. Generation-expression presence checks defer conversion so malformed SQL or unsupported models do not hide missing-column errors. Added analyzer coverage for the legacy SQL-only getter. Updated the in-memory test table to retain modeled generation expressions when merging write schemas, so repeated writes exercise generation and validation. On Java 21.0.13, all 127 generated-column tests and all 394 tests across the seven DSv2 write-analysis suites passed. Scala and Java style checks also passed with no errors or warnings: ```sh build/sbt 'sql/testOnly *GeneratedColumnWriteSuite' build/sbt 'catalyst/testOnly *V2ResolveOutputRelationSuite *V2AppendData*AnalysisSuite *V2Overwrite*AnalysisSuite' build/sbt 'catalyst/scalastyle' 'catalyst/Test/scalastyle' 'sql/Test/scalastyle' 'catalyst/checkstyle' ``` ### 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]
