Github user felixcheung commented on a diff in the pull request:
https://github.com/apache/spark/pull/17807#discussion_r114058157
--- Diff: R/pkg/R/functions.R ---
@@ -3803,3 +3803,89 @@ setMethod("repeat_string",
jc <- callJStatic("org.apache.spark.sql.functions", "repeat",
x@jc, numToInt(n))
column(jc)
})
+
+#' is_grouping
+#'
+#' Indicates whether a specified column in a GROUP BY list is aggregated
or not,
+#' returns 1 for aggregated or 0 for not aggregated in the result set.
+#'
+#' Same as \code{GROUPING} in SQL and \code{grouping} function in Scala.
+#'
+#' @param x Column to compute on
+#'
+#' @rdname is_grouping
+#' @name is_grouping
+#' @family agg_funcs
+#' @aliases is_grouping,Column-method
+#' @export
+#' @examples \dontrun{
+#' df <- createDataFrame(mtcars)
+#'
+#' # With cube
+#' agg(
+#' cube(df, "cyl", "gear", "am"),
+#' mean(df$mpg),
+#' is_grouping(df$cyl), is_grouping(df$gear), is_grouping(df$am)
+#' )
+#'
+#' # With rollup
+#' agg(
+#' rollup(df, "cyl", "gear", "am"),
+#' mean(df$mpg),
+#' is_grouping(df$cyl), is_grouping(df$gear), is_grouping(df$am)
+#' )
+#' }
+#' @note is_grouping since 2.3.0
+#' @seealso \link{cube}, \link{grouping_id}, \link{rollup}
+setMethod("is_grouping",
+ signature(x = "Column"),
+ function(x) {
+ jc <- callJStatic("org.apache.spark.sql.functions",
"grouping", x@jc)
+ column(jc)
+ })
+
+#' grouping_id
+#'
+#' Returns the level of grouping.
+#'
+#' Equals to \code{
+#' (is_grouping(c1) <<; (n-1)) + (is_grouping(c2) <<; (n-2)) + ... +
is_grouping(cn)
--- End diff --
also perhaps it's more appropriate to use the R-equivalent operator instead?
---
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]