drill-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (DRILL-4673) Implement "DROP TABLE IF EXISTS" for drill to prevent FAILED status on command return
Date Mon, 11 Jul 2016 21:28:11 GMT

    [ https://issues.apache.org/jira/browse/DRILL-4673?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15371670#comment-15371670
] 

ASF GitHub Bot commented on DRILL-4673:
---------------------------------------

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

    https://github.com/apache/drill/pull/541#discussion_r70340564
  
    --- 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 --
    
    Looks like `HbaseSchema#getTable` throws a TableNotFoundException instead of returning
`null` when table does not exist.
    
    I am not sure other schema return `null` when table does not exist.


> Implement "DROP TABLE IF EXISTS" for drill to prevent FAILED status on command return
> -------------------------------------------------------------------------------------
>
>                 Key: DRILL-4673
>                 URL: https://issues.apache.org/jira/browse/DRILL-4673
>             Project: Apache Drill
>          Issue Type: New Feature
>          Components: Functions - Drill
>            Reporter: Vitalii Diravka
>            Assignee: Vitalii Diravka
>            Priority: Minor
>              Labels: drill
>
> Implement "DROP TABLE IF EXISTS" for drill to prevent FAILED status on command "DROP
TABLE" return if table doesn't exist.
> The same for "DROP VIEW IF EXISTS"



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message