Github user nsyca commented on a diff in the pull request:
https://github.com/apache/spark/pull/16954#discussion_r103461455
--- 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.
--- End diff --
@dilipbiswal You probably are already on the right track that one of the
subquery expression is not required. I guess either `T1 intersect T1 where
exists (T2)` or a self-join scenario like `T1, T1 Tx where exists (T2 where
<Q>.col = T2.col)` with `<Q>` be `T1` or `Tx` should also do.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]