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

    https://github.com/apache/spark/pull/16868#discussion_r100685152
  
    --- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala 
---
    @@ -833,54 +833,95 @@ class HiveDDLSuite
       }
     
       test("CREATE TABLE LIKE a temporary view") {
    +    // CREATE TABLE LIKE a temporary view.
    +    withCreateTableLikeTempView(None)
    +
    +    // CREATE TABLE LIKE a temporary view location ...
    +    withTempDir {tmpDir =>
    +      withCreateTableLikeTempView(Some(tmpDir.toURI.toString))
    +    }
    +  }
    +
    +  private def withCreateTableLikeTempView(location : Option[String]): Unit 
= {
         val sourceViewName = "tab1"
         val targetTabName = "tab2"
    +    val tableType = if (location.isDefined) CatalogTableType.EXTERNAL else 
CatalogTableType.MANAGED
         withTempView(sourceViewName) {
           withTable(targetTabName) {
             spark.range(10).select('id as 'a, 'id as 'b, 'id as 'c, 'id as 'd)
               .createTempView(sourceViewName)
    -        sql(s"CREATE TABLE $targetTabName LIKE $sourceViewName")
    +
    +        val locationClause = if (location.nonEmpty) s"LOCATION 
'${location.getOrElse("")}'" else ""
    +        sql(s"CREATE TABLE $targetTabName LIKE $sourceViewName 
$locationClause")
     
             val sourceTable = 
spark.sessionState.catalog.getTempViewOrPermanentTableMetadata(
               TableIdentifier(sourceViewName))
             val targetTable = spark.sessionState.catalog.getTableMetadata(
               TableIdentifier(targetTabName, Some("default")))
     
    -        checkCreateTableLike(sourceTable, targetTable)
    +        checkCreateTableLike(sourceTable, targetTable, tableType)
           }
         }
       }
     
       test("CREATE TABLE LIKE a data source table") {
    +    // CREATE TABLE LIKE a data source table.
    +    withCreateTableLikeDSTable(None)
    +
    +    // CREATE TABLE LIKE a data source table location ...
    +    withTempDir { tmpDir =>
    +      withCreateTableLikeDSTable(Some(tmpDir.toURI.toString))
    +    }
    +  }
    +
    +  private def withCreateTableLikeDSTable(location : Option[String]): Unit 
= {
         val sourceTabName = "tab1"
         val targetTabName = "tab2"
    +    val tableType = if (location.isDefined) CatalogTableType.EXTERNAL else 
CatalogTableType.MANAGED
         withTable(sourceTabName, targetTabName) {
           spark.range(10).select('id as 'a, 'id as 'b, 'id as 'c, 'id as 'd)
             .write.format("json").saveAsTable(sourceTabName)
    -      sql(s"CREATE TABLE $targetTabName LIKE $sourceTabName")
    +
    +      val locationClause = if (location.nonEmpty) s"LOCATION 
'${location.getOrElse("")}'" else ""
    +      sql(s"CREATE TABLE $targetTabName LIKE $sourceTabName 
$locationClause")
     
           val sourceTable =
    -        
spark.sessionState.catalog.getTableMetadata(TableIdentifier(sourceTabName, 
Some("default")))
    +        spark.sessionState.catalog.getTableMetadata(
    +          TableIdentifier(sourceTabName, Some("default")))
           val targetTable =
    -        
spark.sessionState.catalog.getTableMetadata(TableIdentifier(targetTabName, 
Some("default")))
    +        spark.sessionState.catalog.getTableMetadata(
    +          TableIdentifier(targetTabName, Some("default")))
           // The table type of the source table should be a Hive-managed data 
source table
           assert(DDLUtils.isDatasourceTable(sourceTable))
           assert(sourceTable.tableType == CatalogTableType.MANAGED)
     
    -      checkCreateTableLike(sourceTable, targetTable)
    +      checkCreateTableLike(sourceTable, targetTable, tableType)
         }
       }
     
       test("CREATE TABLE LIKE an external data source table") {
    +    // CREATE TABLE LIKE an external data source table.
    +    withCreateTableLikeExtDSTable(None)
    --- End diff --
    
    The same here


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