-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-33522][SQL] Improve exception messages while handling UnresolvedTableOrView #30475
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
Conversation
| sql("DROP TABLE testcat.db.notbl") | ||
| } | ||
| assert(ex.getMessage.contains("Table or view not found: testcat.db.notbl")) | ||
| assert(ex.getMessage.contains("Table or view not found for 'DROP TABLE': testcat.db.notbl")) |
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 message could be misleading since DROP TABLE supports table and a temporary view. To fix this, we can add allowPermanentView as the following and update Analyzer accordingly:
case class UnresolvedTableOrView(
multipartIdentifier: Seq[String],
commandName: String,
allowTempView: Boolean = true,
allowPermanentView: Boolean = true) extends LeafNode {
require(allowTempView || allowPermanentView)
override lazy val resolved: Boolean = false
override def output: Seq[Attribute] = Nil
}such that the exception message can be updated to
Table or temporary view not found for 'DROP TABLE': t.
One downside is that if t is resolved to a view, the message will become:
t is a permanent view. 'DROP TABLE' expects a table or temporary view.
instead of (current message):
Cannot drop a view with DROP TABLE. Please use DROP VIEW instead
, meaning it will lose the "hint" (which we can add it to Unresolved* if required).
@cloud-fan WDYT? If you are OK with introducing allowPermanentView, I can do it as a separate PR.
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.
Sorry I don't get it. In this case, testcat.db.notbl is not a permanent view, but a non-existing relation.
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.
When I read Table or view not found for 'DROP TABLE': t, it sounded like DROP TABLE also supports permanent views.
So, I was suggesting Table or temporary view not found for 'DROP TABLE': t since DROP TABLE requires either a table or temporary view. But, I guess Table or view not found sounds better if we want to point out the non-existing relation.
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.
since DROP TABLE requires either a table or temporary view
Do we have such a test case for v2 DROP TABLE?
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.
v2 DROP TABLE only handles ResolvedTable. If it's resolved to a view, it will be handled in ResolveSessionCatalog and tested here:
spark/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala
Lines 1056 to 1070 in fdd6c73
| test("drop view using drop table") { | |
| withTable("tab1") { | |
| spark.range(10).write.saveAsTable("tab1") | |
| withView("view1") { | |
| sql("CREATE VIEW view1 AS SELECT * FROM tab1") | |
| val message = intercept[AnalysisException] { | |
| sql("DROP TABLE view1") | |
| }.getMessage | |
| assert(message.contains("Cannot drop a view with DROP TABLE. Please use DROP VIEW instead")) | |
| } | |
| } | |
| } | |
| test("create view with mismatched schema") { | |
| withTable("tab1") { |
|
Kubernetes integration test starting |
|
Kubernetes integration test status success |
|
Test build #131574 has finished for PR 30475 at commit
|
|
Test build #131609 has finished for PR 30475 at commit
|
|
Test build #131578 has finished for PR 30475 at commit
|
|
Test build #131686 has finished for PR 30475 at commit
|
|
retest this please |
|
Test build #131748 has finished for PR 30475 at commit
|
|
retest this please |
|
Test build #131802 has finished for PR 30475 at commit
|
|
Test build #131808 has finished for PR 30475 at commit
|
|
Test build #131813 has finished for PR 30475 at commit
|
cloud-fan
left a comment
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. Please fix the conflicts.
|
Test build #131872 has finished for PR 30475 at commit
|
|
retest this please |
|
GA passed, merging to master, thanks! |
|
Test build #131878 has finished for PR 30475 at commit
|
What changes were proposed in this pull request?
This PR proposes to improve the exception messages while
UnresolvedTableOrViewis handled based on this suggestion: #30321 (comment).Currently, when an identifier is resolved to a temp view when a table/permanent view is expected, the following exception message is displayed (e.g., for
SHOW CREATE TABLE):After this PR, the message will be:
Also, if an identifier is not resolved, the following exception message is currently used:
After this PR, the message will be:
or
Why are the changes needed?
To improve the exception message.
Does this PR introduce any user-facing change?
Yes, the exception message will be changed as described above.
How was this patch tested?
Updated existing tests.