Repository navigation
fix: inspect every table function in feature analysis and validation - #2760
Open
AndreasLanz01 wants to merge 2 commits into
Open
AndreasLanz01 wants to merge 2 commits into
AndreasLanz01 wants to merge 2 commits into
Conversation
StatementFeatureVisitor only checked TableFunction#getFunction(), which is null for ROWS FROM (...), so every function listed there escaped the purity check. Iterate TableFunction#getFunctions() instead.
SelectValidator only checked that table functions are allowed and never validated the functions themselves, so features, names and nested queries in their arguments went unchecked. This covers both f(..) and every function of ROWS FROM (..).
AndreasLanz01
force-pushed
the
fix/feature-rows-from-functions
branch
from
October 9, 2026 08:31
74ca3db to
a834064
Compare
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.
What
Two visitors looked at only part of a
TableFunction:StatementFeatureVisitornow checks every function ofROWS FROM (...)for purity. Before, it checked onlyTableFunction#getFunction(), which isnullforROWS FROM.SelectValidatornow validates the functions of a table function, forf(...)and for every function ofROWS FROM (...). Before, it validated onlyFeature.tableFunctionandPIVOT/UNPIVOT, so nothing in the arguments was validated.Both use the existing
TableFunction#getFunctions(), which returns theROWS FROMlist or the single function.Why
StatementFeatureVisitor.analyse(statement, name -> false), i.e. no function is declared pure:SELECT * FROM pg_ls_dir('.')MODIFIES_DATA,MODIFIES_SCHEMAuncertain;pg_ls_dirunresolvedSELECT * FROM ROWS FROM (pg_ls_dir('.'))A read-only guard that uses
mayModifyData()therefore accepted any function when it was wrapped inROWS FROM.SelectValidatorwithFeaturesAllowed.SELECTplusFeature.tableFunction:SELECT * FROM t WHERE a = f(?)reportsjdbcParameter not allowed., butSELECT * FROM f(?)andSELECT * FROM ROWS FROM (f(1), g(?))reported no error.Testing
StatementFeatureVisitorTest: new nested class with 4 tests:ROWS FROMwith one function;ROWS FROMwith two functions; marking only the first one pure leaves the second one unresolved;ROWS FROM ... WITH ORDINALITY AS r(n, name, ord).On base
26d3e02athe 3ROWS FROMtests fail and the control passes.SelectValidatorTest: aWHEREcontrol and a parameterized test with 3 cases (f(?),ROWS FROM,ROWS FROM ... WITH ORDINALITY). On base26d3e02athe 3 cases fail withExpected 1 errors, but got: []and the control passes../gradlew checkon Windows 11 with the JDK 17 toolchain passes: 9,550 test cases, 0 failures, 0 errors, 25 skipped. Grammar ambiguity, Spotless, Checkstyle, PMD, SpotBugs and JaCoCo verification pass.All SQL in the new tests executes on PostgreSQL 18.4 (
?sent as$1withPREPARE/EXECUTE; helper tabletand functionsf,gcreated first).Not run:
mvn verify, JMH (no grammar or parser change), Linux/macOS.Also observed, but not changed
SelectValidatordoes not validate select items at all (call commented out with a@todoatSelectValidator.java:152-155). That is why the validator control usesWHERE.FromItemVisitorAdapter.visit(TableFunction)is empty, so the generic adapter does not descend into table function arguments, forf(...)orROWS FROM. Changing it would change behaviour for every adapter user.Origin
First observed with
com.manticore-projects.jsqlformatter:jsqlparser:5.4.104andDialect.POSTGRESQL. Reproduced on upstream master26d3e02a78e061f5fecf2eb2e783bf0482e10840with the default parser.AI disclosure: this change was prepared with an AI coding agent (Claude Code) and reviewed by me.