Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2605,7 +2605,7 @@ public void createView(ConnectorSession session, SchemaTableName viewName, Conne
Optional<Table> existing = metastore.getTable(viewName.getSchemaName(), viewName.getTableName());
if (existing.isPresent()) {
if (!replace || !isPrestoView(existing.get())) {
throw new ViewAlreadyExistsException(viewName);
Copy link
Copy Markdown
Contributor

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 ViewAlreadyExistsException which may be probably replaced by TableAlreadyExistsException.

If you replace all of them, then probably ViewAlreadyExistsException may be removed.

cc @electrum

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ViewAlreadyExistsException is 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.

Copy link
Copy Markdown
Contributor

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 ViewAlreadyExistsException we are doing previously metastore.getTable(..) calls.
I'm thinking that if the metastore calls for a "table", then TableAlreadyExistsException is appropriate.

throw new TableAlreadyExistsException(viewName);
}

metastore.replaceTable(viewName.getSchemaName(), viewName.getTableName(), table, principalPrivileges);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void createView(ConnectorSession session, SchemaTableName schemaViewName,
Optional<io.trino.plugin.hive.metastore.Table> existing = metastore.getTable(schemaViewName.getSchemaName(), schemaViewName.getTableName());
if (existing.isPresent()) {
if (!replace || !isPrestoView(existing.get())) {
throw new ViewAlreadyExistsException(schemaViewName);
throw new TableAlreadyExistsException(schemaViewName);
}

metastore.replaceTable(schemaViewName.getSchemaName(), schemaViewName.getTableName(), table, principalPrivileges);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3925,6 +3925,9 @@ private void verifyViewCreation(SchemaTableName temporaryCreateView)
doCreateView(temporaryCreateView, false);
fail("create existing should fail");
}
catch (TableAlreadyExistsException e) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

shall we remove the catch (ViewAlreadyExistsExcept clause below?

assertEquals(e.getTableName(), temporaryCreateView);
}
catch (ViewAlreadyExistsException e) {
assertEquals(e.getViewName(), temporaryCreateView);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

Expand All @@ -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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is this PR supposed to close that issue?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think Issue #10037 should have been closed by #10186.

the issue is currently open

throw new ViewAlreadyExistsException(schemaViewName);
throw new TableAlreadyExistsException(schemaViewName);
}

stats.getUpdateTable().call(() ->
Expand Down