GitHub user dilipbiswal opened a pull request:

    https://github.com/apache/spark/pull/17636

    [SPARK-20334][SQL] Return a better error message when correlated predicates 
contain aggregate expression that has mixture of outer and local references.

    ## What changes were proposed in this pull request?
    Address a follow up in 
[comment](https://github.com/apache/spark/pull/16954#discussion_r105718880)
    Currently subqueries with correlated predicates containing aggregate 
expression having mixture of outer references and local references generate a 
codegen error like following :
    
    ```SQL
    SELECT t1a 
    FROM   t1
    GROUP  BY 1
    HAVING EXISTS (SELECT 1 
                   FROM  t2
                   WHERE t2a < min(t1a + t2a));
    ```
    Exception snippet.
    ```
    Cannot evaluate expression: min((input[0, int, false] + input[4, int, 
false]))
        at 
org.apache.spark.sql.catalyst.expressions.Unevaluable$class.doGenCode(Expression.scala:226)
        at 
org.apache.spark.sql.catalyst.expressions.aggregate.AggregateExpression.doGenCode(interfaces.scala:87)
        at 
org.apache.spark.sql.catalyst.expressions.Expression$$anonfun$genCode$2.apply(Expression.scala:106)
        at 
org.apache.spark.sql.catalyst.expressions.Expression$$anonfun$genCode$2.apply(Expression.scala:103)
        at scala.Option.getOrElse(Option.scala:121)
        at 
org.apache.spark.sql.catalyst.expressions.Expression.genCode(Expression.scala:103)
        
    ```
    After this PR, a better error message is issued.
    ```
    org.apache.spark.sql.AnalysisException
    Found an aggregate expression in a correlated predicate that has both outer 
and 
    local references, which is not supported yet. 
    Aggregate expression: min((t2.`t2a` + t3.`t3a`)) 
    Outer references: t2.`t2a` 
    Local references: t3.`t3a`;
    ```
    ## How was this patch tested?
    Added tests in SQLQueryTestSuite.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/dilipbiswal/spark subquery_followup1

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/17636.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #17636
    
----
commit a266c8d70df279fb079fcfde8f849dcfd6646bbc
Author: Dilip Biswal <[email protected]>
Date:   2017-03-23T06:57:12Z

    [SPARK-20334] Return a better error message when correlated predicates 
contain aggregate expression that has mixture of outer and local references

----


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