Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/12146#discussion_r59095742
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala ---
    @@ -176,12 +176,70 @@ case class DescribeDatabase(
     }
     
     /**
    + * Drops a table/view from the metastore and removes it if it is cached.
    + *
    + * The syntax of this command is:
    + * {{{
    + *   DROP TABLE [IF EXISTS] table_name [PURGE] [FOR REPLICATION(event_id)];
    + *   DROP VIEW [IF EXISTS] [db_name.]view_name;
    + * }}}
    + *
    + * Note, PURGE and replication clauses are not supported
    + */
    +case class DropTable(
    +    tableName: TableIdentifier,
    +    ifExists: Boolean,
    +    isView: Boolean) extends RunnableCommand {
    +
    +  override def run(sqlContext: SQLContext): Seq[Row] = {
    +    val catalog = sqlContext.sessionState.catalog
    +    if (isView && !catalog.isViewSupported) {
    +      throw new AnalysisException(s"Not supported object: views")
    +    }
    +    // If the command DROP VIEW is to drop a table or DROP TABLE is to 
drop a view
    +    // issue an exception.
    +    catalog.getTableOption(tableName).map(_.tableType match {
    +      case CatalogTableType.VIRTUAL_VIEW if !isView =>
    +        throw new AnalysisException(s"Cannot drop a view with DROP TABLE")
    +      case o if o != CatalogTableType.VIRTUAL_VIEW && isView =>
    +        throw new AnalysisException(s"Cannot drop a table with DROP VIEW")
    +      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)
    +    }
    +    catalog.invalidateTable(tableName)
    +
    +    try {
    +      catalog.dropTable(tableName, ifExists)
    +    } catch {
    +      // Quiesce the exception issued from Hive. Log it as an error message
    +      // This is just to make it consistent with Hive Native Command; 
Otherwise, many test cases
    +      // in HiveCompatibilitySuite fail. In Hive, the orders of test cases 
matter. That is, the
    +      // test cases are not independent.
    +      case e: org.apache.spark.sql.AnalysisException
    +        if e.getMessage.contains("NoSuchObjectException") => 
logError(s"${e.getMessage}", e)
    --- End diff --
    
    Yeah, the existing behavior does not issue an exception. Without this PR, 
you can run the following test cases in `HiveContext`:
    ```
      test("drop tables") {
          sql("DROP TABLE tab1")
          sql("DROP TABLE tab1")
      }
    ```
    `tab1` does not exist. We will not issue any exception. Only error messages.


---
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]

Reply via email to