-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Correct exception type when table exists while creating a view #15580
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3925,6 +3925,9 @@ private void verifyViewCreation(SchemaTableName temporaryCreateView) | |
| doCreateView(temporaryCreateView, false); | ||
| fail("create existing should fail"); | ||
| } | ||
| catch (TableAlreadyExistsException e) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shall we remove the |
||
| assertEquals(e.getTableName(), temporaryCreateView); | ||
| } | ||
| catch (ViewAlreadyExistsException e) { | ||
| assertEquals(e.getViewName(), temporaryCreateView); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ | |
| import io.trino.filesystem.TrinoFileSystemFactory; | ||
| import io.trino.plugin.base.CatalogName; | ||
| import io.trino.plugin.hive.SchemaAlreadyExistsException; | ||
| import io.trino.plugin.hive.TableAlreadyExistsException; | ||
| import io.trino.plugin.hive.TrinoViewUtil; | ||
| import io.trino.plugin.hive.ViewAlreadyExistsException; | ||
| import io.trino.plugin.hive.metastore.glue.GlueMetastoreStats; | ||
|
|
@@ -550,7 +551,7 @@ public void createView(ConnectorSession session, SchemaTableName schemaViewName, | |
| Failsafe.with(new RetryPolicy<>() | ||
| .withMaxRetries(3) | ||
| .withDelay(Duration.ofMillis(100)) | ||
| .abortIf(throwable -> !replace || throwable instanceof ViewAlreadyExistsException)) | ||
| .abortIf(throwable -> !replace || throwable instanceof ViewAlreadyExistsException || throwable instanceof TableAlreadyExistsException)) | ||
| .run(() -> doCreateView(session, schemaViewName, viewTableInput, replace)); | ||
| } | ||
|
|
||
|
|
@@ -559,8 +560,7 @@ private void doCreateView(ConnectorSession session, SchemaTableName schemaViewNa | |
| Optional<com.amazonaws.services.glue.model.Table> existing = getTable(session, schemaViewName); | ||
| if (existing.isPresent()) { | ||
| if (!replace || !isPrestoView(firstNonNull(existing.get().getParameters(), ImmutableMap.of()))) { | ||
| // TODO: ViewAlreadyExists is misleading if the name is used by a table https://github.com/trinodb/trino/issues/10037 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this PR supposed to close that issue?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think Issue #10037 should have been closed by #10186. This PR #15580 is follow-up TODO task for https://github.com/trinodb/trino/pull/11499/files#diff-0c09267905a13855768761575aee308f9a1773e6f3d59c6347de78fa8dbc1c02R422
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| throw new ViewAlreadyExistsException(schemaViewName); | ||
| throw new TableAlreadyExistsException(schemaViewName); | ||
| } | ||
|
|
||
| stats.getUpdateTable().call(() -> | ||
|
|
||
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.
There are other uses of
ViewAlreadyExistsExceptionwhich may be probably replaced byTableAlreadyExistsException.If you replace all of them, then probably
ViewAlreadyExistsExceptionmay be removed.cc @electrum
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.
ViewAlreadyExistsExceptionis required for the case when a view already exists while creating a view.This PR specially deals with when A table exists while creating a view.
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.
In the cases where currently
ViewAlreadyExistsExceptionwe are doing previouslymetastore.getTable(..)calls.I'm thinking that if the metastore calls for a "table", then
TableAlreadyExistsExceptionis appropriate.