Revert "Fix query builder generation of aggregates"

This reverts commit d177810fd246aa6025b7f36f2fe8fe33a081d6c9.

The changes done by the upstream repo to resolve the problem supercede
and will conflict with these changes.