zhengruifeng commented on code in PR #43813:
URL: https://github.com/apache/spark/pull/43813#discussion_r1398628293
##########
sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala:
##########
@@ -1825,6 +1825,33 @@ class Dataset[T] private[sql](
RelationalGroupedDataset(toDF(), cols.map(_.expr),
RelationalGroupedDataset.CubeType)
}
+ /**
+ * Create multi-dimensional aggregation for the current Dataset using the
specified grouping sets,
+ * so we can run aggregation on them.
+ * See [[RelationalGroupedDataset]] for all the available aggregate
functions.
+ *
+ * {{{
+ * // Compute the average for all numeric columns group by specific
grouping sets.
+ * ds.groupingSets(Seq(Seq($"department", $"group"),Seq()),$"department",
$"group").avg()
+ *
+ * // Compute the max age and average salary, group by specific grouping
sets.
+ * ds.groupingSets(Seq($"department", $"gender"), Seq()),$"department",
$"group").agg(Map(
+ * "salary" -> "avg",
+ * "age" -> "max"
+ * ))
+ * }}}
+ *
+ * @group untypedrel
+ * @since 4.0.0
+ */
+ @scala.annotation.varargs
+ def groupingSets(
+ groupingSets: Seq[Seq[Column]],
+ cols: Column*): RelationalGroupedDataset = {
Review Comment:
```suggestion
groupingSets: Seq[Seq[Column]],
cols: Column*): RelationalGroupedDataset = {
```
##########
sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala:
##########
@@ -1960,6 +1987,42 @@ class Dataset[T] private[sql](
toDF(), colNames.map(colName => resolve(colName)),
RelationalGroupedDataset.CubeType)
}
+ /**
+ * Create multi-dimensional aggregation for the current Dataset using the
specified grouping sets,
+ * so we can run aggregation on them.
+ * See [[RelationalGroupedDataset]] for all the available aggregate
functions.
+ *
+ * This is a variant of groupingSets that can only group by existing columns
using column names
+ * (i.e. cannot construct expressions).
+ *
+ * {{{
+ * // Compute the average for all numeric columns group by specific
grouping sets.
+ * ds.groupingSets(Seq(Seq("department", "group"),Seq()),"department",
"group").avg()
+ *
+ * // Compute the max age and average salary, group by specific grouping
sets.
+ * ds.groupingSets(Seq($"department", $"gender"), Seq($"department"),
Seq()).agg(Map(
+ * "salary" -> "avg",
+ * "age" -> "max"
+ * ))
+ * }}}
+ *
+ * @group untypedrel
+ * @since 4.0.0
+ */
+ @scala.annotation.varargs
+ def groupingSets(
+ groupingSets: Seq[Seq[String]],
+ col1: String,
+ cols: String*): RelationalGroupedDataset = {
Review Comment:
```suggestion
groupingSets: Seq[Seq[String]],
col1: String,
cols: String*): RelationalGroupedDataset = {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]