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 Thu, 05 Jan 2017 02:34:21 GMT
Github user paul-rogers commented on a diff in the pull request:

    https://github.com/apache/drill/pull/666#discussion_r94701739
  
    --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/DropTableHandler.java
---
    @@ -55,35 +58,79 @@ 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();
    +
    +    boolean removedTemporaryTable = removeTemporaryTable(defaultSchema, tableSchema,
originalTableName);
    +    // if table to be dropped is not temporary table, we need to check among persistent
tables or views
    +    if (!removedTemporaryTable) {
    +      AbstractSchema drillSchema = SchemaUtilites.resolveToMutableDrillSchema(defaultSchema,
tableSchema);
    +      Table tableToDrop = SqlHandlerUtil.getTableFromSchema(drillSchema, originalTableName);
    +      if (tableToDrop == null || tableToDrop.getJdbcTableType() != Schema.TableType.TABLE)
{
    +        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);
    +        }
    +      }
     
    -    if (tableIdentifier != null) {
    -      drillSchema = SchemaUtilites.resolveToMutableDrillSchema(defaultSchema, dropTableNode.getSchema());
    +      try {
    +        drillSchema.dropTable(originalTableName);
    +      } catch (Exception e) {
    +        // concurrency check: we might have failed because somebody has already dropped
the table
    +        if (SqlHandlerUtil.getTableFromSchema(drillSchema, originalTableName) != null)
{
    +          throw e;
    +        }
    +      }
         }
     
    -    String tableName = dropTableNode.getName();
    -    if (drillSchema == null) {
    -      throw UserException.validationError()
    -          .message("Invalid table_name [%s]", tableName)
    -          .build(logger);
    +    String message = String.format("%s [%s] dropped",
    +        removedTemporaryTable ? "Temporary table" : "Table", originalTableName);
    +    logger.info(message);
    +    return DirectPlan.createDirectPlan(context, true, message);
    +  }
    +
    +  /**
    +   * If used workspace is default temporary workspace and temporary table is found,
    +   * drops the table and removes it from session temporary tables list.
    +   *
    +   * @param defaultSchema default schema
    +   * @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(SchemaPlus defaultSchema, List<String> tableSchema,
String tableName) {
    +    String temporaryWorkspace = context.getConfig().getString(ExecConstants.DEFAULT_TEMPORARY_WORKSPACE);
    +
    +    // look for temporary table only if default temporary workspace is used
    +    if (!(tableSchema.isEmpty() || SchemaUtilites.getSchemaPath(tableSchema).equals(temporaryWorkspace)))
{
    --- End diff --
    
    This same logic appears several times. Can it be factored out to the `SchemaUtilities`
class?
    
    ```
    boolean isTemporaryTable(List<String> tableSchema, DrillConfig config) {
    ...
    ```


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