Class

org.apache.spark.sql

RelationalGroupedDataset

Related Doc: package sql

Permalink

class RelationalGroupedDataset extends AnyRef

A set of methods for aggregations on a DataFrame, created by Dataset.groupBy.

The main method is the agg function, which has multiple variants. This class also contains convenience some first order statistics such as mean, sum for convenience.

This class was named GroupedData in Spark 1.x.

Annotations
@Stable()
Source
RelationalGroupedDataset.scala
Since

2.0.0

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. RelationalGroupedDataset
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new RelationalGroupedDataset(df: DataFrame, groupingExprs: Seq[Expression], groupType: GroupType)

    Permalink
    Attributes
    protected[org.apache.spark.sql]

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. def agg(expr: Column, exprs: Column*): DataFrame

    Permalink

    Compute aggregates by specifying a series of aggregate columns.

    Compute aggregates by specifying a series of aggregate columns. Note that this function by default retains the grouping columns in its output. To not retain grouping columns, set spark.sql.retainGroupColumns to false.

    The available aggregate methods are defined in org.apache.spark.sql.functions.

    // Selects the age of the oldest employee and the aggregate expense for each department
    
    // Scala:
    import org.apache.spark.sql.functions._
    df.groupBy("department").agg(max("age"), sum("expense"))
    
    // Java:
    import static org.apache.spark.sql.functions.*;
    df.groupBy("department").agg(max("age"), sum("expense"));

    Note that before Spark 1.4, the default behavior is to NOT retain grouping columns. To change to that behavior, set config variable spark.sql.retainGroupColumns to false.

    // Scala, 1.3.x:
    df.groupBy("department").agg($"department", max("age"), sum("expense"))
    
    // Java, 1.3.x:
    df.groupBy("department").agg(col("department"), max("age"), sum("expense"));
    Annotations
    @varargs()
    Since

    1.3.0

  5. def agg(exprs: Map[String, String]): DataFrame

    Permalink

    (Java-specific) Compute aggregates by specifying a map from column name to aggregate methods.

    (Java-specific) Compute aggregates by specifying a map from column name to aggregate methods. The resulting DataFrame will also contain the grouping columns.

    The available aggregate methods are avg, max, min, sum, count.

    // Selects the age of the oldest employee and the aggregate expense for each department
    import com.google.common.collect.ImmutableMap;
    df.groupBy("department").agg(ImmutableMap.of("age", "max", "expense", "sum"));
    Since

    1.3.0

  6. def agg(exprs: Map[String, String]): DataFrame

    Permalink

    (Scala-specific) Compute aggregates by specifying a map from column name to aggregate methods.

    (Scala-specific) Compute aggregates by specifying a map from column name to aggregate methods. The resulting DataFrame will also contain the grouping columns.

    The available aggregate methods are avg, max, min, sum, count.

    // Selects the age of the oldest employee and the aggregate expense for each department
    df.groupBy("department").agg(Map(
      "age" -> "max",
      "expense" -> "sum"
    ))
    Since

    1.3.0

  7. def agg(aggExpr: (String, String), aggExprs: (String, String)*): DataFrame

    Permalink

    (Scala-specific) Compute aggregates by specifying the column names and aggregate methods.

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

    // Selects the age of the oldest employee and the aggregate expense for each department
    df.groupBy("department").agg(
      "age" -> "max",
      "expense" -> "sum"
    )
    Since

    1.3.0

  8. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  9. def avg(colNames: String*): DataFrame

    Permalink

    Compute the mean value for each numeric columns for each group.

    Compute the mean value for each numeric columns for each group. The resulting DataFrame will also contain the grouping columns. When specified columns are given, only compute the mean values for them.

    Annotations
    @varargs()
    Since

    1.3.0

  10. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  11. def count(): DataFrame

    Permalink

    Count the number of rows for each group.

    Count the number of rows for each group. The resulting DataFrame will also contain the grouping columns.

    Since

    1.3.0

  12. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  13. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  14. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  15. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  16. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  17. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  18. def max(colNames: String*): DataFrame

    Permalink

    Compute the max value for each numeric columns for each group.

    Compute the max value for each numeric columns for each group. The resulting DataFrame will also contain the grouping columns. When specified columns are given, only compute the max values for them.

    Annotations
    @varargs()
    Since

    1.3.0

  19. def mean(colNames: String*): DataFrame

    Permalink

    Compute the average value for each numeric columns for each group.

    Compute the average value for each numeric columns for each group. This is an alias for avg. The resulting DataFrame will also contain the grouping columns. When specified columns are given, only compute the average values for them.

    Annotations
    @varargs()
    Since

    1.3.0

  20. def min(colNames: String*): DataFrame

    Permalink

    Compute the min value for each numeric column for each group.

    Compute the min value for each numeric column for each group. The resulting DataFrame will also contain the grouping columns. When specified columns are given, only compute the min values for them.

    Annotations
    @varargs()
    Since

    1.3.0

  21. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  22. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  23. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  24. def pivot(pivotColumn: String, values: List[Any]): RelationalGroupedDataset

    Permalink

    Pivots a column of the current DataFrame and perform the specified aggregation.

    Pivots a column of the current DataFrame and perform the specified aggregation. There are two versions of pivot function: one that requires the caller to specify the list of distinct values to pivot on, and one that does not. The latter is more concise but less efficient, because Spark needs to first compute the list of distinct values internally.

    // Compute the sum of earnings for each year by course with each course as a separate column
    df.groupBy("year").pivot("course", Arrays.<Object>asList("dotNET", "Java")).sum("earnings");
    
    // Or without specifying column values (less efficient)
    df.groupBy("year").pivot("course").sum("earnings");
    pivotColumn

    Name of the column to pivot.

    values

    List of values that will be translated to columns in the output DataFrame.

    Since

    1.6.0

  25. def pivot(pivotColumn: String, values: Seq[Any]): RelationalGroupedDataset

    Permalink

    Pivots a column of the current DataFrame and perform the specified aggregation.

    Pivots a column of the current DataFrame and perform the specified aggregation. There are two versions of pivot function: one that requires the caller to specify the list of distinct values to pivot on, and one that does not. The latter is more concise but less efficient, because Spark needs to first compute the list of distinct values internally.

    // Compute the sum of earnings for each year by course with each course as a separate column
    df.groupBy("year").pivot("course", Seq("dotNET", "Java")).sum("earnings")
    
    // Or without specifying column values (less efficient)
    df.groupBy("year").pivot("course").sum("earnings")
    pivotColumn

    Name of the column to pivot.

    values

    List of values that will be translated to columns in the output DataFrame.

    Since

    1.6.0

  26. def pivot(pivotColumn: String): RelationalGroupedDataset

    Permalink

    Pivots a column of the current DataFrame and perform the specified aggregation.

    Pivots a column of the current DataFrame and perform the specified aggregation. There are two versions of pivot function: one that requires the caller to specify the list of distinct values to pivot on, and one that does not. The latter is more concise but less efficient, because Spark needs to first compute the list of distinct values internally.

    // Compute the sum of earnings for each year by course with each course as a separate column
    df.groupBy("year").pivot("course", Seq("dotNET", "Java")).sum("earnings")
    
    // Or without specifying column values (less efficient)
    df.groupBy("year").pivot("course").sum("earnings")
    pivotColumn

    Name of the column to pivot.

    Since

    1.6.0

  27. def sum(colNames: String*): DataFrame

    Permalink

    Compute the sum for each numeric columns for each group.

    Compute the sum for each numeric columns for each group. The resulting DataFrame will also contain the grouping columns. When specified columns are given, only compute the sum for them.

    Annotations
    @varargs()
    Since

    1.3.0

  28. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  29. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  30. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  31. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  32. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped