Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,8 @@ class ResolveCatalogs(val catalogManager: CatalogManager)
case ShowTablesStatement(Some(NonSessionCatalog(catalog, nameParts)), pattern) =>
ShowTables(catalog.asTableCatalog, nameParts, pattern)

// TODO (SPARK-29014): we should check if the current catalog is not session catalog here.
case ShowTablesStatement(None, pattern) if defaultCatalog.isDefined =>
ShowTables(defaultCatalog.get.asTableCatalog, catalogManager.currentNamespace, pattern)
case ShowTablesStatement(None, pattern) if !isSessionCatalog(currentCatalog) =>
ShowTables(currentCatalog.asTableCatalog, catalogManager.currentNamespace, pattern)

case UseStatement(isNamespaceSet, nameParts) =>
if (isNamespaceSet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ private[sql] trait LookupCatalog extends Logging {
Some((catalogManager.catalog(nameParts.head), nameParts.tail))
} catch {
case _: CatalogNotFoundException =>
// TODO (SPARK-29014): use current catalog here.
Some((defaultCatalog.getOrElse(sessionCatalog), nameParts))
Some((currentCatalog, nameParts))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,7 @@ class ResolveSessionCatalog(
}
ShowTablesCommand(Some(nameParts.head), pattern)

// TODO (SPARK-29014): we should check if the current catalog is session catalog here.
case ShowTablesStatement(None, pattern) if defaultCatalog.isEmpty =>
case ShowTablesStatement(None, pattern) if isSessionCatalog(currentCatalog) =>
ShowTablesCommand(None, pattern)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,23 @@ class DataSourceV2SQLSuite
expectV2Catalog = false)
}

test("ShowTables: change current catalog and namespace with USE statements") {
sql("CREATE TABLE testcat.ns1.ns2.table (id bigint) USING foo")

// Initially, the v2 session catalog (current catalog) is used.
runShowTablesSql(
"SHOW TABLES", Seq(Row("", "source", true), Row("", "source2", true)),
expectV2Catalog = false)

// Update the current catalog, and no table is matched since the current namespace is Array().
sql("USE testcat")
runShowTablesSql("SHOW TABLES", Seq())

// Update the current namespace to match ns1.ns2.table.
sql("USE testcat.ns1.ns2")
runShowTablesSql("SHOW TABLES", Seq(Row("ns1.ns2", "table")))
}

private def runShowTablesSql(
sqlText: String,
expected: Seq[Row],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class PlanResolutionSuite extends AnalysisTest {
throw new CatalogNotFoundException(s"No such catalog: $name")
}
})
when(manager.currentCatalog).thenReturn(testCat)
when(manager.defaultCatalog).thenReturn(Some(testCat))
Comment thread
imback82 marked this conversation as resolved.
Outdated
when(manager.v2SessionCatalog).thenReturn(v2SessionCatalog)
when(manager.v1SessionCatalog).thenReturn(v1SessionCatalog)
Expand All @@ -112,6 +113,7 @@ class PlanResolutionSuite extends AnalysisTest {
throw new CatalogNotFoundException(s"No such catalog: $name")
}
})
when(manager.currentCatalog).thenReturn(v2SessionCatalog)
when(manager.defaultCatalog).thenReturn(None)
when(manager.v2SessionCatalog).thenReturn(v2SessionCatalog)
when(manager.v1SessionCatalog).thenReturn(v1SessionCatalog)
Expand Down