-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Add support for ALTER VIEW RENAME TO statement #23749
base: master
Are you sure you want to change the base?
Conversation
Codenotify: Notifying subscribers in CODENOTIFY files for diff b19167e...ce12a4a.
|
Consider adding documentation for this to https://prestodb.io/docs/current/connector/iceberg.html#sql-support. |
6f20ada
to
cae013d
Compare
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.
LGTM! (docs)
Pull branch, local doc build, looks good. Thanks!
Thanks for the PR. I have a few suggestions -
|
presto-main/src/main/java/com/facebook/presto/execution/RenameViewTask.java
Outdated
Show resolved
Hide resolved
presto-main/src/main/java/com/facebook/presto/execution/RenameViewTask.java
Outdated
Show resolved
Hide resolved
presto-main/src/main/java/com/facebook/presto/testing/LocalQueryRunner.java
Outdated
Show resolved
Hide resolved
c3a6ed6
to
b1a2ab6
Compare
@dmariamgeorge Can we split this into two commits like @agrawalreetika suggested? Once we have both commits I will also review |
Minor nits of formatting suggested for the release note entry.
|
Sure @ZacBlanco. Working on the same. |
4f1282b
to
4cbfaee
Compare
@ZacBlanco - I have split the commits as suggested by @agrawalreetika. Can you please take a look? |
7331ea7
to
5b56c09
Compare
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.
@dmariamgeorge Thank you for making the changes. LGTM
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 doc! Just a few formatting nits and such.
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 this work, one little problem and some nits, otherwise looks good to me.
|
||
Table table = getRequiredTable(metastoreContext, databaseName, tableName); | ||
getRequiredDatabase(metastoreContext, newDatabaseName); | ||
if (isIcebergTable(table)) { | ||
throw new PrestoException(NOT_SUPPORTED, "Rename not supported for Iceberg tables"); | ||
} |
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.
Is it OK to completely remove this check? As far as I know, there could still have problems with altering iceberg table names now, so should we just allow the iceberg view here? Any misunderstanding please let me know.
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.
@hantangwangd - The class FileHiveMetastore.java is for testing, and it will only affect the test logic.
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.
As I understand, it's not just for testing. When user set hive.metastore=file
and set hive.metastore.catalog.dir
to a local or hdfs path, they are indeed using FileHiveMetastore
in their environment. Meanwhile, it's not a good idea to introduce additional problems in any code, even for code that is only used in testing.
Iceberg views created by hive catalog will have a table parameters presto_view=true
, so I think we can check this parameter, let iceberg view to pass, and keep iceberg table as it is until we really support renaming iceberg table name in hive catalog. Do you think this makes sense?
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.
Sure @hantangwangd.
.append(node.getSource()) | ||
.append(" RENAME TO ") | ||
.append(node.getTarget()); |
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.
Is it better to use formatName(node.getSource())
and formatName(node.getTarget)
as in other places? Since formatName(...)
use QualifiedName.originalParts
while QualifiedName.toString()
use QualifiedName.parts
.
@Override | ||
public int hashCode() | ||
{ | ||
return Objects.hash(source, target); |
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: miss exists
return Objects.equals(source, o.source) && | ||
Objects.equals(target, o.target); |
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: miss exists
return toStringHelper(this) | ||
.add("source", source) | ||
.add("target", target) | ||
.toString(); |
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: miss exists
context.getSource(), | ||
Optional.empty(), | ||
false, | ||
HiveColumnConverterProvider.DEFAULT_COLUMN_CONVERTER_PROVIDER, |
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: static import
public void checkCanRenameView(ConnectorTransactionHandle transaction, ConnectorIdentity identity, AccessControlContext context, SchemaTableName viewName, SchemaTableName newViewName) | ||
{ | ||
MetastoreContext metastoreContext = new MetastoreContext( | ||
identity, context.getQueryId().getId(), |
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: split these arguments onto two lines
@Override | ||
public void checkCanRenameView(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, SchemaTableName viewName, SchemaTableName newViewName) | ||
{ | ||
delegate().checkCanRenameView(transactionHandle, identity, context, viewName, newViewName); |
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.
this should be delegate
, not delegate()
{ | ||
assertQuerySucceeds("CREATE TABLE iceberg.test_schema.iceberg_test_table (_string VARCHAR, _integer INTEGER)"); | ||
assertUpdate("CREATE VIEW iceberg.test_schema.test_view_to_be_renamed AS SELECT * FROM iceberg.test_schema.iceberg_test_table"); | ||
assertUpdate("ALTER VIEW IF EXISTS iceberg.test_schema.test_view_to_be_renamed RENAME TO iceberg.test_schema.test_view_renamed"); |
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 we add a case without the IF EXISTS
clause?
throw new SemanticException(VIEW_ALREADY_EXISTS, statement, "Target view '%s' already exists", target); | ||
} | ||
if (!viewName.getCatalogName().equals(target.getCatalogName())) { | ||
throw new SemanticException(NOT_SUPPORTED, statement, "View rename across catalogs is not supported"); |
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.
We support renaming across schemas though? Does it make sense to rename across schemas? What if the source tables don't exist in the new schema?
@@ -185,6 +185,31 @@ public void testViews() | |||
assertQueryFails("DROP VIEW test_view", "line 1:1: View 'memory.default.test_view' does not exist"); | |||
} | |||
|
|||
@Test | |||
public void testRenameView() |
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.
Wondering if we should instead add these tests to AbstractTestDistributedQueries
? This way all connectors which support views can run this and we don't need to duplicate code.
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.
@ZacBlanco - The support for ALTER VIEW RENAME TO is implemented only for the Iceberg and Memory connectors. If we add a test for this in AbstractTestDistributedQueries, it is required to override it in each connector, so the test will not fail for the other connectors.
206a4aa
to
c0e1953
Compare
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.
LGTM! (docs)
Pull updated branch, new local doc build, reviewed, looks good. Thanks!
7773b97
to
e566492
Compare
b524a99
to
0f8daf1
Compare
0f8daf1
to
ce12a4a
Compare
Description
Add support for SQL statement ALTER VIEW <view_name> RENAME TO <new_view_name>.
Motivation and Context
Addresses issue: #23748
Impact
Support SQL statement ALTER VIEW <view_name> RENAME TO <new_view_name> in Iceberg connector.
Test Plan
Contributor checklist
Release Notes
Please follow release notes guidelines and fill in the release notes below.