Move aggregation preparation to a rewriter

Moves the isolating of aggregations into
one of the new rewriters working directly
on the AST.
Cleaned up imports
Merge pull request #2193 from systay/aggregation-isolation

Move another rewriter to the new AST