dongjoon-hyun opened a new pull request, #60635:
URL: https://github.com/apache/spark/pull/60635

   ### What changes were proposed in this pull request?
   
   This PR fixes `Column.builderFrom` so that a column keeps the SQL string 
returned by the legacy `Column.generationExpression()` getter.
   
   `builderFrom` used to copy only `columnGenerationExpression()`. It now uses 
`new GenerationExpression(legacySql, modeledExpression)` when 
`generationExpression()` returns a SQL string and 
`columnGenerationExpression()` is either null or has no SQL string. This is the 
same fallback as `GeneratedColumn.columnGenerationExpression`.
   
   ### Why are the changes needed?
   
   `Column.builderFrom` read `column.generationExpression()` in v4.2.0, but 
SPARK-57544 changed it to read only `column.columnGenerationExpression()`, 
which shipped in v4.3.0. That getter returns null by default, so a connector 
that implements only the legacy SQL getter loses its generation expression when 
its column is copied. A column can also return a modeled expression without SQL 
while providing the SQL through the legacy getter. That shape is supported 
since SPARK-61495, and the copy lost the SQL in this case too.
   
   The only caller in the main code is `CatalogV2Util.clearIds`, which is used 
by `CreateTableLikeExec` when the source of `CREATE TABLE ... LIKE` is not a V1 
table. For such a source, the new table silently gets an ordinary column 
instead of a generated column.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, but it only restores the behavior of v4.2.0. In v4.3.0, `CREATE TABLE 
... LIKE` from a DSv2 table drops the generation expression of a column that 
provides it only through `Column.generationExpression()`. With this PR, the 
generation expression is copied to the new table.
   
   ### How was this patch tested?
   
   Added a test to `CreateTableLikeSuite`. It creates a source table with two 
generated columns, one with `columnGenerationExpression()` returning null and 
one returning a modeled expression without SQL, and checks the columns of the 
table created by `CREATE TABLE ... LIKE`. The test fails without the fix, and 
passes with it.
   
   ```
   build/sbt 'sql/testOnly org.apache.spark.sql.connector.CreateTableLikeSuite'
   ```
   
   ### 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]

Reply via email to