Skip to content

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

Open
vishalmore90 wants to merge 1 commit into
apache:masterfrom
vishalmore90:fix-issue-41052
Open

vishalmore90 wants to merge 1 commit 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).

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

1 participant