Tisya Bhatia created CALCITE-7676:
-------------------------------------
Summary: GROUP BY ALL / ORDER BY ALL should exclude constant
literals from the implicit keys
Key: CALCITE-7676
URL: https://issues.apache.org/jira/browse/CALCITE-7676
Project: Calcite
Issue Type: Improvement
Reporter: Tisya Bhatia
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.
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)