You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Soumyakanti Das (Jira)" <ji...@apache.org> on 2021/08/10 15:49:00 UTC
[jira] [Comment Edited] (CALCITE-4702) Error when executing query
with GROUP BY constant via JDBC adapter
[ https://issues.apache.org/jira/browse/CALCITE-4702?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17396749#comment-17396749 ]
Soumyakanti Das edited comment on CALCITE-4702 at 8/10/21, 3:48 PM:
--------------------------------------------------------------------
I think we can introduce a new method in {{SqlDialect}} like public {{List<SqlNode> transformGroupKeys(List<SqlNode> groupKeys)}} which will simply return the list. And this method can be overridden in {{RedshiftSqlDialect}}, etc, to loop over the keys and transform the constant fields. The method {{transformGroupKeys}} can be called right after populating the {{groupKeys}} in {{RelToSqlConverter.generateGroupList}}.
If you all agree with the API, I can start working on a PR.
Also, regarding the transformation itself there are two ways we can go about it.
1. Transform GROUP BY <any constant> to GROUP BY (SELECT 1)
2. Transform GROUP BY true -> GROUP BY (SELECT true), GROUP BY 'a' -> GROUP BY (SELECT 'a'), etc.
Do let me know what your thoughts are regarding these transformations.
was (Author: soumyakanti.das):
I think we can introduce a new method in `SqlDialect` like `public List<SqlNode> transformGroupKeys(List<SqlNode> groupKeys)` which will simply return the list. And this method can be overridden in `RedshiftSqlDialect`, etc, to loop over the keys and transform the constant fields. The method `transformGroupKeys` can be called right after populating the `groupKeys` in `RelToSqlConverter.generateGroupList`.
If you all agree with the API, I can start working on a PR.
Also, regarding the transformation itself there are two ways we can go about it.
1. Transform GROUP BY <any constant> to GROUP BY (SELECT 1)
2. Transform GROUP BY true -> GROUP BY (SELECT true), GROUP BY 'a' -> GROUP BY (SELECT 'a'), etc.
Do let me know what your thoughts are regarding these transformations.
> Error when executing query with GROUP BY constant via JDBC adapter
> ------------------------------------------------------------------
>
> Key: CALCITE-4702
> URL: https://issues.apache.org/jira/browse/CALCITE-4702
> Project: Calcite
> Issue Type: Bug
> Components: core, jdbc-adapter
> Affects Versions: 1.27.0
> Reporter: Stamatis Zampetakis
> Assignee: Stamatis Zampetakis
> Priority: Major
>
> The following functionally equivalent SQL queries are accepted by Calcite and produce a valid plan
> {noformat}
> select avg(salary) from employee group by true
> select avg(salary) from employee group by 'a'
> {noformat}
> but they may fail if they are executed via the JDBC adapter since not all DBMS allow grouping by constants expressions. Moreover, what works for one may not work for the other.
> +Examples+
> The {{GROUP BY TRUE}} query works in Postgres, and MySQL but fails in Redshift with the following exception:
> {noformat}
> com.amazon.redshift.util.RedshiftException: ERROR: non-integer constant in GROUP BY
> {noformat}
> The {{GROUP BY 'a'}} query works in MySQL but fails in Postgres with the following exception:
> {noformat}
> ERROR: non-integer constant in GROUP BY
> {noformat}
> +Edit:+
> The {{GROUP BY}} constant is similar to {{GROUP BY ()}} "nothing" but as shown in the discussion below they are not equivalent. There is a nice [blog post|https://blog.jooq.org/2018/05/25/how-to-group-by-nothing-in-sql/] listing some limitations of various DBMS when it comes to {{GROUP BY ()}}.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)