aboutsummaryrefslogtreecommitdiff
path: root/sql/catalyst/src/main/scala/org/apache
diff options
context:
space:
mode:
authorWenchen Fan <wenchen@databricks.com>2016-09-22 12:52:09 +0800
committerWenchen Fan <wenchen@databricks.com>2016-09-22 12:52:09 +0800
commitb50b34f5611a1f182ba9b6eaf86c666bbd9f9eb0 (patch)
tree1097e32b1e9aac12f7166dae9d5cb88f363abad2 /sql/catalyst/src/main/scala/org/apache
parent8bde03bf9a0896ea59ceaa699df7700351a130fb (diff)
downloadspark-b50b34f5611a1f182ba9b6eaf86c666bbd9f9eb0.tar.gz
spark-b50b34f5611a1f182ba9b6eaf86c666bbd9f9eb0.tar.bz2
spark-b50b34f5611a1f182ba9b6eaf86c666bbd9f9eb0.zip
[SPARK-17609][SQL] SessionCatalog.tableExists should not check temp view
## What changes were proposed in this pull request? After #15054 , there is no place in Spark SQL that need `SessionCatalog.tableExists` to check temp views, so this PR makes `SessionCatalog.tableExists` only check permanent table/view and removes some hacks. This PR also improves the `getTempViewOrPermanentTableMetadata` that is introduced in #15054 , to make the code simpler. ## How was this patch tested? existing tests Author: Wenchen Fan <wenchen@databricks.com> Closes #15160 from cloud-fan/exists.
Diffstat (limited to 'sql/catalyst/src/main/scala/org/apache')
-rw-r--r--sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala70
1 files changed, 34 insertions, 36 deletions
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala
index ef29c75c01..8c01c7a3f2 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala
@@ -246,6 +246,16 @@ class SessionCatalog(
}
/**
+ * Return whether a table/view with the specified name exists. If no database is specified, check
+ * with current database.
+ */
+ def tableExists(name: TableIdentifier): Boolean = synchronized {
+ val db = formatDatabaseName(name.database.getOrElse(currentDb))
+ val table = formatTableName(name.table)
+ externalCatalog.tableExists(db, table)
+ }
+
+ /**
* Retrieve the metadata of an existing permanent table/view. If no database is specified,
* assume the table/view is in the current database. If the specified table/view is not found
* in the database then a [[NoSuchTableException]] is thrown.
@@ -271,24 +281,6 @@ class SessionCatalog(
}
/**
- * Retrieve the metadata of an existing temporary view or permanent table/view.
- * If the temporary view does not exist, tries to get the metadata an existing permanent
- * table/view. If no database is specified, assume the table/view is in the current database.
- * If the specified table/view is not found in the database then a [[NoSuchTableException]] is
- * thrown.
- */
- def getTempViewOrPermanentTableMetadata(name: String): CatalogTable = synchronized {
- val table = formatTableName(name)
- getTempView(table).map { plan =>
- CatalogTable(
- identifier = TableIdentifier(table),
- tableType = CatalogTableType.VIEW,
- storage = CatalogStorageFormat.empty,
- schema = plan.output.toStructType)
- }.getOrElse(getTableMetadata(TableIdentifier(name)))
- }
-
- /**
* Load files stored in given path into an existing metastore table.
* If no database is specified, assume the table is in the current database.
* If the specified table is not found in the database then a [[NoSuchTableException]] is thrown.
@@ -369,6 +361,30 @@ class SessionCatalog(
// -------------------------------------------------------------
/**
+ * Retrieve the metadata of an existing temporary view or permanent table/view.
+ *
+ * If a database is specified in `name`, this will return the metadata of table/view in that
+ * database.
+ * If no database is specified, this will first attempt to get the metadata of a temporary view
+ * with the same name, then, if that does not exist, return the metadata of table/view in the
+ * current database.
+ */
+ def getTempViewOrPermanentTableMetadata(name: TableIdentifier): CatalogTable = synchronized {
+ val table = formatTableName(name.table)
+ if (name.database.isDefined) {
+ getTableMetadata(name)
+ } else {
+ getTempView(table).map { plan =>
+ CatalogTable(
+ identifier = TableIdentifier(table),
+ tableType = CatalogTableType.VIEW,
+ storage = CatalogStorageFormat.empty,
+ schema = plan.output.toStructType)
+ }.getOrElse(getTableMetadata(name))
+ }
+ }
+
+ /**
* Rename a table.
*
* If a database is specified in `oldName`, this will rename the table in that database.
@@ -450,24 +466,6 @@ class SessionCatalog(
}
/**
- * Return whether a table/view with the specified name exists.
- *
- * Note: If a database is explicitly specified, then this will return whether the table/view
- * exists in that particular database instead. In that case, even if there is a temporary
- * table with the same name, we will return false if the specified database does not
- * contain the table/view.
- */
- def tableExists(name: TableIdentifier): Boolean = synchronized {
- val db = formatDatabaseName(name.database.getOrElse(currentDb))
- val table = formatTableName(name.table)
- if (isTemporaryTable(name)) {
- true
- } else {
- externalCatalog.tableExists(db, table)
- }
- }
-
- /**
* Return whether a table with the specified name is a temporary table.
*
* Note: The temporary table cache is checked only when database is not