What is the user of user-defined aggregate function (UDAF) and when to use?

What is the user of user-defined aggregate function (UDAF) and when to use?

I have gone through above link but I didn’t get the concept. Please guide me when to use it and how to use it.

When you want to aggregate data in a way that can’t easily be done with the built-in aggregates like SUM, COUNT, MAX, and so on, you can create a UDAF to do it. For example, suppose you have a table like

objects(id,lower_x, lower_y, upper_x, upper_y, property1, property2)

where lower_x, lower_y, upper_x, upper_y define the bounding box of the object. And you want to know the overall bounding box of the objects with property1=“red”. Then you could create a UDAF bounding_box() to do it. E.g. with a query like:

select bounding_box(lower_x, lower_y, upper_x, upper_y) as bb
from objects
where property1=“red”;

could you elaborate it with more explanation,please?