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

    https://github.com/apache/spark/pull/15024#discussion_r78468230
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/InMemoryCatalog.scala
 ---
    @@ -195,18 +195,31 @@ class InMemoryCatalog(
             throw new TableAlreadyExistsException(db = db, table = table)
           }
         } else {
    -      if (tableDefinition.tableType == CatalogTableType.MANAGED) {
    -        val dir = new Path(catalog(db).db.locationUri, table)
    -        try {
    -          val fs = dir.getFileSystem(hadoopConfig)
    -          fs.mkdirs(dir)
    -        } catch {
    -          case e: IOException =>
    -            throw new SparkException(s"Unable to create table $table as 
failed " +
    -              s"to create its directory $dir", e)
    +      val tableWithLocation = if (tableDefinition.tableType == 
CatalogTableType.MANAGED) {
    +        val defaultTableLocation = new Path(catalog(db).db.locationUri, 
table)
    +        // Ideally we can not create a managed table with location, but 
due to some limitations in
    +        // [[CreateDataSourceTableAsSelectCommand]], we have to create the 
table directory and
    +        // write out data before we create this table. We should handle 
this case and allow the
    +        // table location to be pre-created, as long as it's same with the 
default table location.
    +        if (tableDefinition.storage.locationUri.isDefined) {
    +          val givenTableLocation = new 
Path(tableDefinition.storage.locationUri.get).toUri.toString
    +          require(defaultTableLocation.toUri.toString == 
givenTableLocation)
    +          tableDefinition
    +        } else {
    +          try {
    +            val fs = defaultTableLocation.getFileSystem(hadoopConfig)
    +            fs.mkdirs(defaultTableLocation)
    +          } catch {
    +            case e: IOException =>
    +              throw new SparkException(s"Unable to create table $table as 
failed " +
    --- End diff --
    
    Maybe we should use IOException type instead of SparkException?


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

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to