Skip to content

fix: walk the BY SIMILARITY expression of DuckDB joins - #2964

Open
tanjiroK-coder wants to merge 1 commit into
JSQLParser:masterfrom
tanjiroK-coder:join-similarity-traversal
Open

tanjiroK-coder wants to merge 1 commit into
JSQLParser:masterfrom
tanjiroK-coder:join-similarity-traversal

Conversation

@tanjiroK-coder

Copy link
Copy Markdown
Contributor

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.

This branch has not been deployed

No deployments
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