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

Document "DROP TABLE IF EXISTS" throws an error if view exists #12623

Merged
merged 1 commit into from
Jan 15, 2024

Conversation

sushi30
Copy link

@sushi30 sushi30 commented Jun 1, 2022

folliowing #11555

Description

Is this change a fix, improvement, new feature, refactoring, or other?

documentation

Is this a change to the core query engine, a connector, client library, or the SPI interfaces? (be specific)

no

How would you describe this change to a non-technical end user or system administrator?

add documentation regarding an error

Related issues, pull requests, and links

Documentation

(x) No documentation is needed.
( ) Sufficient documentation is included in this PR.
( ) Documentation PR is available with #prnumber.
( ) Documentation issue #issuenumber is filed, and can be handled later.

Release notes

(x) No release notes entries required.
( ) Release notes entries required with the following suggested text:

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

@cla-bot
Copy link

cla-bot bot commented Jun 1, 2022

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to [email protected]. For more information, see https://github.com/trinodb/cla.

@github-actions github-actions bot added the docs label Jun 1, 2022
Copy link
Member

@colebow colebow left a comment

Choose a reason for hiding this comment

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

LGTM. If you haven't already submitted the CLA, ping me here and I'll try to communicate that to the maintainers once you have.

@@ -15,7 +15,8 @@ Description
Drops an existing table.

The optional ``IF EXISTS`` clause causes the error to be suppressed if
the table does not exist.
the table does not exist. The error will not be supressed if a view with the
Copy link
Member

Choose a reason for hiding this comment

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

The error is not supressed

Copy link
Member

Choose a reason for hiding this comment

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

But I am also wondering if that is true ... what kind of view are we talking about here? A trino native view or a view in the underlying database? And is this consistent across connectors..

Copy link
Member

Choose a reason for hiding this comment

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

@hashhar can you clarify how this works for views (and what kind of views)

Copy link
Member

Choose a reason for hiding this comment

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

Trino doesn't know if something is a view in remote database (at-least for JDBC connectors or things like BigQuery). So those views are tables for Trino. i.e. DROP TABLE will work on views that exist in remote system.

This is specifically talking about Trino views.

cc: @findinpath for double checking me regarding other connectors like hive.

Copy link
Member

@mosabua mosabua Jun 3, 2022

Choose a reason for hiding this comment

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

So we most likely have to clarify what type of view we are talking about here .. since from @hashhar is saying .. this current change would be incorrect for views in JDBC connector data sources and similar.

Also thinking about this some more I am wondering why we want to add this message at all. E.g. will it actually drop a native view if is exists with the "Drop table" command? This might require a larger discussion on how this works and how we document that consistent across the system.

Copy link
Author

Choose a reason for hiding this comment

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

So we most likely have to clarify what type of view we are talking about here .. since from @hashhar is saying .. this current change would be incorrect for views in JDBC connector data sources and similar.

Also thinking about this some more I am wondering why we want to add this message at all. E.g. will it actually drop a native view if is exists with the "Drop table" command? This might require a larger discussion on how this works and how we document that consistent across the system.

The documentation currently makes a blanket statement that errors are suppressed which is clearly wrong. What is more "wrong"? Current documentation or the proposed documentation? I think that this is a step in right direction but if it's a larger issue then I suggest someone with a deeper understanding open an issue and lead a discussion. I use trino only with hive so I do not have the context mentioned in this discussion like JDBC.

Copy link
Member

@mosabua mosabua Jun 3, 2022

Choose a reason for hiding this comment

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

Oh.. so this applies to Hive views or Trino views in your case? Or both ...

The thing is that for JDBC connectors where a table and a view (native view in the datasource) are the same .. and the documentation for that use case is correct.. by adding your PR we would make it wrong in that case.. I hope that explains what the problem is and why we need to decide how to properly fix this.

Copy link
Author

Choose a reason for hiding this comment

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

Trino views with hive connector (not sure how they are represented by Hive under the hood).

Copy link
Contributor

Choose a reason for hiding this comment

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

Relevant code for DROP TABLE functionality.

if (metadata.isMaterializedView(session, originalTableName)) {
throw semanticException(
GENERIC_USER_ERROR,
statement,
"Table '%s' does not exist, but a materialized view with that name exists. Did you mean DROP MATERIALIZED VIEW %s?", originalTableName, originalTableName);
}
if (metadata.isView(session, originalTableName)) {
throw semanticException(
GENERIC_USER_ERROR,
statement,
"Table '%s' does not exist, but a view with that name exists. Did you mean DROP VIEW %s?", originalTableName, originalTableName);
}
RedirectionAwareTableHandle redirectionAwareTableHandle = metadata.getRedirectionAwareTableHandle(session, originalTableName);
if (redirectionAwareTableHandle.getTableHandle().isEmpty()) {
if (!statement.isExists()) {
throw semanticException(TABLE_NOT_FOUND, statement, "Table '%s' does not exist", originalTableName);
}
return immediateVoidFuture();

Note that if we're trying to drop via DROP TABLE a materialized view or a view , a generic user error will be thrown.

If the table to be dropped does not exist, the statement has no effect.

I find the following statement misleading because there is no mention to the table not found error to be suppressed:

The optional IF EXISTS clause causes the error to be suppressed if the table does not exist.

Copy link
Member

Choose a reason for hiding this comment

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

So @findinpath and @hashhar .. how do we go from here.. I am not sure this doc change on its own is sufficient or even correct.

@sushi30
Copy link
Author

sushi30 commented Jun 2, 2022

LGTM. If you haven't already submitted the CLA, ping me here and I'll try to communicate that to the maintainers once you have.

I have signed the CLA and sent it over.

@cla-bot
Copy link

cla-bot bot commented Jun 2, 2022

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to [email protected]. For more information, see https://github.com/trinodb/cla.

@mosabua
Copy link
Member

mosabua commented Jun 2, 2022

Thank you for the CLA.. we will process shortly while we continue to sort out the content of the PR.

Copy link
Member

@mosabua mosabua left a comment

Choose a reason for hiding this comment

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

This is good to go. I will follow up with more clarifying docs about views and Trino views and so on. I also got a training session for this ready to go and will work the material into the docs.

@mosabua mosabua merged commit fa20e96 into trinodb:master Jan 15, 2024
8 checks passed
@github-actions github-actions bot added this to the 437 milestone Jan 15, 2024
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.

5 participants