suhuruli opened a new pull request, #60680:
URL: https://github.com/apache/spark/pull/60680
### What changes were proposed in this pull request?
`V2SessionCatalog.alterTable` applies the table changes to
`catalogTable.properties` and then reads the new comment and default collation
back from that map. A session-catalog table does not keep either value in
`properties`: they live in the dedicated `CatalogTable.comment` and
`CatalogTable.collation` fields. So every ALTER that changes a table property
sets the field it does not name to `None`. Column-only changes take the
`alterTableSchema` branch and were never affected.
This PR changes `alterTable` to recompute the comment or the collation from
the changes only when a change sets or removes that property. Otherwise it
keeps the existing `catalogTable` value. The v1 `ALTER TABLE ... SET/UNSET
TBLPROPERTIES` commands already follow this rule. Owner, location and the other
fields are unchanged.
### Why are the changes needed?
On the session catalog, setting one of the two values silently clears the
other one:
```sql
CREATE TABLE t (a STRING) USING parquet COMMENT 'table comment' DEFAULT
COLLATION UTF8_LCASE;
COMMENT ON TABLE t IS 'new comment';
DESCRIBE TABLE EXTENDED t; -- Comment: new comment, the Collation row is
gone
-- on a fresh t:
ALTER TABLE t DEFAULT COLLATION UNICODE;
DESCRIBE TABLE EXTENDED t; -- Collation: UNICODE, the Comment row is gone
```
This came up in the review of #60462 ([SPARK-57670][SDP] Remove table
properties dropped from the dataset definition), which alters pipeline tables
through this method and depends on this fix for its comment tests. This happens
on both the in-memory catalog and the Hive catalog. `ALTER TABLE t SET
TBLPROPERTIES (...)` is not affected because it runs as the v1 command, which
already keeps both values. `COMMENT ON TABLE` and `ALTER TABLE ... DEFAULT
COLLATION` go through `V2SessionCatalog.alterTable` and lose them.
### Does this PR introduce _any_ user-facing change?
Yes. A session-catalog table's comment or default collation is no longer
cleared by an ALTER TABLE that does not name it.
Before: `COMMENT ON TABLE` clears the default collation and `ALTER TABLE ...
DEFAULT COLLATION` clears the comment. After: each keeps the other.
No migration-guide entry: the fix restores what the v1 `SET/UNSET
TBLPROPERTIES` commands already do.
### How was this patch tested?
New tests:
- `V2SessionCatalogTableSuite`:
- "SPARK-62033: alterTable keeps the comment and collation unless a change
names them" is a table-driven test. It covers setting or removing an unrelated
property, and removing only the comment or only the collation.
- "SPARK-62033: alterTable sets or removes the comment and collation a
change names" checks that changes naming either property still apply.
- `DDLSuite`: "SPARK-62033: COMMENT ON TABLE keeps the default collation and
ALTER TABLE DEFAULT COLLATION keeps the comment". It runs through SQL on both
the in-memory session catalog (`InMemoryCatalogedDDLSuite`) and the Hive
session catalog (`HiveDDLSuite`). Rows: `COMMENT ON TABLE t IS 'new comment'`,
`COMMENT ON TABLE t IS NULL` and `ALTER TABLE t DEFAULT COLLATION UNICODE`. The
parser turns `IS NULL` into an empty comment, so that row expects `Some("")`
and checks that the collation is kept. SQL has no statement that removes a
default collation (`UNSET TBLPROPERTIES` rejects the reserved `collation` key),
so removal is only covered in `V2SessionCatalogTableSuite`.
All new tests fail without the change in `V2SessionCatalog` and pass with it.
```
build/sbt -Phive "sql/testOnly
org.apache.spark.sql.execution.datasources.v2.V2SessionCatalogTableSuite
org.apache.spark.sql.execution.datasources.v2.V2SessionCatalogNamespaceSuite
org.apache.spark.sql.execution.command.InMemoryCatalogedDDLSuite"
build/sbt -Phive "hive/testOnly
org.apache.spark.sql.hive.execution.HiveDDLSuite"
build/sbt -Phive sql/scalastyle sql/Test/scalastyle hive/scalastyle
hive/Test/scalastyle
```
### 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]