Skip to content
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

Prevent Views from replacing MVs #15622

Closed
wants to merge 2 commits into from

Conversation

alexjo2144
Copy link
Member

Description

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

This would have only been possible during a rare race condition since the engine also checks that an existing entity is not a MV before calling on the connector to create or replace the view.

Additional context and related issues

Noticed while reviewing: #15580

Release notes

( ) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text:

# Section
* Fix some things. ({issue}`issuenumber`)

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

This would have only been possible during a rare race condition since
the engine also checks that an existing entity is not a MV before
calling on the connector to create or replace the view.
@alexjo2144
Copy link
Member Author

CI hit: #13633

@@ -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
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
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
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
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

@github-actions
Copy link

This pull request has gone a while without any activity. Tagging the Trino developer relations team: @bitsondatadev @colebow @mosabua

@github-actions github-actions bot added the stale label Feb 22, 2023
@alexjo2144
Copy link
Member Author

Good bot.

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.

@raunaqmorarka can we think about doing that separately and fix the bug here first?

@bitsondatadev
Copy link
Member

Good bot.

lol, just gonna reply here so it removes the stale label...carry on!

@github-actions github-actions bot removed the stale label Feb 23, 2023
@@ -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
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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants