GitHub user marmbrus opened a pull request:

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

    [SPARK-11404] [SQL] Support for groupBy using column expressions

    This PR adds a new method `groupBy(cols: Column*)` to `Dataset` that allows 
users to group using column expressions instead of a lambda function.  Since 
the return type of these expressions is not known at compile time, we just set 
the key type as a generic `Row`.  If the user would like to work the key in a 
type-safe way, they can call `grouped.asKey[Type]`, which is also added in this 
PR.
    
    ```scala
    val ds = Seq(("a", 10), ("a", 20), ("b", 1), ("b", 2), ("c", 1)).toDS()
    val grouped = ds.groupBy($"_1").asKey[String]
    val agged = grouped.mapGroups { case (g, iter) =>
      Iterator((g, iter.map(_._2).sum))
    }
    
    agged.collect()
    
    res0: Array(("a", 30), ("b", 3), ("c", 1))
    ```

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

    $ git pull https://github.com/marmbrus/spark columnGroupBy

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

    https://github.com/apache/spark/pull/9359.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 #9359
    
----
commit 0b0e2f880518e2b4b2b5ea025bf76345c48775c2
Author: Michael Armbrust <[email protected]>
Date:   2015-10-29T15:22:03Z

    [SPARK-11404] [SQL] Support for groupBy using column expressions

----


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