Repository navigation
[spark] Fix CREATE TABLE LIKE on Spark 4.2/4.3 and its catalog resolution on 3.4+ - #11353
LuciferYang wants to merge 2 commits into
Conversation
JingsongLi
left a comment
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
[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.
There was a problem hiding this comment.
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.
Purpose
Fixes #11351. Spark 4.2 (SPARK-33902) parses CREATE TABLE LIKE into the v2
CreateTableLike, whichRewriteCreateTableLikeCommanddoes not rewrite. It fails with "paimon does not support CREATE TABLE LIKE", or, for aSparkGenericCatalogtarget withUSING paimonand a non-Paimon source, creates a table Paimon cannot read.A parser rule in the Spark 4.2 module, shared with 4.3, passes
CreateTableLiketo the same rewrite. On 3.4 to 4.1, Paimon's grammar fallback passes the names as written, not as a v1TableIdentifier.ext.outer.inner.srckeeps its nested namespace.Tests
The Spark 4.2 module now runs the shared
DDLTestBase,DDLWithHiveCatalogTestBaseandCatalogQualifiedCreateTableLikeTest, 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 throughSparkCatalogandSparkGenericCatalog.