Skip to content

[SPARK-56611][SQL] Fix ALTER TABLE RENAME TO with catalog-qualified and table-only targets#55547

Open
lunar-shadow wants to merge 1 commit intoapache:masterfrom
lunar-shadow:fix/rename-table-with-catalog
Open

[SPARK-56611][SQL] Fix ALTER TABLE RENAME TO with catalog-qualified and table-only targets#55547
lunar-shadow wants to merge 1 commit intoapache:masterfrom
lunar-shadow:fix/rename-table-with-catalog

Conversation

@lunar-shadow
Copy link
Copy Markdown

@lunar-shadow lunar-shadow commented Apr 24, 2026

What changes were proposed in this pull request?

This fixes ALTER TABLE ... RENAME TO in V2 catalogs for two cases that weren't handled correctly:

  • When the target name is catalog-qualified
  • When the target is just a table name (no namespace)

Changes:

  • Strip the catalog prefix from the target when it matches the source catalog
  • Inherit source namespace when target is table-only
  • Add tests covering the above cases

Why are the changes needed?

Right now, rename behaves incorrectly in a few scenarios.

For example:

ALTER TABLE testcat.ns.t1 RENAME TO testcat.ns.t2;

fails because asIdentifier treats everything except the last part as the namespace. That means the catalog name (testcat) incorrectly ends up inside the namespace:

Identifier.of(["testcat", "ns"], "t2")

instead of:

Identifier.of(["ns"], "t2")

Similarly:

ALTER TABLE testcat.ns.t1 RENAME TO t2;

creates an identifier with an empty namespace, instead of inheriting ns from the source table.

Steps to reproduce:

CREATE TABLE testcat.ns.t1 USING foo AS SELECT 1 AS id;
ALTER TABLE testcat.ns.t1 RENAME TO testcat.ns.t2;

This fails with a namespace resolution error due to the catalog being treated as part of the namespace.

Does this PR introduce any user-facing change?

Yes.

  • Catalog-qualified renames like ALTER TABLE catalog.ns.t1 RENAME TO catalog.ns.t2 now work correctly
  • Renaming to a table-only name (e.g., RENAME TO t2) now correctly keeps the original namespace
  • Cross-namespace renames (e.g., RENAME TO other_ns.t2) continue to work as before

How was this patch tested?

Added tests in DataSourceV2SQLSuite covering catalog-qualified renames, table-only renames, and cross-namespace renames.

Was this patch authored or co-authored using generative AI tooling?

No

@lunar-shadow lunar-shadow force-pushed the fix/rename-table-with-catalog branch from 669a517 to 8163d49 Compare April 24, 2026 20:04
@lunar-shadow lunar-shadow force-pushed the fix/rename-table-with-catalog branch from 8163d49 to cf3a248 Compare April 25, 2026 05:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant