DISTINCT not being handled correctly in RelToSqlConverter
When creating a RelNode for a Query with a DISTINCT keyword in it, I use
the relBuilder.distinct() api to apply distinct.
It creates a LogicalAggregate with all the Fields of the LogicalProject as
This is a problem when one of those projections is a windowing function
(i.e SUM(col1) over (partition by col2) ).
The group by key now contains an aggregate function which is wrong.
The output is something like( SqlNode.toSqlString() ):-
SELECT sum(col1) OVER (partition by col2) from t1 group by sum(col1) over
(partition by col2).
I have a fix ready for this.
Basically, sub-querying the projection containing the aggregate function
and apply the Group By(due to DISTINCT) outside the sub-query.
Please let me know if this is an actual bug or my assumptions are wrong.