@@ -283,7 +283,7 @@ class Analyzer(
283283 val conflictingAttributes = left.outputSet.intersect(right.outputSet)
284284 logDebug(s " Conflicting attributes ${conflictingAttributes.mkString(" ," )} in $j" )
285285
286- val (oldRelation, newRelation) = right.collect {
286+ right.collect {
287287 // Handle base relations that might appear more than once.
288288 case oldVersion : MultiInstanceRelation
289289 if oldVersion.outputSet.intersect(conflictingAttributes).nonEmpty =>
@@ -308,25 +308,27 @@ class Analyzer(
308308 if AttributeSet (windowExpressions.map(_.toAttribute)).intersect(conflictingAttributes)
309309 .nonEmpty =>
310310 (oldVersion, oldVersion.copy(windowExpressions = newAliases(windowExpressions)))
311- }.headOption.getOrElse { // Only handle first case, others will be fixed on the next pass.
312- sys.error(
313- s """
314- |Failure when resolving conflicting references in Join:
315- | $plan
316- |
317- |Conflicting attributes: ${conflictingAttributes.mkString(" ," )}
318- """ .stripMargin)
319311 }
320-
321- val attributeRewrites = AttributeMap (oldRelation.output.zip(newRelation.output))
322- val newRight = right transformUp {
323- case r if r == oldRelation => newRelation
324- } transformUp {
325- case other => other transformExpressions {
326- case a : Attribute => attributeRewrites.get(a).getOrElse(a)
327- }
312+ // Only handle first case, others will be fixed on the next pass.
313+ .headOption match {
314+ case None =>
315+ /*
316+ * No result implies that there is a logical plan node that produces new references
317+ * that this rule cannot handle. When that is the case, there must be another rule
318+ * that resolves these conflicts. Otherwise, the analysis will fail.
319+ */
320+ j
321+ case Some ((oldRelation, newRelation)) =>
322+ val attributeRewrites = AttributeMap (oldRelation.output.zip(newRelation.output))
323+ val newRight = right transformUp {
324+ case r if r == oldRelation => newRelation
325+ } transformUp {
326+ case other => other transformExpressions {
327+ case a : Attribute => attributeRewrites.get(a).getOrElse(a)
328+ }
329+ }
330+ j.copy(right = newRight)
328331 }
329- j.copy(right = newRight)
330332
331333 // When resolve `SortOrder`s in Sort based on child, don't report errors as
332334 // we still have chance to resolve it based on grandchild
0 commit comments