Repository navigation
fix(lint): report a join condition that does not link the tables as GV003 (#156) - #164
Conversation
An ON condition now counts as a key join only when an equality compares columns of two different tables. ON 1=1, ON TRUE and ON t.id = t.id are reported as GV003 errors. A real key with extra conditions, unqualified columns, USING, NATURAL and CROSS joins behave as before. Closes laaielichter#156
|
Ran locally before opening: |
laaielichter
left a comment
There was a problem hiding this comment.
Approved on a055603. Thank you, @Ipsita-Mondal-30, this is a careful first PR. The _on_link helper is small and easy to read, and the "unqualified column means we cannot tell, so do not guess" rule is exactly the right call.
What I checked, on this head merged with current main (no conflicts with main):
ruff check .clean; fullpytest899 passed, 10 skipped.- Before (main):
ON 1=1andON t.id = t.idgive "No scale problems found", andgulliver run "select count(*) from events e join users u on 1=1"on the demo is OK. After: both are GV003 errors with a clear message, and the samerunis now BLOCKED. - Also GV003 errors:
ON TRUE,ON 'a' = 'a',ON x.id = x.idwith aliases, and a later join in a chain (... join v on v.k = v.k). - No new findings:
ON t.id = u.id AND 1=1,ON a.id = b.id, aliasedx.id = y.id,ON id = user_id,USING,ON lower(t.n) = lower(u.n), an equality against a subquery,ON 1=1inside a string or a comment, andON t.id = u.id OR 1=1(still the GV008 warning as before). - Mutation check: with
src/gulliver/lint.pyreverted to main, 7 of the new tests fail. - The diff is limited to
lint.py,tests/test_lint.pyandCHANGELOG.md.
Ready to merge from my side. It still needs the maintainer to approve the first-time CI runs (they show action_required for first-time contributors) and the 14 checks have to pass. I will add the "Thanks to @Ipsita-Mondal-30" credit to the CHANGELOG line, so you do not need to change it.
One heads-up, not a blocker: #165 also adds a line at the same spot in CHANGELOG.md, so whichever of the two lands second will need main merged and both lines kept.
Generated by Claude Code
|
Merged, and welcome to Gulliver, @Ipsita-Mondal-30! Thank you for this first contribution. Telling apart a join condition that really links two tables from If you want a next one: #159 (translate the README quick start into your language) is free and a good first issue. CONTRIBUTING.md has the setup and PR rules. Your #165 is next in the queue. If Gulliver is useful to you, a ⭐ helps other people find it. Generated by Claude Code |
Closes #156
An
ONcondition counted as a key join whenever it contained any=, soON 1=1andON t.id = t.idpassed lint and the gate stayed open on a full cartesian product.Change (
src/gulliver/lint.py)A new helper
_on_linkclassifies the condition:ON 1=1,ON TRUE,ON 'a'='a'): GV003 error.ON TRUEwas a GV008 warning before; it is the same cartesian product.ON t.id = t.id,ON u.x = u.y): GV003 error, with a message saying the condition does not link the two tables.ON id = user_id): no finding, because the side cannot be known.USING,NATURAL,UNNEST/LATERALandCROSS JOINare untouched.Not covered: a third table in a chain that is never linked (
a JOIN b ON ... JOIN c ON a.id = b.id); the issue says this can be left out.Tests (
tests/test_lint.py): parametrized cases for each bullet above, plus the finding message. CHANGELOG line added. The README rule table is unchanged because the GV003 description did not change.pytest(899 passed, 10 skipped) andruff check .pass.