drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paul-rogers <...@git.apache.org>
Subject [GitHub] drill pull request #666: DRILL-4956: Temporary tables support
Date Tue, 06 Dec 2016 06:12:26 GMT
Github user paul-rogers commented on a diff in the pull request:

    https://github.com/apache/drill/pull/666#discussion_r90697492
  
    --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/DropTableHandler.java
---
    @@ -55,35 +57,48 @@ public DropTableHandler(SqlHandlerConfig config) {
        */
       @Override
       public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, RelConversionException,
IOException {
    -
         SqlDropTable dropTableNode = ((SqlDropTable) sqlNode);
    -    SqlIdentifier tableIdentifier = dropTableNode.getTableIdentifier();
    -
    +    String originalTableName = dropTableNode.getName();
         SchemaPlus defaultSchema = config.getConverter().getDefaultSchema();
    -    AbstractSchema drillSchema = null;
    +    List<String> tableSchema = dropTableNode.getSchema();
     
    -    if (tableIdentifier != null) {
    -      drillSchema = SchemaUtilites.resolveToMutableDrillSchema(defaultSchema, dropTableNode.getSchema());
    -    }
    -
    -    String tableName = dropTableNode.getName();
    -    if (drillSchema == null) {
    -      throw UserException.validationError()
    -          .message("Invalid table_name [%s]", tableName)
    -          .build(logger);
    -    }
    +    boolean removedTemporaryTable = removeTemporaryTable(tableSchema, originalTableName);
    +    if (!removedTemporaryTable) {
    +      AbstractSchema drillSchema = SchemaUtilites.resolveToMutableDrillSchema(defaultSchema,
tableSchema);
    +      if (drillSchema == null) {
    +        throw UserException.validationError().message("Invalid table_name [%s]", originalTableName).build(logger);
    +      }
     
    -    if (dropTableNode.checkTableExistence()) {
    -      final Table tableToDrop = SqlHandlerUtil.getTableFromSchema(drillSchema, tableName);
    +      final Table tableToDrop = SqlHandlerUtil.getTableFromSchema(drillSchema, originalTableName);
           if (tableToDrop == null || tableToDrop.getJdbcTableType() != Schema.TableType.TABLE)
{
    -        return DirectPlan.createDirectPlan(context, true,
    -            String.format("Table [%s] not found", tableName));
    +        if (dropTableNode.checkTableExistence()) {
    +          return DirectPlan.createDirectPlan(context, false, String.format("Table [%s]
not found", originalTableName));
    +        } else {
    +          throw UserException.validationError().message("Table [%s] not found", originalTableName).build(logger);
    +        }
           }
    +      drillSchema.dropTable(originalTableName);
         }
     
    -    drillSchema.dropTable(tableName);
    +    String message = String.format("%s [%s] dropped",
    +            removedTemporaryTable ? "Temporary table" : "Table", originalTableName);
    +    logger.info(message);
    +    return DirectPlan.createDirectPlan(context, true, message);
    +  }
     
    -    return DirectPlan.createDirectPlan(context, true,
    -        String.format("Table [%s] %s", tableName, "dropped"));
    +  /**
    +   * Checks if table aimed to be dropped is temporary table.
    +   * If table is temporary table, it is dropped from schema
    +   * and removed from temporary tables session cache.
    +   *
    +   * @param tableSchema table schema indicated in drop statement
    +   * @param tableName   table name to drop
    +   * @return true if temporary table existed and was dropped, false otherwise
    +   */
    +  private boolean removeTemporaryTable(List<String> tableSchema, String tableName)
{
    --- End diff --
    
    What happens if some other query is running against the table when we attempt to delete
it? Will this delete fail (because the file is open) or will the other query fail (because
the data disappears out from under the reader)? Anything special we have to check to handle
the race condition case?


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