-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[SPARK-29728][SQL] Datasource V2: Support ALTER TABLE RENAME TO #26539
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
cc: @cloud-fan @rdblue @viirya |
@@ -93,6 +93,22 @@ class ResolveCatalogs(val catalogManager: CatalogManager) | |||
s"Can not specify catalog `${catalog.name}` for view ${tableName.quoted} " + | |||
s"because view support in catalog has not been implemented yet") | |||
|
|||
case RenameTableStatement(NonSessionCatalog(catalog, oldName), newNameParts, isView) => | |||
if (isView) { | |||
throw new AnalysisException("Renaming view is not supported in v2 catalogs.") |
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.
Could you add a test coverage for this too?
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.
Thanks for catching this. I will add one.
throw new AnalysisException("Renaming view is not supported in v2 catalogs.") | ||
} | ||
newNameParts match { | ||
case NonSessionCatalog(newCatalog, 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.
If there is a name conflict, this forces users to always specify the catalog name.
I think it's easier to define the newNameParts
as the identifier of the target catalog, so that we can just return
RenameTable(atalog.asTableCatalog, oldName.asIdentifier, newNameParts.asIdentifier)
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.
Thanks for the suggestion, but wanted to make sure if I understood correctly.
Are you suggesting newNameParts
will contain only the identifier info, not the catalog name?
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.
yea, since we won't support cross catalog renaming (it's not renaming anymore), I don't think it's necessary to contain catalog name in the newNameParts
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.
OK, that should simplify the logic. But, I have one concern. For the following:
ALTER TABLE testcat.ns1.ns2.old RENAME TO testcat.ns1.ns2.new
, ns1.ns2.old
will be renamed to testcat.ns1.ns2.new
. Is this the expected behavior or should we handle it gracefully?
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.
I think it is the expected behavior.
@@ -158,6 +158,14 @@ class ResolveSessionCatalog( | |||
case AlterViewUnsetPropertiesStatement(SessionCatalog(catalog, tableName), keys, ifExists) => | |||
AlterTableUnsetPropertiesCommand(tableName.asTableIdentifier, keys, ifExists, isView = true) | |||
|
|||
case RenameTableStatement(SessionCatalog(_, oldName), newNameParts, isView) => | |||
newNameParts match { |
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.
ditto
Test build #113844 has finished for PR 26539 at commit
|
Test build #114033 has finished for PR 26539 at commit
|
thanks, merging to master! |
/** | ||
* Physical plan node for renaming a table. | ||
*/ | ||
case class RenameTableExec( |
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.
Are there any specific reasons for naming it as RenameTableExec
instead of AlterTableRenameExec
similarly to other alter table exec nodes?
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.
I don't think there was a specific reason. Most likely a byproduct of following TableCatalog.renameTable
and visitRenameTable
naming.
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.
It's not a big deal, and I prefer RenameTableExec
as it's shorter.
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.
DropPartitionExec
is shorter than AlterTableDropPartitionExec
too but we have the AlterTable
prefix in all ALTER TABLE
exec nodes.
Looks slightly strange that all alter table commands begin from AlterTable
except only one.
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.
How many AlterTable*
v2 commands out there? If it's a lot then let's update this one as well.
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.
Not a a lot but we have for now:
- AlterTableAddPartitionExec
- AlterTableRenamePartitionExec
- AlterTableDropPartitionExec
- AlterTableExec
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.
Then it's probably better to change them to AddPartitionExec
, etc.
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.
Here is the PR #31584
What changes were proposed in this pull request?
This PR adds
ALTER TABLE a.b.c RENAME TO x.y.x
support for V2 catalogs.Why are the changes needed?
The current implementation doesn't support this command V2 catalogs.
Does this PR introduce any user-facing change?
Yes, now the renaming table works for v2 catalogs:
How was this patch tested?
Added unit tests.