cloud-fan commented on code in PR #36586: URL: https://github.com/apache/spark/pull/36586#discussion_r875384403
########## sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala: ########## @@ -97,8 +97,15 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog { */ @throws[AnalysisException]("database does not exist") override def listTables(dbName: String): Dataset[Table] = { - val tables = sessionCatalog.listTables(dbName).map(makeTable) - CatalogImpl.makeDataset(tables, sparkSession) + if (sessionCatalog.databaseExists(dbName)) { + val tables = sessionCatalog.listTables(dbName).map(makeTable) + CatalogImpl.makeDataset(tables, sparkSession) + } else { + val multiParts = sparkSession.sessionState.sqlParser.parseMultipartIdentifier(dbName) + val plan = ShowTables(UnresolvedNamespace(multiParts), None) + val ret = sparkSession.sessionState.executePlan(plan).toRdd.collect() + CatalogImpl.makeDataset(Seq(), sparkSession) Review Comment: first, check if the name is a temp view or nor, then, get `TableCatalog` by catalog name and call `loadTable` ########## sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala: ########## @@ -97,8 +97,15 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog { */ @throws[AnalysisException]("database does not exist") override def listTables(dbName: String): Dataset[Table] = { - val tables = sessionCatalog.listTables(dbName).map(makeTable) - CatalogImpl.makeDataset(tables, sparkSession) + if (sessionCatalog.databaseExists(dbName)) { + val tables = sessionCatalog.listTables(dbName).map(makeTable) + CatalogImpl.makeDataset(tables, sparkSession) + } else { + val multiParts = sparkSession.sessionState.sqlParser.parseMultipartIdentifier(dbName) + val plan = ShowTables(UnresolvedNamespace(multiParts), None) + val ret = sparkSession.sessionState.executePlan(plan).toRdd.collect() + CatalogImpl.makeDataset(Seq(), sparkSession) Review Comment: first, check if the name is a temp view or not, then, get `TableCatalog` by catalog name and call `loadTable` -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org