cube2222 / octosql

OctoSQL is a query tool that allows you to join, analyse and transform data from multiple databases and file formats using SQL.
Mozilla Public License 2.0
4.74k stars 201 forks source link

GroupBy dimension not work, need replace with distinct #321

Open Lvnszn opened 1 year ago

Lvnszn commented 1 year ago
select cname from dual group by cname

the sql will return the same value in one column.

cube2222 commented 1 year ago

I think this is a bug in the current sql->logical plan transform.

Right now it treats a query as a grouping if there's at least one aggregate function (so it works for whole-table aggregates).

This could be fixed to treat a query as a grouping if there's either at least on aggregate function, or at least one grouped-by field.

Lvnszn commented 1 year ago

how do i fix this bug?

cube2222 commented 1 year ago

You can try to change the ParseSelect function in parser/parser.go so that isGroupBy is true not only when there's an aggregate used, but when statement.GroupBy is non-empty.