Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
initial commit
  • Loading branch information
imback82 committed Oct 14, 2019
commit 2fa927a1dbe69ae6bb1b69917e026f66a363305b
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