Class

org.apache.spark.sql.expressions

Aggregator

Related Doc: package expressions

Permalink

abstract class Aggregator[-IN, BUF, OUT] extends Serializable

:: Experimental :: A base class for user-defined aggregations, which can be used in 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

IN

The input type for the aggregation.

BUF

The type of the intermediate value of the reduction.

OUT

The type of the final output result.

Annotations
@Experimental() @Evolving()
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
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Aggregator()

    Permalink

Abstract Value Members

  1. abstract def bufferEncoder: Encoder[BUF]

    Permalink

    Specifies the Encoder for the intermediate value type.

    Specifies the Encoder for the intermediate value type.

    Since

    2.0.0

  2. abstract def finish(reduction: BUF): OUT

    Permalink

    Transform the output of the reduction.

    Transform the output of the reduction.

    Since

    1.6.0

  3. abstract def merge(b1: BUF, b2: BUF): BUF

    Permalink

    Merge two intermediate values.

    Merge two intermediate values.

    Since

    1.6.0

  4. abstract def outputEncoder: Encoder[OUT]

    Permalink

    Specifies the Encoder for the final ouput value type.

    Specifies the Encoder for the final ouput value type.

    Since

    2.0.0

  5. abstract def reduce(b: BUF, a: IN): BUF

    Permalink

    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

  6. abstract def zero: BUF

    Permalink

    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: 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. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

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

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

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

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

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

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

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

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

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

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

    Permalink
    Definition Classes
    AnyRef
  16. def toColumn: TypedColumn[IN, OUT]

    Permalink

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

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

    Since

    1.6.0

  17. def toString(): String

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

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

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

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

Inherited from Serializable

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped