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

Add support for ALTER VIEW RENAME TO statement #23749

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

dmariamgeorge
Copy link
Contributor

@dmariamgeorge dmariamgeorge commented Sep 30, 2024

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

image

Contributor checklist

  • Please make sure your submission complies with our development, formatting, commit message, and attribution guidelines.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.

Release Notes

Please follow release notes guidelines and fill in the release notes below.

== RELEASE NOTES ==
General Changes
* Add support for ``ALTER VIEW RENAME TO``. :pr:`23749`

Iceberg Connector Changes
* Add support for ``ALTER VIEW RENAME TO``. :pr:`23749`

Copy link

github-actions bot commented Sep 30, 2024

Codenotify: Notifying subscribers in CODENOTIFY files for diff b19167e...ce12a4a.

Notify File(s)
@aditi-pandit presto-parser/src/main/antlr4/com/facebook/presto/sql/parser/SqlBase.g4
@elharo presto-parser/src/main/antlr4/com/facebook/presto/sql/parser/SqlBase.g4
@kaikalur presto-parser/src/main/antlr4/com/facebook/presto/sql/parser/SqlBase.g4
@rschlussel presto-parser/src/main/antlr4/com/facebook/presto/sql/parser/SqlBase.g4

@steveburnett
Copy link
Contributor

Consider adding documentation for this to https://prestodb.io/docs/current/connector/iceberg.html#sql-support.

steveburnett
steveburnett previously approved these changes Sep 30, 2024
Copy link
Contributor

@steveburnett steveburnett left a 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!

@agrawalreetika
Copy link
Member

agrawalreetika commented Sep 30, 2024

Thanks for the PR.

I have a few suggestions -

  • I think we can add one commit about adding SQL statement support and different commits for support for ALTER VIEW RENAME support for each connector support along with their connector document updates about the support
  • Please add tests as well in respective connector support commits
  • We can add ALTER VIEW documentation along with 1st commit of SQL Statement support here https://prestodb.io/docs/current/sql.html
  • Also it would be good to add SQL statement support for ALTER VIEW [ IF EXISTS ] as well and its respective tests

@ZacBlanco
Copy link
Contributor

@dmariamgeorge Can we split this into two commits like @agrawalreetika suggested? Once we have both commits I will also review

@steveburnett
Copy link
Contributor

Minor nits of formatting suggested for the release note entry.

== RELEASE NOTES ==
General Changes
* Add support for ``ALTER VIEW RENAME TO``. :pr:`23749`

Iceberg Connector Changes
* Add support for ``ALTER VIEW RENAME TO``. :pr:`23749`

@dmariamgeorge
Copy link
Contributor Author

@dmariamgeorge Can we split this into two commits like @agrawalreetika suggested? Once we have both commits I will also review

Sure @ZacBlanco. Working on the same.

@dmariamgeorge dmariamgeorge force-pushed the alter_view_rename branch 4 times, most recently from 4f1282b to 4cbfaee Compare November 11, 2024 13:46
@dmariamgeorge
Copy link
Contributor Author

@dmariamgeorge Can we split this into two commits like @agrawalreetika suggested? Once we have both commits I will also review

Sure @ZacBlanco. Working on the same.

@ZacBlanco - I have split the commits as suggested by @agrawalreetika. Can you please take a look?

agrawalreetika
agrawalreetika previously approved these changes Nov 13, 2024
Copy link
Member

@agrawalreetika agrawalreetika left a 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

Copy link
Contributor

@steveburnett steveburnett left a 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.

presto-docs/src/main/sphinx/sql.rst Outdated Show resolved Hide resolved
presto-docs/src/main/sphinx/connector/iceberg.rst Outdated Show resolved Hide resolved
presto-docs/src/main/sphinx/connector/memory.rst Outdated Show resolved Hide resolved
presto-docs/src/main/sphinx/sql/alter-view.rst Outdated Show resolved Hide resolved
presto-docs/src/main/sphinx/sql/alter-view.rst Outdated Show resolved Hide resolved
Copy link
Member

@hantangwangd hantangwangd left a 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.

Comment on lines 514 to 519

Table table = getRequiredTable(metastoreContext, databaseName, tableName);
getRequiredDatabase(metastoreContext, newDatabaseName);
if (isIcebergTable(table)) {
throw new PrestoException(NOT_SUPPORTED, "Rename not supported for Iceberg tables");
}
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 696 to 698
.append(node.getSource())
.append(" RENAME TO ")
.append(node.getTarget());
Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: miss exists

Comment on lines 94 to 95
return Objects.equals(source, o.source) &&
Objects.equals(target, o.target);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: miss exists

Comment on lines 101 to 106
return toStringHelper(this)
.add("source", source)
.add("target", target)
.toString();
Copy link
Member

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,
Copy link
Contributor

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(),
Copy link
Contributor

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);
Copy link
Contributor

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");
Copy link
Contributor

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");
Copy link
Contributor

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()
Copy link
Contributor

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.

Copy link
Contributor Author

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.

steveburnett
steveburnett previously approved these changes Nov 18, 2024
Copy link
Contributor

@steveburnett steveburnett left a 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants