Adding support for aggregation of distinct streams. I also added support
for distinct() and select() in subqueries, and refactored subquery
transform code so that they share code with normal non-subquery
transform code.