citusdata / citus

Distributed PostgreSQL as an extension
https://www.citusdata.com
GNU Affero General Public License v3.0
10.59k stars 671 forks source link

Reduce code duplication in aggregate logic #2192

Open furkansahin opened 6 years ago

furkansahin commented 6 years ago

In Citus, we support aggregate functions by whitelisting them in planning time by ingesting proper aggregate functions into the worker and master queries separately. We process the aggregates in MasterAggregateExpression and WorkerAggregateExpressionList.

If we inspect the code paths in these functions, we can easily see that there are a good amount of code duplications in between the if - else if blocks. For example, these two PRs are almost identical, #2186 and #2175.

We need more generic functions to produce the necessary aggregates from the given master and worker aggregate function names. One very basic and (not even) a half implemented method for master aggregate can be seen in custom_aggregate_support branch in this line

marcocitus commented 6 years ago

We already have an issue on custom aggregates: https://github.com/citusdata/citus/issues/120 , renaming this issue.