Skip to content

Commit

Permalink
[SPARK-22686][SQL] DROP TABLE IF EXISTS should not show AnalysisExcep…
Browse files Browse the repository at this point in the history
…tion

## What changes were proposed in this pull request?

During [SPARK-22488](#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 <dongjoon@apache.org>

Closes #19888 from dongjoon-hyun/SPARK-22686.
  • Loading branch information
dongjoon-hyun authored and cloud-fan committed Dec 6, 2017
1 parent 59aa3d5 commit 82183f7
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,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]
}
}
Expand Down

0 comments on commit 82183f7

Please sign in to comment.