The user defined aggregate function (UDAF) operates upon more than one row while returning single value results. UDAF normally works in conjunction with a group by clause where some analysis or aggregation may be required on a set of data identified using the group by clause. In Spark, two different types of UDAF can be created untyped and type-safe UDAF.