-
Notifications
You must be signed in to change notification settings - Fork 28k
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
[SPARK-19115] [SQL] Supporting Create External Table Like Location #16638
Changes from 4 commits
adde008
713ca97
b80f8e6
71f1d12
9e59fb4
bb3660a
5dd21b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ import org.apache.spark.sql.types._ | |
import org.apache.spark.util.Utils | ||
|
||
/** | ||
* A command to create a MANAGED table with the same definition of the given existing table. | ||
* A command to create a table with the same definition of the given existing table. | ||
* In the target table definition, the table comment is always empty but the column comments | ||
* are identical to the ones defined in the source table. | ||
* | ||
|
@@ -51,13 +51,14 @@ import org.apache.spark.util.Utils | |
* | ||
* The syntax of using this command in SQL is: | ||
* {{{ | ||
* CREATE TABLE [IF NOT EXISTS] [db_name.]table_name | ||
* LIKE [other_db_name.]existing_table_name | ||
* CREATE [EXTERNAL] TABLE [IF NOT EXISTS] [db_name.]table_name | ||
* LIKE [other_db_name.]existing_table_name [locationSpec] | ||
* }}} | ||
*/ | ||
case class CreateTableLikeCommand( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please update the comment of this class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok,i will update it later,Thanks! |
||
targetTable: TableIdentifier, | ||
sourceTable: TableIdentifier, | ||
location: Option[String], | ||
ifNotExists: Boolean) extends RunnableCommand { | ||
|
||
override def run(sparkSession: SparkSession): Seq[Row] = { | ||
|
@@ -70,12 +71,19 @@ case class CreateTableLikeCommand( | |
sourceTableDesc.provider | ||
} | ||
|
||
// If location is specified, we create an external table internally. | ||
// Else create managed table. | ||
val tblType = if (location.isEmpty) { | ||
CatalogTableType.MANAGED | ||
} else { | ||
CatalogTableType.EXTERNAL | ||
} | ||
|
||
val newTableDesc = | ||
CatalogTable( | ||
identifier = targetTable, | ||
tableType = CatalogTableType.MANAGED, | ||
// We are creating a new managed table, which should not have custom table location. | ||
storage = sourceTableDesc.storage.copy(locationUri = None), | ||
tableType = tblType, | ||
storage = sourceTableDesc.storage.copy(locationUri = location), | ||
schema = sourceTableDesc.schema, | ||
provider = newProvider, | ||
partitionColumnNames = sourceTableDesc.partitionColumnNames, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -518,8 +518,8 @@ class HiveDDLCommandSuite extends PlanTest with SQLTestUtils with TestHiveSingle | |
|
||
test("create table like") { | ||
val v1 = "CREATE TABLE table1 LIKE table2" | ||
val (target, source, exists) = parser.parsePlan(v1).collect { | ||
case CreateTableLikeCommand(t, s, allowExisting) => (t, s, allowExisting) | ||
val (target, source, location, exists) = parser.parsePlan(v1).collect { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add an assert to check |
||
case CreateTableLikeCommand(t, s, l, allowExisting) => (t, s, l, allowExisting) | ||
}.head | ||
assert(exists == false) | ||
assert(target.database.isEmpty) | ||
|
@@ -528,8 +528,8 @@ class HiveDDLCommandSuite extends PlanTest with SQLTestUtils with TestHiveSingle | |
assert(source.table == "table2") | ||
|
||
val v2 = "CREATE TABLE IF NOT EXISTS table1 LIKE table2" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add one more test case to check CREATE TABLE LIKE with location |
||
val (target2, source2, exists2) = parser.parsePlan(v2).collect { | ||
case CreateTableLikeCommand(t, s, allowExisting) => (t, s, allowExisting) | ||
val (target2, source2, location2, exists2) = parser.parsePlan(v2).collect { | ||
case CreateTableLikeCommand(t, s, l, allowExisting) => (t, s, l, allowExisting) | ||
}.head | ||
assert(exists2) | ||
assert(target2.database.isEmpty) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no
EXTERNAL