GitHub user dilipbiswal opened a pull request:
https://github.com/apache/spark/pull/13483
[SPARK-15688] RelationalGroupedDataset.toDF should not add group by
xpressions that are already added in the aggregate expressions
## What changes were proposed in this pull request?
The dataset aggregate methods (agg) computes aggregates and produces
the resulting dataset. Currently the resulting data set includes the
grouping columns even though the aggregation expression already
contains the columns resulting in duplicate columns.
```SQL
val df = Seq(1 -> "a", 2 -> "b", 3 -> "b").toDF("col1", "col2")
val df1 = df.groupBy("col1").agg($"col1", count("*")).show()
+----+----+--------+
|col1|col1|count(1)|
+----+----+--------+
| 3| 3| 1|
| 1| 1| 1|
| 2| 2| 1|
+----+----+--------+
```
This PR addresses the problem by only including grouping columns
in the dataset if they were not already contained by the aggregate
expressions.
```SQL
val df1 = df.groupBy("col1").agg($"col1", count("*")).show()
+----+--------+
|col1|count(1)|
+----+--------+
| 3| 1|
| 1| 1|
| 2| 1|
+----+--------+
```
## How was this patch tested?
Added tests in DatasetAggregatorSuite
(If this patch involves UI changes, please attach a screenshot; otherwise,
remove this)
â¦xpressions that are already added in the aggregate expressions
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/dilipbiswal/spark spark-15688
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/13483.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 #13483
----
commit 393f589225c1e650204654acf3143df99c8c7275
Author: Dilip Biswal <[email protected]>
Date: 2016-06-02T07:46:33Z
[SPARK-15688] RelationalGroupedDataset.toDF should not add group by
expressions that are already added in the aggregate 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]