diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveMetadata.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveMetadata.java index 51fb0463b177..dc57ab72a88d 100644 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveMetadata.java +++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveMetadata.java @@ -2605,7 +2605,7 @@ public void createView(ConnectorSession session, SchemaTableName viewName, Conne Optional existing = metastore.getTable(viewName.getSchemaName(), viewName.getTableName()); if (existing.isPresent()) { if (!replace || !isPrestoView(existing.get())) { - throw new ViewAlreadyExistsException(viewName); + throw new TableAlreadyExistsException(viewName); } metastore.replaceTable(viewName.getSchemaName(), viewName.getTableName(), table, principalPrivileges); diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/TrinoViewHiveMetastore.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/TrinoViewHiveMetastore.java index 08ac71168857..64d26f45401e 100644 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/TrinoViewHiveMetastore.java +++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/TrinoViewHiveMetastore.java @@ -87,7 +87,7 @@ public void createView(ConnectorSession session, SchemaTableName schemaViewName, Optional 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); diff --git a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/AbstractTestHive.java b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/AbstractTestHive.java index e7339589f2a5..76e9e44bf325 100644 --- a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/AbstractTestHive.java +++ b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/AbstractTestHive.java @@ -3925,6 +3925,9 @@ private void verifyViewCreation(SchemaTableName temporaryCreateView) doCreateView(temporaryCreateView, false); fail("create existing should fail"); } + catch (TableAlreadyExistsException e) { + assertEquals(e.getTableName(), temporaryCreateView); + } catch (ViewAlreadyExistsException e) { assertEquals(e.getViewName(), temporaryCreateView); } diff --git a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/glue/TrinoGlueCatalog.java b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/glue/TrinoGlueCatalog.java index 1af83791cca2..971e0fbab1b9 100644 --- a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/glue/TrinoGlueCatalog.java +++ b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/glue/TrinoGlueCatalog.java @@ -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 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 - throw new ViewAlreadyExistsException(schemaViewName); + throw new TableAlreadyExistsException(schemaViewName); } stats.getUpdateTable().call(() ->