Skip to content

Commit 51966bc

Browse files
committed
Merge with [SPARK-29039][SQL] centralize the catalog and table lookup logic
1 parent fece0a0 commit 51966bc

File tree

3 files changed

+8
-19
lines changed

3 files changed

+8
-19
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveCatalogs.scala

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,11 @@ class ResolveCatalogs(val catalogManager: CatalogManager)
165165
s"Can not specify catalog `${catalog.name}` for view ${viewName.quoted} " +
166166
s"because view support in catalog has not been implemented yet")
167167

168-
case ShowNamespacesStatement(Some(NonSessionCatalog(catalog, nameParts)), pattern) =>
169-
val namespace = if (nameParts.isEmpty) None else Some(nameParts)
168+
case ShowNamespacesStatement(Some(CurrentCatalogAndNamespace(catalog, namespace)), pattern) =>
170169
ShowNamespaces(catalog.asNamespaceCatalog, namespace, pattern)
171170

172-
// TODO (SPARK-29014): we should check if the current catalog is not session catalog here.
173-
case ShowNamespacesStatement(None, pattern) if defaultCatalog.isDefined =>
174-
ShowNamespaces(defaultCatalog.get.asNamespaceCatalog, None, pattern)
171+
case ShowNamespacesStatement(None, pattern) =>
172+
ShowNamespaces(currentCatalog.asNamespaceCatalog, None, pattern)
175173

176174
case ShowTablesStatement(Some(NonSessionCatalog(catalog, nameParts)), pattern) =>
177175
ShowTables(catalog.asTableCatalog, nameParts, pattern)
@@ -185,8 +183,7 @@ class ResolveCatalogs(val catalogManager: CatalogManager)
185183
SetCatalogAndNamespace(catalogManager, None, Some(nameParts))
186184
} else {
187185
val CurrentCatalogAndNamespace(catalog, namespace) = nameParts
188-
val ns = if (namespace.isEmpty) { None } else { Some(namespace) }
189-
SetCatalogAndNamespace(catalogManager, Some(catalog.name()), ns)
186+
SetCatalogAndNamespace(catalogManager, Some(catalog.name()), namespace)
190187
}
191188
}
192189

sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/LookupCatalog.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private[sql] trait LookupCatalog extends Logging {
102102
}
103103
}
104104

105-
type CurrentCatalogAndNamespace = (CatalogPlugin, Seq[String])
105+
type CurrentCatalogAndNamespace = (CatalogPlugin, Option[Seq[String]])
106106

107107
/**
108108
* Extract catalog and namespace from a multi-part identifier with the current catalog if needed.
@@ -112,10 +112,11 @@ private[sql] trait LookupCatalog extends Logging {
112112
def unapply(parts: Seq[String]): Some[CurrentCatalogAndNamespace] = parts match {
113113
case Seq(catalogName, tail @ _*) =>
114114
try {
115-
Some((catalogManager.catalog(catalogName), tail))
115+
Some(
116+
(catalogManager.catalog(catalogName), if (tail.isEmpty) { None } else { Some(tail) }))
116117
} catch {
117118
case _: CatalogNotFoundException =>
118-
Some((currentCatalog, parts))
119+
Some((currentCatalog, Some(parts)))
119120
}
120121
}
121122
}

sql/core/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveSessionCatalog.scala

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,6 @@ class ResolveSessionCatalog(
256256
case DropViewStatement(SessionCatalog(catalog, viewName), ifExists) =>
257257
DropTableCommand(viewName.asTableIdentifier, ifExists, isView = true, purge = false)
258258

259-
case ShowNamespacesStatement(Some(SessionCatalog(catalog, nameParts)), pattern) =>
260-
throw new AnalysisException(
261-
"SHOW NAMESPACES is not supported with the session catalog.")
262-
263-
// TODO (SPARK-29014): we should check if the current catalog is session catalog here.
264-
case ShowNamespacesStatement(None, pattern) if defaultCatalog.isEmpty =>
265-
throw new AnalysisException(
266-
"SHOW NAMESPACES is not supported with the session catalog.")
267-
268259
case ShowTablesStatement(Some(SessionCatalog(catalog, nameParts)), pattern) =>
269260
if (nameParts.length != 1) {
270261
throw new AnalysisException(

0 commit comments

Comments
 (0)