-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Conversation
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. |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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..
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
I have signed the CLA and sent it over. |
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. |
Thank you for the CLA.. we will process shortly while we continue to sort out the content of the PR. |
Co-authored by: sushi30 <[email protected]>
There was a problem hiding this 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.
folliowing #11555
Description
documentation
no
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: