Github user jiangxb1987 commented on a diff in the pull request:
https://github.com/apache/spark/pull/14897#discussion_r81112745
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala
---
@@ -472,27 +557,48 @@ class SessionCatalog(
* explicitly specified.
*/
def isTemporaryTable(name: TableIdentifier): Boolean = synchronized {
- name.database.isEmpty &&
tempTables.contains(formatTableName(name.table))
+ val table = formatTableName(name.table)
+ if (name.database.isEmpty) {
+ tempTables.contains(table)
+ } else if (formatDatabaseName(name.database.get) ==
globalTempViewManager.database) {
+ globalTempViewManager.get(table).isDefined
+ } else {
+ false
+ }
}
/**
- * List all tables in the specified database, including temporary tables.
+ * List all tables in the specified database, including local temporary
tables.
+ *
+ * Note that, if the specified database is global temporary view
database, we will list global
+ * temporary views.
*/
def listTables(db: String): Seq[TableIdentifier] = listTables(db, "*")
/**
- * List all matching tables in the specified database, including
temporary tables.
+ * List all matching tables in the specified database, including local
temporary tables.
+ *
+ * Note that, if the specified database is global temporary view
database, we will list global
+ * temporary views.
*/
def listTables(db: String, pattern: String): Seq[TableIdentifier] = {
val dbName = formatDatabaseName(db)
- requireDbExists(dbName)
- val dbTables =
- externalCatalog.listTables(dbName, pattern).map { t =>
TableIdentifier(t, Some(dbName)) }
- synchronized {
- val _tempTables = StringUtils.filterPattern(tempTables.keys.toSeq,
pattern)
- .map { t => TableIdentifier(t) }
- dbTables ++ _tempTables
+ val dbTables = if (dbName == globalTempViewManager.database) {
+ globalTempViewManager.listViewNames(pattern).map { name =>
+ TableIdentifier(name, Some(globalTempViewManager.database))
+ }
+ } else {
+ requireDbExists(dbName)
+ externalCatalog.listTables(dbName, pattern).map { name =>
+ TableIdentifier(name, Some(dbName))
+ }
+ }
+ val localTempViews = synchronized {
+ StringUtils.filterPattern(tempTables.keys.toSeq, pattern).map { name
=>
+ TableIdentifier(name)
+ }
}
+ dbTables ++ localTempViews
--- End diff --
Why we should move this line out of the `synchronized` block?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]