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

    https://github.com/apache/drill/pull/541#discussion_r71585003
  
    --- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/DropTableIfExistsHandler.java
 ---
    @@ -28,47 +30,57 @@
     import org.apache.drill.exec.physical.PhysicalPlan;
     import org.apache.drill.exec.planner.sql.DirectPlan;
     import org.apache.drill.exec.planner.sql.SchemaUtilites;
    -import org.apache.drill.exec.planner.sql.parser.SqlDropTable;
    +import org.apache.drill.exec.planner.sql.parser.SqlDropTableIfExists;
     import org.apache.drill.exec.store.AbstractSchema;
     
     // SqlHandler for dropping a table.
    -public class DropTableHandler extends DefaultSqlHandler {
    +public class DropTableIfExistsHandler extends DefaultSqlHandler {
     
    -  private static org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(DropTableHandler.class);
    +  private static org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(DropTableIfExistsHandler.class);
     
    -  public DropTableHandler(SqlHandlerConfig config) {
    +  public DropTableIfExistsHandler(SqlHandlerConfig config) {
         super(config);
       }
     
       /**
    -   * Function resolves the schema and invokes the drop method. Raises an 
exception if the schema is
    -   * immutable.
    -   * @param sqlNode - Table name identifier
    -   * @return - Single row indicating drop succeeded, raise exception 
otherwise
    +   * Function resolves the schema and invokes the drop method
    +   * (while IF EXISTS statement is used function invokes the drop method 
only if table exists).
    +   * Raises an exception if the schema is immutable.
    +   * @param sqlNode - SqlDropTableIfExists (SQL parse tree of drop table 
[if exists] query)
    +   * @return - Single row indicating drop succeeded or table is not found 
while IF EXISTS statement is used,
    +   * raise exception otherwise
        * @throws ValidationException
        * @throws RelConversionException
        * @throws IOException
        */
       @Override
       public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, 
RelConversionException, IOException {
     
    -    SqlDropTable dropTableNode = ((SqlDropTable) sqlNode);
    -    SqlIdentifier tableIdentifier = dropTableNode.getTableIdentifier();
    +    SqlDropTableIfExists dropTableIfExistsNode = ((SqlDropTableIfExists) 
sqlNode);
    +    SqlIdentifier tableIdentifier = 
dropTableIfExistsNode.getTableIdentifier();
     
         SchemaPlus defaultSchema = config.getConverter().getDefaultSchema();
         AbstractSchema drillSchema = null;
     
         if (tableIdentifier != null) {
    -      drillSchema = 
SchemaUtilites.resolveToMutableDrillSchema(defaultSchema, 
dropTableNode.getSchema());
    +      drillSchema = 
SchemaUtilites.resolveToMutableDrillSchema(defaultSchema, 
dropTableIfExistsNode.getSchema());
         }
     
    -    String tableName = ((SqlDropTable) sqlNode).getName();
    +    String tableName = dropTableIfExistsNode.getName();
         if (drillSchema == null) {
           throw UserException.validationError()
               .message("Invalid table_name [%s]", tableName)
               .build(logger);
         }
     
    +    if (dropTableIfExistsNode.checkTableExistence()) {
    +      final Table tableToDrop = 
SqlHandlerUtil.getTableFromSchema(drillSchema, tableName);
    +      if (tableToDrop == null || tableToDrop.getJdbcTableType() != 
Schema.TableType.TABLE) {
    --- End diff --
    
    I checked such query `drop table if exists hbase.TestTableNullStr` and 
found that the message is proper and same like for `DROP TABLE` statement: 
`PARSE ERROR: Unable to create or drop tables/views. Schema [hbase] is 
immutable.`.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to