vranes opened a new pull request, #60620:
URL: https://github.com/apache/spark/pull/60620
### What changes were proposed in this pull request?
This PR changes the optional table alias after a BIN BY clause from
`errorCapturingIdentifier` to `strictIdentifier`. This is the same identifier
rule that `tableAlias` and the GAP FILL alias use.
### Why are the changes needed?
In the default keyword mode
(`spark.sql.ansi.enforceReservedKeywords=false`), `errorCapturingIdentifier`
accepts the strict-non-reserved keywords, such as LEFT, RIGHT, FULL, NATURAL,
INNER, CROSS, and SEMI. The parser takes a join keyword after the BIN BY clause
as the table alias, and the join loses its type:
```sql
SELECT * FROM t
BIN BY (RANGE s TO e BIN WIDTH INTERVAL 1 HOUR DISTRIBUTE UNIFORM (v))
LEFT JOIN u ON t.k = u.k
```
Before this PR, the parsed plan is an inner join with a `SubqueryAlias LEFT`
over the BIN BY:
```
'Project [*]
+- 'Join Inner, ('t.k = 'u.k)
:- 'SubqueryAlias LEFT
: +- 'UnresolvedBinBy ...
+- 'UnresolvedRelation [u], [], false
```
After this PR, the plan is a `Join LeftOuter` with no alias. When reserved
keywords are enforced, the join keywords are reserved, so the result was
already correct in that mode.
### Does this PR introduce _any_ user-facing change?
Yes, in the default keyword mode:
- A join keyword after a BIN BY clause now starts the join with the correct
join type. Before, the keyword became the table alias, and the query ran with a
different join type (for example, an inner join instead of a LEFT join).
- An unquoted strict-non-reserved keyword is no longer accepted as a BIN BY
table alias (for example, `... ) AS left`). A quoted alias (``... ) AS `left`
``) still works. This is the same rule as for other table aliases.
BIN BY is available since Spark 4.3.0.
### How was this patch tested?
A new test in `PlanParserSuite` parses BIN BY followed by LEFT, RIGHT, FULL,
INNER, LEFT SEMI, LEFT ANTI, CROSS, NATURAL, and NATURAL LEFT joins. It checks
the join type and that no alias wraps the BIN BY. It also checks that an alias
before the join keyword and a quoted keyword alias still work. The test runs
with reserved keywords enforced and not enforced.
```
build/sbt 'catalyst/testOnly
org.apache.spark.sql.catalyst.parser.PlanParserSuite'
```
The bug is in 4.3.0. Please consider merging this PR to `master` and
`branch-4.x`, and backporting it to `branch-4.4` and `branch-4.3`.
### 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]