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:33:58 GMT
Github user paul-rogers commented on a diff in the pull request:

    https://github.com/apache/drill/pull/666#discussion_r94690087
  
    --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/CreateTableHandler.java
---
    @@ -242,4 +267,53 @@ private RexNode composeDisjunction(final RexBuilder rexBuilder, List<RexNode>
co
         return node;
       }
     
    +  /**
    +   * Gets schema path defined in create table statement.
    +   * If temporary table is being created and schema is not indicated,
    +   * uses default temporary workspace.
    +   *
    +   * @param sqlCreateTable create table call
    +   * @param temporaryWorkspace default temporary workspace
    +   * @return table schema path
    +   */
    +  private List<String> getSchemaPath(SqlCreateTable sqlCreateTable, String temporaryWorkspace)
{
    +    List<String> indicatedSchemaPath = sqlCreateTable.getSchemaPath();
    +    if (sqlCreateTable.isTemporary() && indicatedSchemaPath.size() == 0) {
    +      indicatedSchemaPath = Lists.newArrayList(temporaryWorkspace);
    +    }
    +    return indicatedSchemaPath;
    +  }
    +
    +  /**
    +   * Checks if any object (persistent table / temporary table / view)
    +   * with the same name as table to be created exists in indicated schema.
    +   *
    +   * @param drillSchema schema where table will be created
    +   * @param tableName table name
    +   * @param isTemporaryWorkspace is default temporary workspace
    +   * @param userSession current user session
    +   * @throws UserException if duplicate is found
    +   */
    +  private void checkDuplicatedObjectExistence(AbstractSchema drillSchema,
    +                                              String tableName,
    +                                              boolean isTemporaryWorkspace,
    +                                              UserSession userSession) {
    +    String schemaPath = drillSchema.getFullSchemaName();
    +    boolean isTemporaryTable = false;
    +    if (isTemporaryWorkspace) {
    +      String temporaryTableName = userSession.findTemporaryTable(tableName);
    +      if (temporaryTableName != null) {
    +        Table temporaryTable = SqlHandlerUtil.getTableFromSchema(drillSchema, temporaryTableName);
    --- End diff --
    
    Question here about concurrency. Suppose I kick of two queries from the same Drillbit
connection, both of which do:
    
    ```
    CREATE TEMPORARY TABLE foo AS ...
    ```
    
    Both queries run at the same time. The first creates table foo in the user session temp
table registry. The second finds the table and returns true from this function, then proceeds
to overwrite the table as the first query runs.
    
    Is this possible? Do we register the new temp table only after the query completes? Or,
before the query starts? If at start, do we need to worry about the race condition just outlined?



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