Github user gatorsmile commented on a diff in the pull request: https://github.com/apache/spark/pull/16868#discussion_r100685183 --- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala --- @@ -891,32 +932,58 @@ class HiveDDLSuite assert(DDLUtils.isDatasourceTable(sourceTable)) assert(sourceTable.tableType == CatalogTableType.EXTERNAL) - checkCreateTableLike(sourceTable, targetTable) + checkCreateTableLike(sourceTable, targetTable, tableType) } } } test("CREATE TABLE LIKE a managed Hive serde table") { - val catalog = spark.sessionState.catalog + // CREATE TABLE LIKE a managed Hive serde table. + withCreateTableLikeManagedHiveTable(None) + + // CREATE TABLE LIKE a managed Hive serde table location ... + withTempDir { tmpDir => + withCreateTableLikeManagedHiveTable(Some(tmpDir.toURI.toString)) + } + } + + private def withCreateTableLikeManagedHiveTable(location : Option[String]): Unit = { val sourceTabName = "tab1" val targetTabName = "tab2" + val tableType = if (location.isDefined) CatalogTableType.EXTERNAL else CatalogTableType.MANAGED + val catalog = spark.sessionState.catalog withTable(sourceTabName, targetTabName) { sql(s"CREATE TABLE $sourceTabName TBLPROPERTIES('prop1'='value1') AS SELECT 1 key, 'a'") - sql(s"CREATE TABLE $targetTabName LIKE $sourceTabName") - val sourceTable = catalog.getTableMetadata(TableIdentifier(sourceTabName, Some("default"))) + val locationClause = if (location.nonEmpty) s"LOCATION '${location.getOrElse("")}'" else "" + sql(s"CREATE TABLE $targetTabName LIKE $sourceTabName $locationClause") + + val sourceTable = catalog.getTableMetadata( + TableIdentifier(sourceTabName, Some("default"))) assert(sourceTable.tableType == CatalogTableType.MANAGED) assert(sourceTable.properties.get("prop1").nonEmpty) - val targetTable = catalog.getTableMetadata(TableIdentifier(targetTabName, Some("default"))) + val targetTable = catalog.getTableMetadata( + TableIdentifier(targetTabName, Some("default"))) - checkCreateTableLike(sourceTable, targetTable) + checkCreateTableLike(sourceTable, targetTable, tableType) } } test("CREATE TABLE LIKE an external Hive serde table") { + // CREATE TABLE LIKE an external Hive serde table. + withCreateTableLikeExtHiveTable(None) + + // CREATE TABLE LIKE an external Hive serde table location ... + withTempDir { tmpDir => + withCreateTableLikeExtHiveTable(Some(tmpDir.toURI.toString)) + } + } + + private def withCreateTableLikeExtHiveTable(location : Option[String]): Unit = { val catalog = spark.sessionState.catalog + val tableType = if (location.isDefined) CatalogTableType.EXTERNAL else CatalogTableType.MANAGED withTempDir { tmpDir => - val basePath = tmpDir.toURI + val basePath1 = tmpDir.toURI --- End diff -- revert it back?
--- 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