[ 
https://issues.apache.org/jira/browse/CALCITE-7675?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18099563#comment-18099563
 ] 

Mihai Budiu commented on CALCITE-7675:
--------------------------------------

Beware that in some conformance levels GROUP BY 1 means "by the first field"

> GROUP BY ALL / ORDER BY ALL should exclude constant literals from the 
> implicit keys
> -----------------------------------------------------------------------------------
>
>                 Key: CALCITE-7675
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7675
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Tisya Bhatia
>            Priority: Major
>
> Description:
> GROUP BY ALL (CALCITE-7594) and ORDER BY ALL (CALCITE-7597) expand into every
> non-aggregate SELECT expression during validation. The expansion currently 
> also
> adds constant literals to the implicit keys.
> Example:
> SELECT count(*), 42 AS c FROM emp GROUP BY ALL;   -- becomes GROUP BY 42
> SELECT sal, 42 AS c FROM emp ORDER BY ALL;        -- becomes ORDER BY 42
> Motivation: grouping or sorting by a constant is a no-op, and materializing it
> produces an ambiguous "GROUP BY 42" / "ORDER BY 42". On unparse round-trips
> (view / materialized-table expansion, SqlValidatorFixture#rewritesTo) it is
> re-parsed as an ordinal position under ordinal-style conformances (BABEL,
> BigQuery, LENIENT, MySQL, Presto) and fails as out of range, and is a constant
> key under DEFAULT -- a conformance-dependent, lossy round-trip. Reported by
> Sergey Nuyanzin on the Flink dev@ thread.
> Proposed behaviour:
> - rewriteGroupByAll / rewriteOrderByAll skip SELECT items that are a 
> SqlLiteral,
>   so a constant never becomes an implicit key. This is result-equivalent (one
>   group / no reordering either way).
> - Only bare literals are affected; compound constant expressions such as 1 + 1
>   are SqlCalls, are never treated as ordinals, and are intentionally left 
> alone.
> Scope:
> - Follow-up to CALCITE-7594 / CALCITE-7597; GROUP BY ALL and ORDER BY ALL 
> only.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to