Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CREATE TABLE LIKE Feature for Delta #1584

Closed
wants to merge 11 commits into from
Prev Previous commit
Next Next commit
Squashed commits:
  - 392d30a4b5caaef1c921b07ee1d4bbbbfb9cc7a3 fixed nits by Dhruv-Shah9 <dhruv.shah@databricks.com>

GitOrigin-RevId: 392d30a4b5caaef1c921b07ee1d4bbbbfb9cc7a3
  • Loading branch information
Dhruv-Shah9 committed Feb 9, 2023
commit 8ad62ca74f87c300ba1cf286894279ed6c58c959
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ class DeltaCreateTableLikeSuite extends QueryTest
checkPartitionColumns: Boolean = true,
checkConfiguration: Boolean = true,
checkTargetTableByPath: Boolean = false,
checkLocation: Option[String] = None,
isNamelessExternalTable: Boolean = false): Unit = {
checkLocation: Option[String] = None): Unit = {
val src = DeltaLog.forTable(spark, TableIdentifier(srcTbl))
val target =
if (checkTargetTableByPath) {
Expand Down Expand Up @@ -83,31 +82,6 @@ class DeltaCreateTableLikeSuite extends QueryTest
"configuration does not match")
}

val df =
if (isNamelessExternalTable) {
spark.sql(s"desc formatted delta.`$targetTbl`")
} else {
spark.sql(s"desc formatted $targetTbl")
}
val tableType = df.filter(df("col_name") === "Type").collect()(0).get(1)

if (checkLocation.isDefined) {
val catalog = spark.sessionState.catalog
assert(
catalog.getTableMetadata(TableIdentifier(targetTbl)).location.toString + "/"
== checkLocation.get ||
catalog.getTableMetadata(TableIdentifier(targetTbl)).location.toString ==
checkLocation.get, "location does not match")
assert(tableType == "EXTERNAL")
} else if (isNamelessExternalTable) {
// The tableType returned for nameless external tables is MANAGED, not EXTERNAL
assert(tableType == "MANAGED")
} else {
// If location is not defined and table is not
// a nameless external table, then target table should be managed
assert(tableType == "MANAGED",
"table type does not match")
}
}

/**
Expand Down Expand Up @@ -361,8 +335,8 @@ class DeltaCreateTableLikeSuite extends QueryTest
withTable(srcTbl) {
createTable(srcTbl)
spark.sql(s"CREATE TABLE delta.`${dir.toURI.toString}` LIKE $srcTbl")
checkTableCopyDelta(srcTbl, dir.toString, checkTargetTableByPath = true,
isNamelessExternalTable = true)
checkTableCopyDelta(srcTbl, dir.toString, checkTargetTableByPath = true
)
}
}
}
Expand Down