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

[SPARK-13828][SQL] Bring back stack trace of AnalysisException thrown from QueryExecution.assertAnalyzed #11677

Closed

Conversation

liancheng
Copy link
Contributor

What changes were proposed in this pull request?

PR #11443 added an extra plan: Option[LogicalPlan] argument to AnalysisException and attached partially analyzed plan to thrown AnalysisException in QueryExecution.assertAnalyzed(). However, the original stack trace wasn't properly inherited. This PR fixes this issue by inheriting the stack trace.

How was this patch tested?

A test case is added to verify that the first entry of AnalysisException stack trace isn't from QueryExecution.

@liancheng
Copy link
Contributor Author

cc @rxin

(Seems that ASF JIRA is down right now, and I couldn't find the JIRA number. Will fill it back once JIRA comes back.)

@liancheng
Copy link
Contributor Author

Also verified locally in Spark shell.

Before:

scala> sqlContext range 10 select ('id as 'a, 'id as 'b) groupBy 'b agg 'a
org.apache.spark.sql.AnalysisException: expression '`a`' is neither present in the group by, nor is it an aggregate function. Add to group by or wrap in first() (or first_value) if you don't care which value you get.;
  at org.apache.spark.sql.execution.QueryExecution.assertAnalyzed(QueryExecution.scala:36)
  at org.apache.spark.sql.Dataset$.newDataFrame(DataFrame.scala:58)
  at org.apache.spark.sql.GroupedData.toDF(GroupedData.scala:58)
  at org.apache.spark.sql.GroupedData.agg(GroupedData.scala:214)
  ... 49 elided

After:

scala> sqlContext range 10 select ('id as 'a, 'id as 'b) groupBy 'b agg 'a
org.apache.spark.sql.AnalysisException: expression '`a`' is neither present in the group by, nor is it an aggregate function. Add to group by or wrap in first() (or first_value) if you don't care which value you get.;
  at org.apache.spark.sql.catalyst.analysis.CheckAnalysis$class.failAnalysis(CheckAnalysis.scala:38)
  at org.apache.spark.sql.catalyst.analysis.Analyzer.failAnalysis(Analyzer.scala:50)
  at org.apache.spark.sql.catalyst.analysis.CheckAnalysis$$anonfun$checkAnalysis$1.org$apache$spark$sql$catalyst$analysis$CheckAnalysis$class$$anonfun$$checkValidAggregateExpression$1(CheckAnalysis.scala:152)
  at org.apache.spark.sql.catalyst.analysis.CheckAnalysis$$anonfun$checkAnalysis$1$$anonfun$apply$4.apply(CheckAnalysis.scala:180)
  at org.apache.spark.sql.catalyst.analysis.CheckAnalysis$$anonfun$checkAnalysis$1$$anonfun$apply$4.apply(CheckAnalysis.scala:180)
  at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
  at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)
  at org.apache.spark.sql.catalyst.analysis.CheckAnalysis$$anonfun$checkAnalysis$1.apply(CheckAnalysis.scala:180)
  at org.apache.spark.sql.catalyst.analysis.CheckAnalysis$$anonfun$checkAnalysis$1.apply(CheckAnalysis.scala:50)
  at org.apache.spark.sql.catalyst.trees.TreeNode.foreachUp(TreeNode.scala:119)
  at org.apache.spark.sql.catalyst.analysis.CheckAnalysis$class.checkAnalysis(CheckAnalysis.scala:50)
  at org.apache.spark.sql.catalyst.analysis.Analyzer.checkAnalysis(Analyzer.scala:50)
  at org.apache.spark.sql.execution.QueryExecution.assertAnalyzed(QueryExecution.scala:34)
  at org.apache.spark.sql.Dataset$.newDataFrame(DataFrame.scala:58)
  at org.apache.spark.sql.GroupedData.toDF(GroupedData.scala:58)
  at org.apache.spark.sql.GroupedData.agg(GroupedData.scala:214)
  ... 49 elided

@SparkQA
Copy link

SparkQA commented Mar 12, 2016

Test build #52999 has finished for PR 11677 at commit 00f299b.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@rxin
Copy link
Contributor

rxin commented Mar 12, 2016

Thanks - I've merged this and added JIRA ticket to the commit message.

@asfgit asfgit closed this in 4eace4d Mar 12, 2016
@liancheng liancheng changed the title [SQL] Bring back stack trace of AnalysisException thrown from QueryExecution.assertAnalyzed [SPARK-13828][SQL] Bring back stack trace of AnalysisException thrown from QueryExecution.assertAnalyzed Mar 13, 2016
@liancheng liancheng deleted the analysis-exception-stacktrace branch March 13, 2016 03:47
jeanlyn pushed a commit to jeanlyn/spark that referenced this pull request Mar 17, 2016
… from QueryExecution.assertAnalyzed

PR apache#11443 added an extra `plan: Option[LogicalPlan]` argument to `AnalysisException` and attached partially analyzed plan to thrown `AnalysisException` in `QueryExecution.assertAnalyzed()`.  However, the original stack trace wasn't properly inherited.  This PR fixes this issue by inheriting the stack trace.

A test case is added to verify that the first entry of `AnalysisException` stack trace isn't from `QueryExecution`.

Author: Cheng Lian <lian@databricks.com>

Closes apache#11677 from liancheng/analysis-exception-stacktrace.
roygao94 pushed a commit to roygao94/spark that referenced this pull request Mar 22, 2016
… from QueryExecution.assertAnalyzed

PR apache#11443 added an extra `plan: Option[LogicalPlan]` argument to `AnalysisException` and attached partially analyzed plan to thrown `AnalysisException` in `QueryExecution.assertAnalyzed()`.  However, the original stack trace wasn't properly inherited.  This PR fixes this issue by inheriting the stack trace.

A test case is added to verify that the first entry of `AnalysisException` stack trace isn't from `QueryExecution`.

Author: Cheng Lian <lian@databricks.com>

Closes apache#11677 from liancheng/analysis-exception-stacktrace.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants