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

    https://github.com/apache/spark/pull/14531#discussion_r75759665
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala ---
    @@ -75,18 +81,52 @@ case class CreateTableLikeCommand(
           throw new AnalysisException(
             s"Source table in CREATE TABLE LIKE does not exist: 
'$sourceTable'")
         }
    -    if (catalog.isTemporaryTable(sourceTable)) {
    -      throw new AnalysisException(
    -        s"Source table in CREATE TABLE LIKE cannot be temporary: 
'$sourceTable'")
    -    }
     
    -    val tableToCreate = catalog.getTableMetadata(sourceTable).copy(
    -      identifier = targetTable,
    -      tableType = CatalogTableType.MANAGED,
    -      createTime = System.currentTimeMillis,
    -      lastAccessTime = -1).withNewStorage(locationUri = None)
    +    val sourceTableDesc = catalog.getTableMetadata(sourceTable)
    +    val sourceStorageFormat = sourceTableDesc.storage
     
    -    catalog.createTable(tableToCreate, ifNotExists)
    +    sourceTableDesc.tableType match {
    +      case CatalogTableType.MANAGED | CatalogTableType.EXTERNAL | 
CatalogTableType.VIEW => // OK
    +      case o => throw new AnalysisException(
    +        s"CREATE TABLE LIKE is not allowed when the source table is 
${o.name}")
    +    }
    +
    +    // For EXTERNAL_TABLE, the table properties has a particular field. To 
change it
    +    // to a MANAGED_TABLE, we need to remove it; Otherwise, it will be 
EXTERNAL_TABLE,
    +    // even if we set the tableType to MANAGED
    +    // 
(metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java#L1095-L1105)
    +    // Table comment is stored as a table property. To clean it, we also 
should remove them.
    +    val newTableProp = sourceTableDesc.properties.filterKeys(_ != 
"EXTERNAL")
    --- End diff --
    
    After checking the code, we did not remove `EXTERNAL` from the table 
properties. We still add `EXTERNAL` when converting `CatalogTable` to 
`HiveTable`. See the 
[code](https://github.com/apache/spark/blob/master/sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala#L756).
    
    In this PR, should we remove `EXTERNAL` from the properties when reading 
the metadata (in 
[restoreTableMetadata](https://github.com/apache/spark/blob/master/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala#L411-L442))?
 


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