dongjoon-hyun opened a new pull request, #60466:
URL: https://github.com/apache/spark/pull/60466
### What changes were proposed in this pull request?
This PR aims to make the in-memory test catalogs keep the `Column` objects
that `CREATE TABLE` and `ALTER TABLE` do not change.
Previously, the following test code rebuilt every column of a table from a
`StructType`.
- `alterTable` of `InMemoryTableCatalog`,
`InMemoryRowLevelOperationTableCatalog`, and `PartialSchemaEvolutionCatalog`.
- `InMemoryRowLevelOperationTableCatalog.createTable`.
- `loadTable` and `alterTable` of `TxnTableCatalog`, which built each
`TxnTable` from a `StructType`.
A `StructField` does not hold everything that a `Column` has, so the round
trip loses the following.
- The connector expression of a generation expression
(`GenerationExpression.getExpression`).
- 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.
With this PR:
- `alterTable` keeps the columns that no `TableChange.ColumnChange` refers
to, via a new helper `InMemoryTableCatalog.alteredColumns`. A column that a
change refers to is still rebuilt from the altered schema.
- `InMemoryRowLevelOperationTableCatalog.createTable` builds the table from
`TableInfo.columns()` directly. `TxnTable` takes columns instead of a
`StructType`. For this, the primary constructor of
`InMemoryRowLevelOperationTable` becomes `private[catalog]`.
- `TxnTable` no longer reassigns missing column IDs, because the constructor
of `InMemoryBaseTable` already does it.
- `TxnTable.commit()` still re-keys the data with the schema that the
`TxnTable` is built with. `TxnTable` now keeps that schema in `initialSchema`,
since it no longer takes a `StructType`.
### Why are the changes needed?
Tests that use these catalogs silently test other columns than the ones they
create: after `ALTER TABLE`, and with `InMemoryRowLevelOperationTableCatalog`,
right after `CREATE TABLE`. For example, a test of a connector column that
implements only the legacy getter of a generation expression tests a
`ColumnImpl` instead, and a test of the connector expression of a generation
expression or a default value tests a column without it.
### 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 cases in `CatalogSuite`.
Without this PR, all four new test cases fail with the same mismatch.
```
[info] - SPARK-61659: columns survive creation and alterations that do not
change them (InMemoryTableCatalog) *** FAILED *** (702 milliseconds)
[info] Array(ColumnImpl("id", LongType, true, null, null, null, null,
null, null), ColumnImpl("gen", LongType, true, null, null,
GenerationExpression{sql=id + 1, expression=null}, 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@5bf273e6)
(CatalogSuite.scala:173)
[info] - SPARK-61659: columns survive creation and alterations that do not
change them (InMemoryRowLevelOperationTableCatalog) *** FAILED *** (24
milliseconds)
[info] ...
[info] - SPARK-61659: columns survive creation and alterations that do not
change them (PartialSchemaEvolutionCatalog) *** FAILED *** (8 milliseconds)
[info] ...
[info] - SPARK-61659: columns survive transactional alterations that do not
change them *** FAILED *** (10 milliseconds)
[info] ...
```
### 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]