-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-24675][SQL]Rename table: validate existence of new location #21655
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
Conversation
| tempViews.foreach(kv => target.tempViews.put(kv._1, kv._2)) | ||
| } | ||
|
|
||
| private def validateLocationOfRename(oldName: TableIdentifier, newName: TableIdentifier): Unit = { |
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.
Can you add code comments along with validateName?
| } | ||
|
|
||
| test ("rename a managed table with existing empty directory") { | ||
| val tableLoc = new File(spark.sessionState.catalog.defaultTablePath(TableIdentifier("tab2"))) |
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.
nit: remove the space between test and (.
| val newTableLocation = new Path(new Path(databaseLocation), formatTableName(newName.table)) | ||
| val fs = newTableLocation.getFileSystem(hadoopConf) | ||
| if (fs.exists(newTableLocation)) { | ||
| throw new AnalysisException(s"Can not rename the managed table('${oldName}')" + |
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.
nit: remove braces: ${oldName} -> $oldName
| val fs = newTableLocation.getFileSystem(hadoopConf) | ||
| if (fs.exists(newTableLocation)) { | ||
| throw new AnalysisException(s"Can not rename the managed table('${oldName}')" + | ||
| s". The associated location('${newTableLocation.toString}') already exists.") |
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.
nit: ${newTableLocation.toString} -> $newTableLocation?
| val tableLoc = new File(spark.sessionState.catalog.defaultTablePath(TableIdentifier("tab2"))) | ||
| try { | ||
| withTable("tab1") { | ||
| sql(s"CREATE TABLE tab1 USING ${dataSource} AS SELECT 1, 'a'") |
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.
nit: ${dataSource} -> $dataSource
|
Test build #92417 has finished for PR 21655 at commit
|
|
Test build #92429 has finished for PR 21655 at commit
|
| requireTableExists(TableIdentifier(oldTableName, Some(db))) | ||
| requireTableNotExists(TableIdentifier(newTableName, Some(db))) | ||
| validateName(newTableName) | ||
| validateNewLocationOfRename(oldName, newName) |
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.
Add this new behavior to migration guide?
|
Test build #92591 has finished for PR 21655 at commit
|
|
LGTM Thanks! Merged to master. |
What changes were proposed in this pull request?
If table is renamed to a existing new location, data won't show up.
The file layout is like
In Hive, if the new location exists, the renaming will fail even the location is empty.
We should have the same validation in Catalog, in case of unexpected bugs.
How was this patch tested?
New unit test.