Skip to content

Conversation

@imback82
Copy link
Contributor

@imback82 imback82 commented Nov 23, 2020

What changes were proposed in this pull request?

This PR proposes to improve the exception messages while UnresolvedTableOrView is 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):

t is a temp view not table or permanent view.

After this PR, the message will be:

t is a temp view. 'SHOW CREATE TABLE' expects a table or permanent view.

Also, if an identifier is not resolved, the following exception message is currently used:

Table or view not found: t

After this PR, the message will be:

Table or permanent view not found for 'SHOW CREATE TABLE': t

or

Table or view not found for 'ANALYZE TABLE ... FOR COLUMNS ...': t

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.

@github-actions github-actions bot added the SQL label Nov 23, 2020
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"))
Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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:

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") {

@SparkQA
Copy link

SparkQA commented Nov 23, 2020

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/36175/

@SparkQA
Copy link

SparkQA commented Nov 23, 2020

Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/36175/

@SparkQA
Copy link

SparkQA commented Nov 23, 2020

Test build #131574 has finished for PR 30475 at commit fd2eb37.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@imback82 imback82 changed the title [SPARK-33522][SQL] Improve exception messages while handling UnresolvedTable [SPARK-33522][SQL] Improve exception messages while handling UnresolvedTableOrView Nov 24, 2020
@SparkQA
Copy link

SparkQA commented Nov 24, 2020

Test build #131609 has finished for PR 30475 at commit b97c925.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Nov 24, 2020

Test build #131578 has finished for PR 30475 at commit fd2eb37.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Nov 24, 2020

Test build #131686 has finished for PR 30475 at commit 68ee277.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • case class TruncateTable(

@imback82
Copy link
Contributor Author

retest this please

@SparkQA
Copy link

SparkQA commented Nov 25, 2020

Test build #131748 has finished for PR 30475 at commit 68ee277.

  • This patch fails to build.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • case class TruncateTable(

@imback82
Copy link
Contributor Author

retest this please

@SparkQA
Copy link

SparkQA commented Nov 25, 2020

Test build #131802 has finished for PR 30475 at commit 68ee277.

  • This patch fails to build.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • case class TruncateTable(

@SparkQA
Copy link

SparkQA commented Nov 25, 2020

Test build #131808 has finished for PR 30475 at commit 147c654.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Nov 26, 2020

Test build #131813 has finished for PR 30475 at commit 82cda10.

  • This patch fails PySpark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

Copy link
Contributor

@cloud-fan cloud-fan left a 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.

@SparkQA
Copy link

SparkQA commented Nov 27, 2020

Test build #131872 has finished for PR 30475 at commit 46a4c4e.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • case class CoalesceShufflePartitions(session: SparkSession) extends CustomShuffleReaderRule
  • trait CustomShuffleReaderRule extends Rule[SparkPlan]

@cloud-fan
Copy link
Contributor

retest this please

@cloud-fan
Copy link
Contributor

GA passed, merging to master, thanks!

@cloud-fan cloud-fan closed this in 2c41d9d Nov 27, 2020
@SparkQA
Copy link

SparkQA commented Nov 27, 2020

Test build #131878 has finished for PR 30475 at commit 46a4c4e.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • case class CoalesceShufflePartitions(session: SparkSession) extends CustomShuffleReaderRule
  • trait CustomShuffleReaderRule extends Rule[SparkPlan]

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants