GitHub user maropu opened a pull request:

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

    [SPARK-20390][SQL] Respect deterministic in AttributeReference

    ## What changes were proposed in this pull request?
    This pr respected the `deterministic` properties of query plans in 
`AttributeReference`.
    Only deterministic expressions can exist in grouping keys though, 
non-deterministic one could exist there in some cases. This is because 
`AttributeReference` does not respect `deterministic` properties in query 
plans. A example is as follows;
    
    ```
    scala> val df = sql("""select rand(0), count(1) group by 1""")
    df: org.apache.spark.sql.DataFrame = [rand(0): double, count(1): bigint]
    
    scala> df.explain(true)
    == Parsed Logical Plan ==
    'Aggregate [1], [unresolvedalias('rand(0), None), 
unresolvedalias('count(1), None)]
    +- OneRowRelation$
    
    == Analyzed Logical Plan ==
    rand(0): double, count(1): bigint
    Aggregate [_nondeterministic#92], [_nondeterministic#92 AS rand(0)#90, 
count(1) AS count(1)#91L]
    +- Project [rand(0) AS _nondeterministic#92]
       +- OneRowRelation$
    
    == Optimized Logical Plan ==
    Aggregate [_nondeterministic#92], [_nondeterministic#92 AS rand(0)#90, 
count(1) AS count(1)#91L]
    +- Project [rand(0) AS _nondeterministic#92]
       +- OneRowRelation$
    
    == Physical Plan ==
    *HashAggregate(keys=[_nondeterministic#92], functions=[count(1)], 
output=[rand(0)#90, count(1)#91L])
    +- Exchange hashpartitioning(_nondeterministic#92, 200)
       +- *HashAggregate(keys=[_nondeterministic#92], 
functions=[partial_count(1)], output=[_nondeterministic#92, count#94L])
          +- *Project [rand(0) AS _nondeterministic#92]
             +- Scan OneRowRelation[]
    
    scala> df.show
    +------------------+--------+
    |           rand(0)|count(1)|
    +------------------+--------+
    |0.8446490682263027|       1|
    +------------------+--------+
    ```
    
    ## How was this patch tested?
    Existing tests

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

    $ git pull https://github.com/maropu/spark SPARK-20390

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

    https://github.com/apache/spark/pull/17685.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 #17685
    
----
commit 3e9d9a619507cf10a7f67bd9f701a38137043378
Author: Takeshi Yamamuro <[email protected]>
Date:   2017-04-19T13:27:03Z

    Respect deterministic in AttributeReference

----


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