Github user dilipbiswal commented on a diff in the pull request: https://github.com/apache/spark/pull/16954#discussion_r103363226 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala --- @@ -707,13 +709,85 @@ class Analyzer( } transformUp { case other => other transformExpressions { case a: Attribute => - attributeRewrites.get(a).getOrElse(a).withQualifier(a.qualifier) + dedupAttr(a, attributeRewrites) + case s: SubqueryExpression => + s.withNewPlan(dedupOuterReferencesInSubquery(s.plan, attributeRewrites)) } } newRight } } + private def dedupAttr(attr: Attribute, attrMap: AttributeMap[Attribute]): Attribute = { + attrMap.get(attr).getOrElse(attr).withQualifier(attr.qualifier) + } + + /** + * The outer plan may have been de-duplicated and the function below updates the + * outer references to refer to the de-duplicated attributes. + * + * For example (SQL): + * {{{ + * SELECT * FROM t1 + * WHERE EXISTS (SELECT 1 + * FROM t2 + * WHERE t1.c1 = t2.c1) + * INTERSECT + * SELECT * FROM t1 + * WHERE EXISTS (SELECT 1 + * FROM t2 + * WHERE t1.c1 = t2.c1) + * }}} + * Plan before resolveReference rule. + * 'Intersect + * :- 'Project [*] + * : +- Filter exists#271 [c1#250] + * : : +- Project [1 AS 1#295] + * : : +- Filter (outer(c1#250) = c1#263) + * : : +- SubqueryAlias t2 + * : : +- Relation[c1#263,c2#264] parquet + * : +- SubqueryAlias t1 + * : +- Relation[c1#250,c2#251] parquet + * +- 'Project [*] + * +- Filter exists#272 [c1#250] + * : +- Project [1 AS 1#298] + * : +- Filter (outer(c1#250) = c1#263) + * : +- SubqueryAlias t2 + * : +- Relation[c1#263,c2#264] parquet + * +- SubqueryAlias t1 + * +- Relation[c1#250,c2#251] parquet + * Plan after the resolveReference rule. + * Intersect + * :- Project [c1#250, c2#251] + * : +- Filter exists#271 [c1#250] + * : : +- Project [1 AS 1#295] + * : : +- Filter (outer(c1#250) = c1#263) + * : : +- SubqueryAlias t2 + * : : +- Relation[c1#263,c2#264] parquet + * : +- SubqueryAlias t1 + * : +- Relation[c1#250,c2#251] parquet + * +- Project [c1#299, c2#300] + * +- Filter exists#272 [c1#299] --- End diff -- @hvanhovell Thanks.. will change.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org