Skip to content

Conversation

@nastra
Copy link
Contributor

@nastra nastra commented Dec 19, 2023

This is based on #9340 and adds support for resolving and renaming views: ALTER VIEW view_identifier RENAME TO view_identifier

@github-actions github-actions bot added the spark label Dec 19, 2023
@nastra nastra force-pushed the spark-view-rename branch 2 times, most recently from 951f811 to 122c23c Compare January 4, 2024 18:19
.map(_ => ResolvedV2View(catalog.asViewCatalog, ident))
.getOrElse(u)

case RenameTable(ResolvedV2View(oldCatalog, oldIdent), CatalogAndIdentifier(newCatalog, newIdent), true) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

What is true? Can we add a name to this so that it is more readable?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible for the rule on line 61 to resolve the multi-part to identifier before this rule runs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this to isView@true so that it's clearer. I checked the Spark code and the to identifier isn't resolved anywhere and just passed as-is when doing a rename

String.format(
"SELECT spark_catalog.system.bucket(100, 'a') AS bucket_result, 'a' AS value",
catalogName);
String sql = "SELECT spark_catalog.system.bucket(100, 'a') AS bucket_result, 'a' AS value";
Copy link
Contributor

Choose a reason for hiding this comment

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

😅

@nastra nastra force-pushed the spark-view-rename branch from 122c23c to cab9f16 Compare January 5, 2024 08:34
@nastra nastra added this to the Iceberg 1.5.0 milestone Jan 5, 2024
@nastra nastra requested a review from rdblue January 9, 2024 00:29
@nastra nastra force-pushed the spark-view-rename branch 2 times, most recently from 9ca1a5d to 7565976 Compare January 15, 2024 16:45
@nastra nastra force-pushed the spark-view-rename branch from 7565976 to 9f9d6b5 Compare January 15, 2024 16:48
.map(createViewRelation(parts, _))
.getOrElse(u)

case u@UnresolvedTableOrView(CatalogAndIdentifier(catalog, ident), _, _) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to check whether this matches temp views?

}

@Test
public void renameView() throws NoSuchTableException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add tests for names that reference temp views? I think we want to know what Spark does. My initial opinion (which could change if Spark does something else!) is that it should fail because the reference is ambiguous.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a test that renames a view which is hidden by a temp view. The behavior is in-line with what we've seen when reading from a view that is hidden by a temp view. Doing a rename will first rename the temp view and re-executing the same rename will then do it for the Iceberg view.
I think for now we don't need any additional checks when handling UnresolvedTableOrView in ResolveViews

Copy link
Contributor

@rdblue rdblue left a comment

Choose a reason for hiding this comment

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

I think this is ready to go, but we should double-check how temp views are handled.


ViewCatalog viewCatalog = viewCatalog();

viewCatalog
Copy link
Member

Choose a reason for hiding this comment

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

The SQL tests will be more cleaner if we support the CREATE VIEW SQL first before RENAME VIEW SQL?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rdblue and I talked about this and view creation via SQL requires some additional complexity, so we decided to get a few other smaller PRs/functionality in. #9421 is introducing some of that complexity and once #9421 is in, adding view creation via SQL should be much smaller in terms of complexity/diffset.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I don't think this is a good direction. We want the tests to be independent. This allows us to more easily test just rename.

@nastra nastra merged commit a60ee5d into apache:main Jan 16, 2024
@nastra nastra deleted the spark-view-rename branch January 16, 2024 10:42
geruh pushed a commit to geruh/iceberg that referenced this pull request Jan 26, 2024
adnanhemani pushed a commit to adnanhemani/iceberg that referenced this pull request Jan 30, 2024
devangjhabakh pushed a commit to cdouglas/iceberg that referenced this pull request Apr 22, 2024
@nastra nastra self-assigned this Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants