Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.spark.sql.execution.command

import scala.util.control.NonFatal

import org.apache.spark.internal.Logging
import org.apache.spark.sql.{AnalysisException, Row, SQLContext}
import org.apache.spark.sql.catalyst.TableIdentifier
Expand Down Expand Up @@ -191,31 +193,31 @@ case class DropTable(

override def run(sqlContext: SQLContext): Seq[Row] = {
val catalog = sqlContext.sessionState.catalog
// If the command DROP VIEW is to drop a table or DROP TABLE is to drop a view
// issue an exception.
catalog.getTableMetadataOption(tableName).map(_.tableType match {
case CatalogTableType.VIRTUAL_VIEW if !isView =>
throw new AnalysisException(
"Cannot drop a view with DROP TABLE. Please use DROP VIEW instead")
case o if o != CatalogTableType.VIRTUAL_VIEW && isView =>
throw new AnalysisException(
s"Cannot drop a table with DROP VIEW. Please use DROP TABLE instead")
case _ =>
})

try {
sqlContext.cacheManager.tryUncacheQuery(sqlContext.table(tableName.quotedString))
} catch {
// This table's metadata is not in Hive metastore (e.g. the table does not exist).
case e if e.getClass.getName == "org.apache.hadoop.hive.ql.metadata.InvalidTableException" =>
case _: org.apache.spark.sql.catalyst.analysis.NoSuchTableException =>
// Other Throwables can be caused by users providing wrong parameters in OPTIONS
// (e.g. invalid paths). We catch it and log a warning message.
// Users should be able to drop such kinds of tables regardless if there is an error.
case e: Throwable => log.warn(s"${e.getMessage}", e)
if (!catalog.tableExists(tableName)) {
if (!ifExists) {
val objectName = if (isView) "View" else "Table"
logError(s"$objectName '${tableName.quotedString}' does not exist")
}
} else {
// If the command DROP VIEW is to drop a table or DROP TABLE is to drop a view
// issue an exception.
catalog.getTableMetadataOption(tableName).map(_.tableType match {
case CatalogTableType.VIRTUAL_VIEW if !isView =>
throw new AnalysisException(
"Cannot drop a view with DROP TABLE. Please use DROP VIEW instead")
case o if o != CatalogTableType.VIRTUAL_VIEW && isView =>
throw new AnalysisException(
s"Cannot drop a table with DROP VIEW. Please use DROP TABLE instead")
case _ =>
})
try {
sqlContext.cacheManager.tryUncacheQuery(sqlContext.table(tableName.quotedString))
} catch {
case NonFatal(e) => log.warn(s"${e.getMessage}", e)
}
catalog.invalidateTable(tableName)
catalog.dropTable(tableName, ifExists)
}
catalog.invalidateTable(tableName)
catalog.dropTable(tableName, ifExists)
Seq.empty[Row]
}
}
Expand Down