drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sudheeshkatkam <...@git.apache.org>
Subject [GitHub] drill pull request #541: DRILL-4673: Implement "DROP TABLE IF EXISTS" for dr...
Date Mon, 11 Jul 2016 21:27:54 GMT
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.


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

Mime
View raw message