Github user paul-rogers commented on a diff in the pull request:

    https://github.com/apache/drill/pull/666#discussion_r94857634
  
    --- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserSession.java ---
    @@ -207,18 +245,85 @@ public SchemaPlus getDefaultSchema(SchemaPlus 
rootSchema) {
           return null;
         }
     
    -    final SchemaPlus defaultSchema = SchemaUtilites.findSchema(rootSchema, 
defaultSchemaPath);
    +    return SchemaUtilites.findSchema(rootSchema, defaultSchemaPath);
    +  }
     
    -    if (defaultSchema == null) {
    -      // If the current schema resolves to null, return root schema as the 
current default schema.
    -      return defaultSchema;
    +  public boolean setSessionOption(String name, String value) {
    +    return true;
    +  }
    +
    +  /**
    +   * @return unique session identifier
    +   */
    +  public String getSessionId() { return sessionId; }
    +
    +  /**
    +   * Creates and adds session temporary location if absent using schema 
configuration.
    +   * Generates temporary table name and stores it's original name as key
    +   * and generated name as value in  session temporary tables cache.
    +   * If original table name already exists, new name is not regenerated 
and is reused.
    +   * This can happen if default temporary workspace was changed (file 
system or location) or
    +   * orphan temporary table name has remained (name was registered but 
table creation did not succeed).
    +   *
    +   * @param schema table schema
    +   * @param tableName original table name
    +   * @return generated temporary table name
    +   * @throws IOException if error during session temporary location 
creation
    +   */
    +  public String registerTemporaryTable(AbstractSchema schema, String 
tableName) throws IOException {
    +    if (schema instanceof WorkspaceSchemaFactory.WorkspaceSchema) {
    +      addTemporaryLocation((WorkspaceSchemaFactory.WorkspaceSchema) 
schema);
    +      String temporaryTableName = Paths.get(sessionId, 
UUID.randomUUID().toString()).toString();
    +      String oldTemporaryTableName = 
temporaryTables.putIfAbsent(tableName, temporaryTableName);
    +      return oldTemporaryTableName == null ? temporaryTableName : 
oldTemporaryTableName;
    +    } else {
    +      throw new DrillRuntimeException("Temporary workspace must be 
instance of WorkspaceSchemaFactory.WorkspaceSchema");
         }
    +  }
     
    -    return defaultSchema;
    +  /**
    +   * Returns generated temporary table name from the list of session 
temporary tables, null otherwise.
    +   *
    +   * @param tableName original table name
    +   * @return generated temporary table name
    +   */
    +  public String findTemporaryTable(String tableName) {
    +    return temporaryTables.get(tableName);
       }
     
    -  public boolean setSessionOption(String name, String value) {
    -    return true;
    +  /**
    +   * Removes temporary table name from the list of session temporary 
tables.
    +   *
    +   * @param tableName original table name
    +   */
    +  public void removeTemporaryTable(String tableName) {
    --- End diff --
    
    This method is public and sure looks like what should be called to remove a 
table. But, removing a temp table should delete it from disk since, once it is 
removed from the table, we know longer know about it, right? Should the work 
done in the DROP TABLE command shift here so we have a single place that does 
the deregister-table-and-delete-file as a single operation in a single place?


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

Reply via email to