Github user nsyca commented on the issue:

    https://github.com/apache/spark/pull/15763
  
    @hvanhovell Then we will need to walk from the top of the operator hosting 
the outer reference to the operator hosting the correlation to ensure there is 
no Aggregate or Window operator.
    
    If this is the algorithm you have in mind, I will see how I could implement 
it in an effective way.
    
    Examples are:
    ````
    // Case 1: agg func
    Seq((1,1)).toDF("c1","c2").createOrReplaceTempView("t1")
    Seq((1,1),(2,0)).toDF("c1","c2").createOrReplaceTempView("t2")
    // Case 1A: Simplest case Aggregate is immediately under Project and over 
the correlation point
    sql("""
    | select t1.c1
    | from t1
    | where t1.c1 in (select max(t2.c1) 
    |                 from t2 where t1.c2 >= t2.c2)
    """.stripMargin).show
    // Case 1B: Project - Filter - Aggregate - [correlation point]
    // Project is the operator immediately over T1, the source of the outer 
reference
    // There is a Filter (hosting the HAVING logic) in between
    sql("""
    | select t1.c1
    | from t1
    | where t1.c1 in (select max(t2.c1)
    |                 from t2
    |                 where t1.c2 >= t2.c2
    |                 having count(*) > 0 )
    """.stripMargin).show
    
    // And the list can go on and on such as this one that
    // Case 1C:  Insert a layer of SELECT on top of Case 1B
    sql("""
    | select t1.c1 
    | from t1
    | where t1.c1 in (select maxc+1
    |                 from (select max(t2.c1) as maxc
    |                       from t2
    |                       where t1.c2 >= t2.c2
    |                       having count(*) > 0 ))
    """.stripMargin).show
    ````
    ````
    // Here is the LogicalPlan at the point of checking for Case 1C
    Project [(maxc#161 + 1) AS (maxc + 1)#167, c2#103]  <-- This is the Project 
hosting the outer reference T1.C1
    +- Project [maxc#161, c2#103]
       +- Filter (count(1)#166L > cast(0 as bigint))
          +- Aggregate [c2#103], [max(c1#102) AS maxc#161, count(1) AS 
count(1)#166L, c2#103]
             +- SubqueryAlias t2, `t2`   <-- The boundary of Subquery
                +- Project [_1#99 AS c1#102, _2#100 AS c2#103]
                   +- LocalRelation [_1#99, _2#100]
    ````



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