cloud-fan commented on code in PR #43614:
URL: https://github.com/apache/spark/pull/43614#discussion_r1387469464
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala:
##########
@@ -148,15 +148,39 @@ trait CheckAnalysis extends PredicateHelper with
LookupCatalog with QueryErrorsB
errorClass, missingCol, orderedCandidates, a.origin)
}
+ private def checkUnreferencedCTERelations(
+ cteMap: mutable.Map[Long, (CTERelationDef, Int, mutable.Map[Long, Int])],
+ visited: mutable.Map[Long, Boolean],
+ cteId: Long): Unit = {
+ if (visited(cteId)) {
+ return
+ }
+ val (cteDef, _, refMap) = cteMap(cteId)
+ refMap.foreach { case (id, _) =>
+ checkUnreferencedCTERelations(cteMap, visited, id)
+ }
+ checkAnalysis0(cteDef.child)
+ visited(cteId) = true
+ }
+
def checkAnalysis(plan: LogicalPlan): Unit = {
val inlineCTE = InlineCTE(alwaysInline = true)
val cteMap = mutable.HashMap.empty[Long, (CTERelationDef, Int,
mutable.Map[Long, Int])]
inlineCTE.buildCTEMap(plan, cteMap)
- cteMap.values.foreach { case (relation, refCount, _) =>
+ cteMap.values.foreach { case (relation, _, _) =>
// If a CTE relation is never used, it will disappear after inline. Here
we explicitly check
// analysis for it, to make sure the entire query plan is valid.
try {
- if (refCount == 0) checkAnalysis0(relation.child)
+ // If a CTE relation ref count is 0, the other CTE relations that
reference it
+ // should also be checked by checkAnalysis0. This code will also
guarantee the leaf
+ // relations that are not referenced by any others are checked first.
Review Comment:
```suggestion
// relations that do not reference any others are checked first.
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]