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 @@ -254,6 +254,7 @@
import static io.trino.plugin.hive.ViewReaderUtil.encodeViewData;
import static io.trino.plugin.hive.ViewReaderUtil.isHiveOrPrestoView;
import static io.trino.plugin.hive.ViewReaderUtil.isPrestoView;
import static io.trino.plugin.hive.ViewReaderUtil.isTrinoMaterializedView;
import static io.trino.plugin.hive.acid.AcidTransaction.NO_ACID_TRANSACTION;
import static io.trino.plugin.hive.acid.AcidTransaction.forCreateTable;
import static io.trino.plugin.hive.metastore.MetastoreUtil.buildInitialPrivilegeSet;
Expand Down Expand Up @@ -2604,7 +2605,9 @@ 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())) {
Table existingTable = existing.get();
boolean shouldReplace = isPrestoView(existingTable) && !isTrinoMaterializedView(existingTable.getTableType(), existingTable.getParameters());
if (!replace || !shouldReplace) {
throw new ViewAlreadyExistsException(viewName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.trino.plugin.hive.metastore.Column;
import io.trino.plugin.hive.metastore.HiveMetastore;
import io.trino.plugin.hive.metastore.PrincipalPrivileges;
import io.trino.plugin.hive.metastore.Table;
import io.trino.spi.TrinoException;
import io.trino.spi.connector.ConnectorSession;
import io.trino.spi.connector.ConnectorViewDefinition;
Expand All @@ -38,6 +39,7 @@
import static io.trino.plugin.hive.TrinoViewUtil.createViewProperties;
import static io.trino.plugin.hive.ViewReaderUtil.encodeViewData;
import static io.trino.plugin.hive.ViewReaderUtil.isPrestoView;
import static io.trino.plugin.hive.ViewReaderUtil.isTrinoMaterializedView;
import static io.trino.plugin.hive.metastore.MetastoreUtil.buildInitialPrivilegeSet;
import static io.trino.plugin.hive.metastore.PrincipalPrivileges.NO_PRIVILEGES;
import static io.trino.plugin.hive.metastore.StorageFormat.VIEW_STORAGE_FORMAT;
Expand Down Expand Up @@ -86,7 +88,9 @@ 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())) {
Table existingTable = existing.get();
boolean shouldReplace = isPrestoView(existingTable) && !isTrinoMaterializedView(existingTable.getTableType(), existingTable.getParameters());
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.

isPrestoView returns true for both regular views and Materialized
Views, so it could have been possible for a view to replace a MV.

@raunaqmorarka why is that?

doesn't seem practical
on the code level, the MVs are handled pretty separately, so why would we want to conflate them?

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'm not sure if that was on purpose or an accident, but we've been setting the "presto view" flag for MVs since the initial implementation https://github.com/trinodb/trino/pull/4832/files#diff-0a3bb720afd0370525ff486d8d55d6140e766028d20c95c37e8d60f801790881R765
Maybe it was a shortcut to ensure that MVs get listed in the metadata listing for views.
I agree that a clear separation would be better going forward.

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.

@alexjo2144 would it be possible to fix isPrestoView so that it doesn't return true for MVs?

Can you run this as a separate PR, potentially obsoleting this one?

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 am following-up on this in #18570

if (!replace || !shouldReplace) {
throw new ViewAlreadyExistsException(schemaViewName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,9 @@ 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()))) {
com.amazonaws.services.glue.model.Table existingTable = existing.get();
boolean shouldReplace = isPrestoView(existingTable.getParameters()) && !isTrinoMaterializedView(existingTable.getTableType(), existingTable.getParameters());
if (!replace || !shouldReplace) {
// TODO: ViewAlreadyExists is misleading if the name is used by a table https://github.com/trinodb/trino/issues/10037
throw new ViewAlreadyExistsException(schemaViewName);
}
Expand Down