public abstract class Aggregator<I,B,O>
extends java.lang.Object
implements scala.Serializable
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
Constructor and Description |
---|
Aggregator() |
Modifier and Type | Method and Description |
---|---|
abstract O |
finish(B reduction)
Transform the output of the reduction.
|
abstract B |
merge(B b1,
B b2)
Merge two intermediate values.
|
abstract B |
reduce(B b,
I a)
Combine two values to produce a new value.
|
TypedColumn<I,O> |
toColumn(Encoder<B> bEncoder,
Encoder<O> cEncoder)
Returns this
Aggregator as a TypedColumn that can be used in Dataset or DataFrame
operations. |
abstract B |
zero()
A zero value for this aggregation.
|
public abstract B zero()
public abstract B reduce(B b, I a)
b
and
return it instead of constructing new object for b.b
- (undocumented)a
- (undocumented)public abstract B merge(B b1, B b2)
b1
- (undocumented)b2
- (undocumented)public abstract O finish(B reduction)
reduction
- (undocumented)