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

   ### What changes were proposed in this pull request?
   
   This PR aims to make the in-memory test tables keep their existing `Column` 
objects on writes.
   
   Previously, `InMemoryBaseTable` rebuilt every column of a table from a 
`StructType` on every batch write (`toBatch`), to support write schema 
evolution (SPARK-52860). A `StructField` does not hold everything that a 
`Column` has, so the round trip loses the following.
   - The connector expression of a default value 
(`ColumnDefaultValue.getExpression`).
   - The identity column spec (`Column.identityColumnSpec`).
   - The class of a connector column. For example, a column that overrides only 
the legacy `Column.generationExpression()` becomes a `ColumnImpl` whose 
`columnGenerationExpression()` is not null.
   
   SPARK-61495 (#60368) restores the generation expression of each column after 
this round trip, but not the rest. SPARK-61659 (#60466) fixed the same kind of 
round trip in `CREATE TABLE` and `ALTER TABLE` of the in-memory test catalogs.
   
   With this PR:
   - A write keeps the existing columns as they are and converts only the 
top-level fields that it appends. This replaces the restore of SPARK-61495.
   - A comment in `GeneratedColumnWriteSuite` no longer says that a write 
rebuilds the columns of the in-memory table.
   
   ### Why are the changes needed?
   
   Tests that write to an in-memory table silently test other columns than the 
ones they create after the first write. For example, a test of a connector 
column that implements only the legacy getter of a generation expression tests 
a `ColumnImpl` after its first `INSERT`. For this reason, 
`GeneratedColumnWriteSuite` runs such an `INSERT` last.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No. This PR changes test code only.
   
   ### How was this patch tested?
   
   Pass the CIs with the newly added test case in `CatalogSuite`.
   
   Without this PR, the new test case fails like the following.
   
   ```
   [info] - SPARK-61682: columns survive writes that append other columns *** 
FAILED *** (725 milliseconds)
   [info]   Array(ColumnImpl("id", LongType, true, null, null, null, null, 
null, null), ColumnImpl("gen", LongType, true, null, null, 
GenerationExpression{sql=id + 1, expression=id + 1}, null, null, null), 
ColumnImpl("def", IntegerType, true, null, ColumnDefaultValue{sql=42, 
expression=null, value=42}, null, null, null, null), ColumnImpl("legacy", 
LongType, true, null, null, GenerationExpression{sql=id * 2, expression=null}, 
null, null, null)) did not equal Array(ColumnImpl("id", LongType, true, null, 
null, null, IdentityColumnSpec{start=1, step=1, allowExplicitInsert=false}, 
null, null), ColumnImpl("gen", LongType, true, null, null, 
GenerationExpression{sql=id + 1, expression=id + 1}, null, null, null), 
ColumnImpl("def", IntegerType, true, null, ColumnDefaultValue{sql=42, 
expression=42, value=42}, null, null, null, null), 
org.apache.spark.sql.connector.catalog.CatalogSuite$$anon$1@7dc83ec) 
(CatalogSuite.scala:196)
   ```
   
   ### 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