Skip to content

[spark] Fix CREATE TABLE LIKE on Spark 4.2/4.3 and its catalog resolution on 3.4+ - #11353

Open
LuciferYang wants to merge 2 commits into
apache:masterfrom
LuciferYang:spark42-create-table-like
Open

LuciferYang wants to merge 2 commits into
apache:masterfrom
LuciferYang:spark42-create-table-like

Conversation

@LuciferYang

@LuciferYang LuciferYang commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Fixes #11351. Spark 4.2 (SPARK-33902) parses CREATE TABLE LIKE into the v2 CreateTableLike, which RewriteCreateTableLikeCommand does not rewrite. It fails with "paimon does not support CREATE TABLE LIKE", or, for a SparkGenericCatalog target with USING paimon and a non-Paimon source, creates a table Paimon cannot read.

A parser rule in the Spark 4.2 module, shared with 4.3, passes CreateTableLike to the same rewrite. On 3.4 to 4.1, Paimon's grammar fallback passes the names as written, not as a v1 TableIdentifier.

  • A name of more than three parts is joined into one database only for a Paimon catalog, so ext.outer.inner.src keeps its nested namespace.
  • On 3.4 to 4.1, a non-Paimon target needs both tables in the session catalog. A table of another catalog was read or created there.
  • A temporary view as the source of a Paimon target fails. On 3.4 to 4.1 it copied a same-named table.

Tests

The Spark 4.2 module now runs the shared DDLTestBase, DDLWithHiveCatalogTestBase and CatalogQualifiedCreateTableLikeTest, which the spark42 and spark43 lanes did not run. New shared tests cover a nested source namespace in another V2 catalog, a target or source in another catalog, both tables in the session catalog, and a temporary view source through SparkCatalog and SparkGenericCatalog.

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The three submitted DDL suites passed 70 tests on Spark 4.2.1 and 70 on Spark 4.3.0. The cross-catalog SQL case below reproduced on both. I also checked the Spark 3 / Scala 2.13 CI artifact. The CREATE TABLE LIKE cases passed where active, and the two failures were Spark 3.2 interrupted CTAS tests waiting for input tasks.

rewriter
.rewrite(
toV1Parts(target),
toV1Parts(source.multipartIdentifier),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Preserve multipart source namespaces from other catalogs. On Spark 4.2.1 and 4.3.0 I created external.outer.inner.source with intended INT and external.outer.inner.source with wrong STRING in a Spark V2 catalog. Normal table resolution distinguishes the two. CREATE TABLE paimon.demo.target LIKE external.outer.inner.source USING paimon silently copied wrong STRING. The rewrite collapses outer and inner before it knows which catalog will load the source. Keep the namespace parts for ordinary V2 source catalogs and apply Paimon's dotted-database conversion only when resolving a Paimon identifier.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. RewriteCreateTableLikeCommand resolves the catalog with CatalogAndIdentifier first. It joins the middle parts into one namespace part only when the name has more than three parts and resolves to SparkCatalog or SparkGenericCatalog; any other catalog gets the namespace parts as written. Spark42RewriteCreateTableLike passes the parsed parts through, and toV1Parts is removed.

Spark 3.4 to 4.1 had the same problem in Paimon's grammar fallback, which built a v1 TableIdentifier. It now passes the parts as written to the same rewrite. Your case is a test in the shared CatalogQualifiedCreateTableLikeTest, with Spark's InMemoryTableCatalog registered as external; without the fix it copies the wrong column on 3.5, 4.1 and 4.2.

@LuciferYang LuciferYang changed the title [spark] Fix CREATE TABLE LIKE on Spark 4.2 and 4.3 [spark] Fix CREATE TABLE LIKE on Spark 4.2/4.3 and its catalog resolution on 3.4+ Nov 23, 2026
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.

[Bug] CREATE TABLE LIKE fails on Spark 4.2 and 4.3

2 participants