Github user nsyca commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17428#discussion_r108218188
  
    --- Diff: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/JoinOptimizationSuite.scala
 ---
    @@ -123,6 +136,31 @@ class JoinOptimizationSuite extends PlanTest {
         }
       }
     
    +  test("reorder inner joins - don't put predicate with IN subquery into 
join condition") {
    +    // ReorderJoin collects all predicates and try to put them into join 
condition when creating
    +    // ordered join. If a predicate with an IN subquery is in a join 
condition instead of a filter
    +    // condition, `RewritePredicateSubquery.rewriteExistentialExpr` would 
fail to convert the
    +    // subquery to an ExistenceJoin, and thus result in error.
    +    val x = testRelation.subquery('x)
    +    val y = testRelation1.subquery('y)
    +    val z = testRelation.subquery('z)
    +    val w = testRelation1.subquery('w)
    +    val exists: AttributeReference = AttributeReference("exists", 
BooleanType, nullable = false)()
    +
    +    val queryPlan = x.join(y).join(z)
    +      .where(("x.b".attr === "z.b".attr) && ("y.d".attr === "z.a".attr) &&
    +        ("x.a".attr > 1 || "z.c".attr.in(ListQuery(w.select("w.d".attr)))))
    +
    +    val expectedPlan = x.join(z, Inner, Some("x.b".attr === "z.b".attr))
    +      .join(w, ExistenceJoin(exists), Some("z.c".attr === "w.d".attr))
    +      .where("x.a".attr > 1 || exists)
    +      .select("x.a".attr, "x.b".attr, "x.c".attr, "z.a".attr, "z.b".attr, 
"z.c".attr)
    +      .join(y, Inner, Some("y.d".attr === "z.a".attr))
    --- End diff --
    
    My question was why Optimizer does not pick a plan of Join( Join(y, z), x). 


---
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]

Reply via email to