org.apache.spark.sql.expressions

Aggregator

abstract class Aggregator[-I, B, O] extends Serializable

A base class for user-defined aggregations, which can be used in DataFrame and Dataset operations to take all of the elements of a group and reduce them to a single value.

For example, the following aggregator extracts an int from a specific class and adds them up:

case class Data(i: Int)

val customSummer =  new Aggregator[Data, Int, Int] {
  def zero: Int = 0
  def reduce(b: Int, a: Data): Int = b + a.i
  def merge(b1: Int, b2: Int): Int = b1 + b2
  def finish(r: Int): Int = r
}.toColumn()

val ds: Dataset[Data] = ...
val aggregated = ds.select(customSummer)

Based loosely on Aggregator from Algebird: https://github.com/twitter/algebird

I

The input type for the aggregation.

B

The type of the intermediate value of the reduction.

O

The type of the final output result.

Source
Aggregator.scala
Since

1.6.0

Linear Supertypes
Serializable, Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Aggregator
  2. Serializable
  3. Serializable
  4. AnyRef
  5. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Aggregator()

Abstract Value Members

  1. abstract def finish(reduction: B): O

    Transform the output of the reduction.

    Transform the output of the reduction.

    Since

    1.6.0

  2. abstract def merge(b1: B, b2: B): B

    Merge two intermediate values.

    Merge two intermediate values.

    Since

    1.6.0

  3. abstract def reduce(b: B, a: I): B

    Combine two values to produce a new value.

    Combine two values to produce a new value. For performance, the function may modify b and return it instead of constructing new object for b.

    Since

    1.6.0

  4. abstract def zero: B

    A zero value for this aggregation.

    A zero value for this aggregation. Should satisfy the property that any b + zero = b.

    Since

    1.6.0

Concrete Value Members

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

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

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

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. final def eq(arg0: AnyRef): Boolean

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

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

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

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

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

    Definition Classes
    Any
  14. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  15. final def notify(): Unit

    Definition Classes
    AnyRef
  16. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  17. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  18. def toColumn(implicit bEncoder: Encoder[B], cEncoder: Encoder[O]): TypedColumn[I, O]

    Returns this Aggregator as a TypedColumn that can be used in Dataset or DataFrame operations.

    Returns this Aggregator as a TypedColumn that can be used in Dataset or DataFrame operations.

    Since

    1.6.0

  19. def toString(): String

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

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

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

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Serializable

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped