Skip to content

Commit

Permalink
[SPARK-45421][SQL] Catch AnalysisException over InlineCTE
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?

We are catching exceptions for `CheckAnalysis` and attach inlined plan. However, if `InlineCTE` itself throws we can also catch but attach original plan.

### Why are the changes needed?

Attach original plan if `InlineCTE` throws.

### Does this PR introduce _any_ user-facing change?

No

### How was this patch tested?

Existing UT

### Was this patch authored or co-authored using generative AI tooling?

NO

Closes #43227 from amaliujia/inline_cte_plan.

Authored-by: Rui Wang <rui.wang@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
  • Loading branch information
amaliujia authored and cloud-fan committed Oct 6, 2023
1 parent 58863df commit 94666e9
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,18 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog with QueryErrorsB

}
// Inline all CTEs in the plan to help check query plan structures in subqueries.
val inlinedPlan = inlineCTE(plan)
var inlinedPlan: Option[LogicalPlan] = None
try {
checkAnalysis0(inlinedPlan)
inlinedPlan = Some(inlineCTE(plan))
} catch {
case e: AnalysisException =>
throw new ExtendedAnalysisException(e, inlinedPlan)
throw new ExtendedAnalysisException(e, plan)
}
try {
checkAnalysis0(inlinedPlan.get)
} catch {
case e: AnalysisException =>
throw new ExtendedAnalysisException(e, inlinedPlan.get)
}
plan.setAnalyzed()
}
Expand Down

0 comments on commit 94666e9

Please sign in to comment.