Github user xwu0226 commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13270#discussion_r64318562
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala
 ---
    @@ -216,7 +216,25 @@ class SessionCatalog(
         val table = formatTableName(tableDefinition.identifier.table)
         val newTableDefinition = tableDefinition.copy(identifier = 
TableIdentifier(table, Some(db)))
         requireDbExists(db)
    -    externalCatalog.createTable(db, newTableDefinition, ignoreIfExists)
    +
    +    if (newTableDefinition.tableType == CatalogTableType.EXTERNAL) {
    +      // !! HACK ALERT !!
    +      //
    +      // See https://issues.apache.org/jira/browse/SPARK-15269 for more 
details about why we have to
    +      // set `locationUri` and then remove the directory after creating 
the external table:
    +      val tablePath = defaultTablePath(newTableDefinition.identifier)
    +      try {
    +        externalCatalog.createTable(
    +          db,
    +          newTableDefinition.withNewStorage(locationUri = Some(tablePath)),
    +          ignoreIfExists)
    +      } finally {
    +        val path = new Path(tablePath)
    +        FileSystem.get(path.toUri, hadoopConf).delete(path, true)
    +      }
    +    } else {
    +      externalCatalog.createTable(db, newTableDefinition, ignoreIfExists)
    +    }
    --- End diff --
    
    I am wondering if we should worry about the case where the 
`defaultTablePath` happens to be the same as the user-specified path for 
creating external table that contains real data. It may delete the external 
table data. For example:
    ```
    create table t10 (c1 int) using parquet options(path 
'/Users/xinwu/spark/spark-warehouse/t10');
    insert into t10 values (1);
    drop table t10;
    create table t10 (c1 int) using parquet options(path 
'/Users/xinwu/spark/spark-warehouse/t10');
    ```
    In the above case, my metastore warehouse dir is 
`/Users/xinwu/spark/spark-warehouse', so the `defaultTablePath` will return 
`'/Users/xinwu/spark/spark-warehouse/t10'`.  Now, upon the creation of the 2nd 
table, the data path will be deleted, right? Maybe this is a corner case that 
we may not worry about. but I thought I should bring it up. 
    
    Another observation is that in a hive-compatible case (above case), 
`createDataSourceTabes` set the `locationURI` with the user specified path, but 
will be overridden by the above code. Then, users will not be able to query 
anything back from hive shell, unless users don't expect to see same results 
from hive shell for hive-compatible tables. I am not sure about the semantic of 
hive-compatible datasource table. Will this be a problem? Thanks!


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to