Repository navigation
fix: walk the BY SIMILARITY expression of DuckDB joins - #2964
Open
tanjiroK-coder wants to merge 1 commit into
Open
tanjiroK-coder wants to merge 1 commit into
tanjiroK-coder wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The grammar lets a DuckDB similarity join carry a full expression after BY SIMILARITY, and the parser keeps it in Join.getSimilarity(). Only SelectDeParser ever reads that slot: FromItemVisitorAdapter.visitJoins, TablesNamesFinder.visitJoins and SelectValidator.validateOptionalJoin all walk the ON expressions and the USING columns and stop there. StatementFeatureVisitor builds on the adapter, so SELECT a FROM t JOIN u APPROX NEAREST 2 BY SIMILARITY pg_read_file('x') came back with mayModifyData() == false and no unresolved reference and passed the read-only guard in usage.rst, while the same call in ON leaves MODIFIES_DATA possible with unresolved=[pg_read_file]. findTables returned [t, u] for SELECT a FROM t JOIN u APPROX NEAREST 2 BY SIMILARITY (SELECT max(pw) FROM secrets), also inside a parenthesed FROM item and behind UPDATE ... FROM and DELETE ... USING, so a table allowlist never sees secrets, and with Feature.function removed the similarity call validated with no errors. I found it while checking which Join slots any visitor reads, and similarity is the only one that was missed, so all three visitors now walk it next to the ON expressions. New cases in StatementFeatureVisitorTest, TablesNamesFinderTest and SelectValidatorTest fail before (7 failures) and pass after; ./gradlew check (16821 tests) and mvn verify (16803 tests) pass.