-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-28301][SQL] fix the behavior of table name resolution with multi-catalog #25077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * 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.catalog | ||
|
|
||
| import scala.collection.mutable | ||
|
|
||
| import org.apache.spark.sql.catalog.v2.{CatalogPlugin, Catalogs} | ||
| import org.apache.spark.sql.internal.SQLConf | ||
|
|
||
| /** | ||
| * A thread-safe manager for [[CatalogPlugin]]s. It tracks all the registered catalogs, and allow | ||
| * the caller to look up a catalog by name. | ||
| */ | ||
| class CatalogManager(conf: SQLConf) { | ||
|
|
||
| /** | ||
| * Tracks all the registered catalogs. | ||
| */ | ||
| private val catalogs = mutable.HashMap.empty[String, CatalogPlugin] | ||
|
|
||
| /** | ||
| * Looks up a catalog by name. | ||
| */ | ||
| def getCatalog(name: String): CatalogPlugin = synchronized { | ||
| catalogs.getOrElseUpdate(name, Catalogs.load(name, conf)) | ||
| } | ||
|
|
||
| def getDefaultCatalog(): Option[CatalogPlugin] = { | ||
| conf.defaultV2Catalog.map(getCatalog) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -181,29 +181,32 @@ case class CreateViewCommand( | |
| * Permanent views are not allowed to reference temp objects, including temp function and views | ||
| */ | ||
| private def verifyTemporaryObjectsNotExists(sparkSession: SparkSession): Unit = { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for the sake of consistency, I think it'd be better to use either |
||
| import sparkSession.sessionState.analyzer.AsTableIdentifier | ||
|
|
||
| if (!isTemporary) { | ||
| // This func traverses the unresolved plan `child`. Below are the reasons: | ||
| // 1) Analyzer replaces unresolved temporary views by a SubqueryAlias with the corresponding | ||
| // logical plan. After replacement, it is impossible to detect whether the SubqueryAlias is | ||
| // added/generated from a temporary view. | ||
| // 2) The temp functions are represented by multiple classes. Most are inaccessible from this | ||
| // package (e.g., HiveGenericUDF). | ||
| child.collect { | ||
| child.foreach { | ||
| // Disallow creating permanent views based on temporary views. | ||
| case UnresolvedRelation(AsTableIdentifier(ident)) | ||
| if sparkSession.sessionState.catalog.isTemporaryTable(ident) => | ||
| // temporary views are only stored in the session catalog | ||
| throw new AnalysisException(s"Not allowed to create a permanent view $name by " + | ||
| s"referencing a temporary view $ident") | ||
| case UnresolvedRelation(parts) => | ||
| // The `DataSourceResolution` rule guarantees this. | ||
| assert(parts.nonEmpty && parts.length <= 2) | ||
| val tblIdent = TableIdentifier(parts) | ||
| if (sparkSession.sessionState.catalog.isTemporaryTable(tblIdent)) { | ||
| // temporary views are only stored in the session catalog | ||
| throw new AnalysisException(s"Not allowed to create a permanent view $name by " + | ||
| s"referencing a temporary view $tblIdent") | ||
| } | ||
| case other if !other.resolved => other.expressions.flatMap(_.collect { | ||
| // Disallow creating permanent views based on temporary UDFs. | ||
| case e: UnresolvedFunction | ||
| if sparkSession.sessionState.catalog.isTemporaryFunction(e.name) => | ||
| throw new AnalysisException(s"Not allowed to create a permanent view $name by " + | ||
| s"referencing a temporary function `${e.name}`") | ||
| }) | ||
| case _ => | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it'd be better to add a comment like |
||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed anymore because in #24741 we delay the error reporting of unresolved relation to
CheckAnalysis