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

    https://github.com/apache/spark/pull/17428#discussion_r108222730
  
    --- 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 --
    
    I guess your test case depends on the fact that currently we don't have an 
optimization to push down table y below the join of (x, z).
    
    Essentially, this is not a problem specifically to `ReorderJoin` as implied 
from the title of the PR. The problem is at the definition 
`canEvaluateWithinJoin`. I can demonstrate the same problem without the table y 
in this test case.
    
    A slight modification of your test case as shown below also reveals the 
problem.
    
    ````
        val queryPlan = x.join(z)
          .where(("x.b".attr === "z.b".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)
    ````
    
    which has a call to `canEvaluateWithinJoin` from the rule 
`PushPredicateThroughJoin`.
    



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