Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class RelationalGroupedDataset protected[sql](
}

/**
* (Scala-specific) Compute aggregates by specifying a map from column name to
* (Scala-specific) Compute aggregates by specifying the column names and
* aggregate methods. The resulting [[DataFrame]] will also contain the grouping columns.
*
* The available aggregate methods are `avg`, `max`, `min`, `sum`, `count`.
Expand All @@ -143,7 +143,9 @@ class RelationalGroupedDataset protected[sql](
* @since 1.3.0
*/
def agg(aggExpr: (String, String), aggExprs: (String, String)*): DataFrame = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we should also fix the doc of this method Compute aggregates by specifying a map...

agg((aggExpr +: aggExprs).toMap)
toDF((aggExpr +: aggExprs).map { case (colName, expr) =>
strToExpr(expr)(df(colName).expr)
})
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ class DataFrameAggregateSuite extends QueryTest with SharedSQLContext {
)
}

test("SPARK-17124 agg should be ordering preserving") {
val df = spark.range(2)
val ret = df.groupBy("id").agg("id" -> "sum", "id" -> "count", "id" -> "min")
assert(ret.schema.map(_.name) == Seq("id", "sum(id)", "count(id)", "min(id)"))
checkAnswer(
ret,
Row(0, 0, 1, 0) :: Row(1, 1, 1, 1) :: Nil
)
}

test("rollup") {
checkAnswer(
courseSales.rollup("course", "year").sum("earnings"),
Expand Down