Github user dilipbiswal commented on a diff in the pull request:
https://github.com/apache/spark/pull/22141#discussion_r211839392
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/subquery.scala
---
@@ -137,13 +137,21 @@ object RewritePredicateSubquery extends
Rule[LogicalPlan] with PredicateHelper {
plan: LogicalPlan): (Option[Expression], LogicalPlan) = {
var newPlan = plan
val newExprs = exprs.map { e =>
- e transformUp {
+ e transformDown {
case Exists(sub, conditions, _) =>
val exists = AttributeReference("exists", BooleanType, nullable
= false)()
// Deduplicate conflicting attributes if any.
newPlan = dedupJoin(
Join(newPlan, sub, ExistenceJoin(exists),
conditions.reduceLeftOption(And)))
exists
+ case (Not(InSubquery(values, ListQuery(sub, conditions, _, _)))) =>
+ val exists = AttributeReference("exists", BooleanType, nullable
= false)()
--- End diff --
@maropu The common method looks like this -
``` scala
def getCommonParams(
values: Seq[Expression],
sub: LogicalPlan) : (AttributeReference, Seq[Expression]) = {
(
AttributeReference("exists", BooleanType, nullable = false)(),
values.zip(sub.output).map(EqualTo.tupled)
)
}
```
Not much in terms of lines saved since things don't fit in single line..
You still wanted to do it :-) ?
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]