JingsongLi commented on code in PR #11353: URL: https://github.com/apache/paimon/pull/11353#discussion_r4662567273
########## paimon-spark/paimon-spark-4.2/src/main/scala/org/apache/spark/sql/catalyst/parser/extensions/Spark42RewriteCreateTableLike.scala: ########## @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.spark.sql.catalyst.parser.extensions + +import org.apache.spark.sql.SparkSession +import org.apache.spark.sql.catalyst.analysis.{UnresolvedIdentifier, UnresolvedTableOrView} +import org.apache.spark.sql.catalyst.plans.logical.{CreateTableLike, LogicalPlan} +import org.apache.spark.sql.catalyst.rules.Rule +import org.apache.spark.sql.errors.QueryCompilationErrors +import org.apache.spark.sql.internal.HiveSerDe + +/** + * Spark 4.2 parses CREATE TABLE LIKE into the v2 [[CreateTableLike]] plan instead of + * `CreateTableLikeCommand`, so [[RewriteCreateTableLikeCommand]] never sees it. This rule hands the + * same fields to [[RewriteCreateTableLikeCommand.rewrite]]. + */ +case class Spark42RewriteCreateTableLike(spark: SparkSession) extends Rule[LogicalPlan] { + + private lazy val rewriter = RewriteCreateTableLikeCommand(spark) + + override def apply(plan: LogicalPlan): LogicalPlan = plan.resolveOperatorsUp { + case c @ CreateTableLike( + UnresolvedIdentifier(target, _), + source: UnresolvedTableOrView, + location, + provider, + serdeInfo, + properties, + ifNotExists) => + rewriter + .rewrite( + toV1Parts(target), + toV1Parts(source.multipartIdentifier), Review 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. -- 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]
