Convert a PlainSelect into an Operator + A projection map.
Convert a SelectBody into an Operator + A projection map.
Split an aggregate target expression into its component parts.
This is needed to handle complex aggregate expressions.
For example (if X is a group-by var):
> X + SUM(Y) / COUNT(*) AS FOO
This expression will return:
> X + (FOO_1_0 / FOO_1_1)
> [(SUM, [Y], FOO_1_0), (COUNT, , FOO_1_1)]
In short, this function descends through the expression tree
and picks out all aggregates and var leaves that it hits.
Aggregate expressions are removed from the nested expression
and replaced by unique placeholder variables (as long as
alias is a unique prefix), and the entire expression is
- Raw Variables are returned in the second tuple element
- Aggregates are returned in the third tuple element
Unique placeholder variables are assigned unique names based
on the path through the operator tree.