GitHub user mortada opened a pull request:

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

    [Documentation] fixed groupby aggregation example for pyspark

    ## What changes were proposed in this pull request?
    
    fixing documentation for the groupby/agg example in python
    
    ## How was this patch tested?
    
    the existing example in the documentation dose not contain valid syntax 
(missing parenthesis) and is not using `Column` in the expression for `agg()`
    
    after the fix here's how I tested it:
    
    ```
    In [1]: from pyspark.sql import Row
    
    In [2]: import pyspark.sql.functions as func
    
    In [3]: %cpaste
    Pasting code; enter '--' alone on the line to stop or use Ctrl-D.
    :records = [{'age': 19, 'department': 1, 'expense': 100},
    : {'age': 20, 'department': 1, 'expense': 200},
    : {'age': 21, 'department': 2, 'expense': 300},
    : {'age': 22, 'department': 2, 'expense': 300},
    : {'age': 23, 'department': 3, 'expense': 300}]
    :--
    
    In [4]: df = sqlContext.createDataFrame([Row(**d) for d in records])
    
    In [5]: df.groupBy("department").agg(df["department"], func.max("age"), 
func.sum("expense")).show()
    
    +----------+----------+--------+------------+
    |department|department|max(age)|sum(expense)|
    +----------+----------+--------+------------+
    |         1|         1|      20|         300|
    |         2|         2|      22|         600|
    |         3|         3|      23|         300|
    +----------+----------+--------+------------+


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

    $ git pull https://github.com/mortada/spark groupby_agg_doc_fix

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

    https://github.com/apache/spark/pull/13587.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 #13587
    
----
commit 783415c9424cb6db1333aa5bc3ccd3cd1b227204
Author: Mortada Mehyar <[email protected]>
Date:   2016-06-10T02:34:16Z

    [Documentation] fixed groupby aggregation example for pyspark

----


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