gengliangwang commented on a change in pull request #34747: URL: https://github.com/apache/spark/pull/34747#discussion_r758938379
########## File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala ########## @@ -198,21 +205,39 @@ class Analyzer(override val catalogManager: CatalogManager) } def executeAndCheck(plan: LogicalPlan, tracker: QueryPlanningTracker): LogicalPlan = { - if (plan.analyzed) return plan AnalysisHelper.markInAnalyzer { val analyzed = executeAndTrack(plan, tracker) try { checkAnalysis(analyzed) analyzed } catch { case e: AnalysisException => - val ae = e.copy(plan = Option(analyzed)) + val ae = e.copy(plan = Option(analyzed), + message = e.message + extraHintForAnsiTypeCoercion(plan)) ae.setStackTrace(e.getStackTrace) throw ae } } } + private def extraHintForAnsiTypeCoercion(plan: LogicalPlan): String = { + if (!conf.ansiEnabled) { + "" + } else { + val nonAnsiPlan = AnalysisContext.withDefaultTypeCoercionAnalysisContext { + executeSameContext(plan) + } + try { + checkAnalysis(nonAnsiPlan) + "\nTo fix the error, you might need to add explicit type casts.\n" + Review comment: Take `ResolveAliases` as an example, the order of it is in front of Type Coercion rules, but it won't happen in the first run since the children is not resolved. After apply the Type Coercion rules, we still have to run the other rules again: ![image](https://user-images.githubusercontent.com/1097932/143989969-cd2af234-a071-4f42-a3f1-bc2c25b55f80.png) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org