Marko Radoicic created SPARK-60239:
--------------------------------------
Summary: Reject aliased GROUP BY ordinals in pipe AGGREGATE
Key: SPARK-60239
URL: https://issues.apache.org/jira/browse/SPARK-60239
Project: Spark
Issue Type: Bug
Components: SQL
Affects Versions: 5.0.0
Reporter: Marko Radoicic
Pipe AGGREGATE accepts aliases on grouping expressions, but an alias on an
integer literal silently changes what the literal means. A bare integer is an
ordinal, while an aliased integer is a constant grouping key:
{code:sql}
-- Groups by the second aggregate-list position (ordinal).
TABLE t |> AGGREGATE sum(x) AS s GROUP BY 2
-- Groups by the constant 2 and outputs a column grp = 2.
TABLE t |> AGGREGATE sum(x) AS s GROUP BY 2 AS grp
{code}
The second query is ambiguous: users who write it most likely mean the ordinal.
Regular GROUP BY does not allow aliases at all and rejects the same text:
{code:sql}
SELECT x, sum(x) FROM t GROUP BY 2 AS grp
-- [PARSE_SYNTAX_ERROR] Syntax error at or near 'grp': extra input 'grp'.
SQLSTATE: 42601
{code}
Pipe AGGREGATE should raise the same error for aliased integer literals (with
or without AS, including parenthesized and negative literals), while keeping
bare ordinals and aliases on non-ordinal expressions working.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]