Repository: spark Updated Branches: refs/heads/branch-2.2 5b6300007 -> 7fd6d535d
[SPARK-22686][SQL] DROP TABLE IF EXISTS should not show AnalysisException ## What changes were proposed in this pull request? During [SPARK-22488](https://github.com/apache/spark/pull/19713) to fix view resolution issue, there occurs a regression at `2.2.1` and `master` branch like the following. This PR fixes that. ```scala scala> spark.version res2: String = 2.2.1 scala> sql("DROP TABLE IF EXISTS t").show 17/12/04 21:01:06 WARN DropTableCommand: org.apache.spark.sql.AnalysisException: Table or view not found: t; org.apache.spark.sql.AnalysisException: Table or view not found: t; ``` ## How was this patch tested? Manual. Author: Dongjoon Hyun <dongj...@apache.org> Closes #19888 from dongjoon-hyun/SPARK-22686. (cherry picked from commit 82183f7b57f2a93e646c56a9e37fac64b348ff0b) Signed-off-by: Wenchen Fan <wenc...@databricks.com> Project: http://git-wip-us.apache.org/repos/asf/spark/repo Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/7fd6d535 Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/7fd6d535 Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/7fd6d535 Branch: refs/heads/branch-2.2 Commit: 7fd6d535d3e9a33c7e4d2eb14405ec29edd1682a Parents: 5b63000 Author: Dongjoon Hyun <dongj...@apache.org> Authored: Wed Dec 6 10:52:29 2017 +0800 Committer: Wenchen Fan <wenc...@databricks.com> Committed: Wed Dec 6 10:53:07 2017 +0800 ---------------------------------------------------------------------- .../spark/sql/execution/command/ddl.scala | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/spark/blob/7fd6d535/sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala ---------------------------------------------------------------------- diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala index b1eaecb..62ca018 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala @@ -199,14 +199,20 @@ case class DropTableCommand( case _ => } } - try { - sparkSession.sharedState.cacheManager.uncacheQuery(sparkSession.table(tableName)) - } catch { - case _: NoSuchTableException if ifExists => - case NonFatal(e) => log.warn(e.toString, e) + + if (catalog.isTemporaryTable(tableName) || catalog.tableExists(tableName)) { + try { + sparkSession.sharedState.cacheManager.uncacheQuery(sparkSession.table(tableName)) + } catch { + case NonFatal(e) => log.warn(e.toString, e) + } + catalog.refreshTable(tableName) + catalog.dropTable(tableName, ifExists, purge) + } else if (ifExists) { + // no-op + } else { + throw new AnalysisException(s"Table or view not found: ${tableName.identifier}") } - catalog.refreshTable(tableName) - catalog.dropTable(tableName, ifExists, purge) Seq.empty[Row] } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org