marko-radoicic-db opened a new pull request, #59923:
URL: https://github.com/apache/spark/pull/59923
### What changes were proposed in this pull request?
Follow-up to SPARK-60239. Pipe `AGGREGATE` now rejects an aliased
integer-literal GROUP BY ordinal, for example `TABLE t |> AGGREGATE sum(x) AS s
GROUP BY 2 AS grp`, with `PARSE_SYNTAX_ERROR` (SQLSTATE `42601`) instead of
`UNSUPPORTED_FEATURE.PIPE_OPERATOR_AGGREGATE_UNSUPPORTED_CASE` ("aliases on
GROUP BY ordinals").
The error parameters are built from the alias source text in `AstBuilder`,
the same way regular GROUP BY reports an alias in `withAggregationClause`
(`n.name.getText`), so quoted and `IDENTIFIER()` aliases are reported
identically in both paths. The condition is unchanged:
`spark.sql.groupByOrdinal` is true and
`spark.sql.legacy.allowAliasedPipeAggregateOrdinals` is false.
### Why are the changes needed?
Regular GROUP BY rejects every alias on a grouping expression with
`PARSE_SYNTAX_ERROR`. An ordinal cannot take an alias, so the pipe form is a
syntax error too. Reporting it the same way as regular GROUP BY, with the alias
text as the offending input, is more accurate and consistent than the
unsupported-feature error.
### Does this PR introduce _any_ user-facing change?
Yes, for queries that already fail. `TABLE t |> AGGREGATE sum(x) AS s GROUP
BY 2 AS grp` now fails with `PARSE_SYNTAX_ERROR` (SQLSTATE `42601`) and
parameters `error = 'grp'`, `hint = ": extra input 'grp'"`, instead of
`UNSUPPORTED_FEATURE.PIPE_OPERATOR_AGGREGATE_UNSUPPORTED_CASE`. This only
changes behavior introduced by SPARK-60239, which is unreleased (fix version
4.4.0). Bare ordinals and aliases on other grouping expressions are unchanged.
### How was this patch tested?
- `PlanParserSuite`: updated the SPARK-60239 test to the new error, and
added tests for aliased ordinals over different inputs and for quoted and
`IDENTIFIER()` aliases, asserting the same error text as regular GROUP BY.
- `pipe-operators.sql`: two new cases (``group by 2 as `grp 2` ``, `group by
2 as IDENTIFIER('grp')`); `results/` and `analyzer-results/` goldens
regenerated. Only the aliased-ordinal records change: 4 existing records change
error class, SQLSTATE and parameters, and 2 records are added.
These suites were run on the equivalent change in a downstream build of
Spark; the goldens come from that regeneration.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Isaac (Claude Opus 5.5)
This pull request and its description were written by Isaac.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]