Skip to content

Only apply non-left-associative nesting to deferred join constraints - #2445

Open
revitalkr wants to merge 3 commits into
apache:mainfrom
SatoriCyber:fix/non-left-assoc-join-chain-parsing
Open

Only apply non-left-associative nesting to deferred join constraints#2445
revitalkr wants to merge 3 commits into
apache:mainfrom
SatoriCyber:fix/non-left-assoc-join-chain-parsing

Conversation

@revitalkr

Copy link
Copy Markdown
Contributor

Summary

For dialects with supports_left_associative_joins_without_parens = false, nested joins are currently created even when no deferred join constraint exists.

Problem

The non-left-associative join handling was introduced to support deferred join constraints such as:
A JOIN B JOIN C ON X ON Y
However, the same logic is also applied to queries such as:
A JOIN B LEFT JOIN C ON X
even though there is no deferred ON or USING constraint to attach.
This produces a nested join structure where a flat join chain is expected.

Solution

Only apply the nesting logic when a deferred join constraint (ON or USING) remains to be attached.
Queries without deferred constraints continue to use the normal flat join structure.

Test

Adds coverage for:
SELECT 'ORIGINAL' AS src,
o.order_id,
c.customer_id,
p.product_id
FROM orders AS o
JOIN customers AS c
LEFT JOIN products AS p
ON p.order_id = o.order_id
and verifies that both Generic and Snowflake dialects produce a flat join chain (joins.len() == 2).

Validation - Snowflake script

The following query executes successfully in Snowflake:

SELECT 'ORIGINAL' AS src,
o.order_id,
c.customer_id,
p.product_id
FROM orders AS o
JOIN customers AS c
LEFT JOIN products AS p
ON p.order_id = o.order_id;
and matches the flat interpretation:
(orders AS o JOIN customers AS c)
LEFT JOIN products AS p
ON p.order_id = o.order_id

while the nested interpretation generated by the current non-left-associative handling:
orders AS o
JOIN (
customers AS c
LEFT JOIN products AS p
ON p.order_id = o.order_id
)
is rejected by Snowflake.

@revitalkr
revitalkr force-pushed the fix/non-left-assoc-join-chain-parsing branch from bf6c5e8 to 99aaa65 Compare August 20, 2026 14:23
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.

1 participant