A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://spark.apache.org/docs/latest/api/java/org/apache/spark/sql/expressions/Aggregator.html below:

Aggregator (Spark 4.0.0 JavaDoc)

Object

org.apache.spark.sql.expressions.Aggregator<IN,BUF,OUT>

All Implemented Interfaces:
Serializable, org.apache.spark.sql.internal.UserDefinedFunctionLike
public abstract class Aggregator<IN,BUF,OUT> extends Object implements Serializable, org.apache.spark.sql.internal.UserDefinedFunctionLike

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
     def bufferEncoder: Encoder[Int] = Encoders.scalaInt
     def outputEncoder: Encoder[Int] = Encoders.scalaInt
   }.toColumn()

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

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

Since:
1.6.0
See Also:

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4