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

Remove redundant checks from DropSchemaTask #11612

Conversation

findepi
Copy link
Member

@findepi findepi commented Mar 22, 2022

listTables includes views and materialized views, so calling
listViews and listMaterializedViews is redundant.

findepi added 2 commits March 22, 2022 10:12
`listTables` includes views and materialized views, so calling
`listViews` and `listMaterializedViews` is redundant.
@findepi findepi added maintenance Project maintenance task no-release-notes This pull request does not require release notes entry labels Mar 22, 2022
@cla-bot cla-bot bot added the cla-signed label Mar 22, 2022
Comment on lines +145 to +146
* Get the relation names that match the specified table prefix (never null).
* This includes all relations (e.g. tables, views, materialized views).
Copy link
Member

Choose a reason for hiding this comment

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

I did not check. Is this accurate for all the connector now?

Copy link
Contributor

Choose a reason for hiding this comment

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

I went through all the implementations of io.trino.spi.connector.ConnectorMetadata#listViews and io.trino.spi.connector.ConnectorMetadata#listMaterializedViews and the corresponding listTables implementation does indeed return the views / materialized views as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

I did not check. Is this accurate for all the connector now?

even if it wasn't the case yet, we already have this

/**
* List table, view and materialized view names, possibly filtered by schema. An empty list is returned if none match.
*/
default List<SchemaTableName> listTables(ConnectorSession session, Optional<String> schemaName)

and Metadata just calls that method.

Copy link
Member

@hashhar hashhar left a comment

Choose a reason for hiding this comment

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

Good direction but I don't think all connectors check for existence of materialized views.
All of them do check for views though.

We should also check if there are any connectors whose drop schema impl doens't check for existence of objects in the schema. (i.e. remote views or materialized views or other objects) (I'll check and re-review).

@wendigo
Copy link
Contributor

wendigo commented Mar 22, 2022

Personally I don't have an opinion here as I don't track whether all connectors consistently implement SPI. Isn't that change risky?

@@ -92,19 +92,7 @@ private static boolean isSchemaEmpty(Session session, CatalogSchemaName schema,
{
QualifiedTablePrefix tablePrefix = new QualifiedTablePrefix(schema.getCatalogName(), schema.getSchemaName());

// These are best efforts checks that don't provide any guarantees against concurrent DDL operations
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be beneficial to add views & materialized views in the io.trino.testing.BaseConnectorTest#testDropNonEmptySchema depending on:

  • SUPPORTS_CREATE_VIEW
  • SUPPORTS_CREATE_MATERIALIZED_VIEW

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea, but we would have to test all these 3 cases separately. I don't plan to do this though. Do you want to want to follow up?

Copy link
Contributor

@findinpath findinpath Mar 22, 2022

Choose a reason for hiding this comment

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

Yes, I'll create a PR based on your changes.

See #11614

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I'll create a PR based on your changes.

many thanks!

@findepi
Copy link
Member Author

findepi commented Mar 22, 2022

Good direction but I don't think all connectors check for existence of materialized views.

@hashhar I think exactly one connector supports MVs today, am i right?

@hashhar
Copy link
Member

hashhar commented Mar 22, 2022

@findepi Yes, but how do you ensure this contract is maintained going forward without either tests or by default calling listMaterializedViews (whose default impl returns empty list).

(Because I'm not confident we'll catch this at review time).

@findepi
Copy link
Member Author

findepi commented Mar 22, 2022

(Because I'm not confident we'll catch this at review time).

Failure to list MVs within listTables has other consequences, like SHOW TABLES, information_schema.tables, .columns, system.jdbc.tables, .columns. See eg #11063
So we better make sure that a connector gaining MV support does it correctly, or we have bugs.

@findepi findepi merged commit 029abe0 into trinodb:master Mar 22, 2022
@findepi findepi deleted the findepi/remove-redundant-checks-from-dropschematask-9b1e05 branch March 22, 2022 14:45
@github-actions github-actions bot added this to the 375 milestone Mar 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed maintenance Project maintenance task no-release-notes This pull request does not require release notes entry
Development

Successfully merging this pull request may close these issues.

5 participants