This is the sixteenth part of the SQLxD series. For your convenience you can find other parts in the table of contents in Part 1 – XML Transformation

Today we implement various aggregates. Let’s start with the interface:

We can see that the aggregate returns one cell for whole relation. You might wonder why is it implemented this way but it will be clear when we come to selection. And now the implementations, we begin with simple COUNT working on the whole relation:

We simply return the number of rows.

In order to implement other aggregates, let’s start with base class for aggregate working on single column:

And now specific implementation for COUNT:

As we can see, base class iterates over rows and the specific implementation handles logic. That’s all. Other aggregates are pretty straightforward:

And that’s all.