Skip to content

[YAML] Fix SQL-backed Join generating invalid syntax when joining 3+ inputs - #41068

Merged
derrickaw merged 3 commits into
apache:masterfrom
vishalmore90:fix-issue-41052
Nov 12, 2026
Merged

derrickaw merged 3 commits into
apache:masterfrom
vishalmore90:fix-issue-41052

Conversation

@vishalmore90

Copy link
Copy Markdown
Contributor

Fixes #41052.

Description

In Beam YAML, _SqlJoinTransform generated invalid SQL queries when joining three or more inputs in topologies or dictionary key orderings that did not match a star topology centered at tables[0]. This caused two failure modes:

  1. Tables joining downstream tables were left without an ON clause (INNER JOIN tableB INNER JOIN tableC ON ...), leading to Calcite SqlParseException.
  2. Tables were referenced in preceding ON clauses before being joined into the query scope.
  3. In _parse_fields, specifying '*' as explicitly documented in _SqlJoinTransform raised a ValueError.

This PR:

  • Replaces the linear table iteration with an adjacency graph traversal (BFS) starting at tables[0]. Each newly joined table is connected to already visited tables with all connecting predicates placed into its ON clause, guaranteeing valid SQL scoping and syntax.
  • Supports cols == '*' in _parse_fields.
  • Adds unit tests in yaml_join_test.py covering multi-table arbitrary order joins, cycle/triangle joins, and wildcard field parsing.
  • Updates CHANGES.md.

@github-actions github-actions Bot added python yaml size/m M: 50-249 lines changed labels Nov 7, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📋 Review Summary

This PR resolves #41052 by constructing an adjacency graph from the parsed join equalities and traversing connected tables from tables[0] rather than iterating blindly in input dictionary order. This guarantees every JOIN clause has a valid ON condition and only references tables already introduced in the FROM/JOIN sequence. It also fixes multi-table outer join propagation across visited tables and adds '*' wildcard support in _parse_fields.

🔍 General Feedback

  • The graph traversal and composite ON clause construction cleanly handle arbitrary input orderings, multi-hop chains, and cyclic/triangle join predicates.
  • Adding SqlJoinQueryTest to validate the generated SQL strings directly without requiring an external runner/expansion service provides good precommit test coverage.

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @derrickaw for label yaml.
Backup reviewer: chamikaramj (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@derrickaw

Copy link
Copy Markdown
Collaborator

Hi @vishalmore90, can you address the check failures? Thanks

@vishalmore90

Copy link
Copy Markdown
Contributor Author

@derrickaw Please take a look whenever you get chance

@codecov

codecov Bot commented Nov 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.15%. Comparing base (0fa1aca) to head (ef7401f).
⚠️ Report is 43 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #41068      +/-   ##
============================================
+ Coverage     59.13%   59.15%   +0.02%     
  Complexity     4894     4894              
============================================
  Files          1468     1461       -7     
  Lines        186188   186055     -133     
  Branches       3645     3645              
============================================
- Hits         110096   110064      -32     
+ Misses        72743    72642     -101     
  Partials       3349     3349              
Flag Coverage Δ
python 80.56% <100.00%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@derrickaw
derrickaw merged commit b8329d6 into apache:master Nov 12, 2026
87 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Beam YAML Join generates invalid SQL syntax (missing ON clause or forward-referenced tables) when joining 3+ inputs

2 participants