Skip to content

[SPARK-59627][SQL] Report INCOMPATIBLE_JOIN_TYPES for unsupported join types for ASOF JOIN - #58997

Draft
LukaZdravic wants to merge 3 commits into
apache:masterfrom
LukaZdravic:asof-incompatible-join-types
Draft

LukaZdravic wants to merge 3 commits into
apache:masterfrom
LukaZdravic:asof-incompatible-join-types

Conversation

@LukaZdravic

@LukaZdravic LukaZdravic commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

ASOF JOIN supports only INNER and LEFT [OUTER]. Other join types (RIGHT, FULL, CROSS, SEMI, ANTI), NATURAL, and LATERAL failed with a generic syntax error.

Now the grammar accepts them, and AstBuilder rejects them with INCOMPATIBLE_JOIN_TYPES, as it already does for NATURAL CROSS JOIN. No new error condition is added.

The grammar puts ASOF at the end of the join type. This keeps the "missing 'JOIN'" hint for typos in ordinary joins, such as SELECT * FROM a RIGHT b. The two extra forms this accepts (ASOF without
MATCH_CONDITION, and MATCH_CONDITION without ASOF) are still syntax errors.

Why are the changes needed?

The old error did not say which join type is wrong.

Does this PR introduce any user-facing change?

Yes, only in error messages of the ASOF JOIN:

SELECT * FROM l RIGHT ASOF JOIN r MATCH_CONDITION (l.ts >= r.ts);
-- Before: [PARSE_SYNTAX_ERROR] Syntax error at or near 'ASOF': extra input 'ASOF'.
-- After: [INCOMPATIBLE_JOIN_TYPES] The join types ASOF and RIGHT OUTER are incompatible.

Also, lateral after ASOF JOIN is now read as the keyword, as in ordinary joins.

How was this patch tested?

New PlanParserSuite tests for each rejected form, for the "missing 'JOIN'" hint on every join type, and for asof as a table alias. Two new cases in the join-asof-grammar.sql golden file.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code

…n types before ASOF JOIN

ASOF JOIN supports only INNER and LEFT OUTER. Other join types before ASOF (RIGHT, FULL, CROSS, LEFT SEMI, NATURAL) failed with a generic PARSE_SYNTAX_ERROR that did not name the bad type.

The grammar now accepts any join type and a leading NATURAL before ASOF JOIN, and AstBuilder rejects the unsupported ones with INCOMPATIBLE_JOIN_TYPES, which names the pair. This mirrors how NATURAL CROSS JOIN is handled.
Copilot AI lite review requested due to automatic review settings September 23, 2026 14:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

LukaZdravic and others added 2 commits September 23, 2026 16:53
- Test every join type ASOF rejects: RIGHT [OUTER], FULL [OUTER], CROSS,
  [LEFT] SEMI, [LEFT] ANTI, NATURAL and NATURAL LEFT, plus the pipe syntax
  path and RIGHT ASOF JOIN with ASOF disabled.
- Take the expected error positions from the SQL text, not hand counts.
- Use the Seq(...).contains check shape that NEAREST BY and LATERAL use.
- Remove the unused AsOfJoinType.supportedDisplay.
- Name the error in the ASOF JOIN reference page.

Co-authored-by: Isaac <no-reply@databricks.com>
…TERAL

Put ASOF at the end of the join type in the grammar, so a typo such as
`a RIGHT b` keeps the "missing 'JOIN'" hint. AstBuilder now finds ASOF by
its keyword and rejects the forms the grammar newly accepts: ASOF without
MATCH_CONDITION and MATCH_CONDITION without ASOF (syntax errors, as before)
and ASOF with LATERAL (INCOMPATIBLE_JOIN_TYPES).

Co-authored-by: Isaac <no-reply@databricks.com>
@LukaZdravic
LukaZdravic marked this pull request as draft September 24, 2026 09:04

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants