Repository navigation
fix: traverse missing expression and query children in visitor adapters - #2761
Merged
manticore-projects merged 1 commit intoOct 9, 2026
Conversation
- Visit skipped children: named function parameters, TRIM FROM, ANY/ALL subquery, ESCAPE, AT TIME ZONE, JSON operators and aggregates, column array subscripts - Visit VALUES rows, LIMIT, LIMIT BY, CONNECT BY and set-operation WITH/ORDER BY/LIMIT/OFFSET/FETCH - StatementFeatureVisitor now checks functions, locks and writes there Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Thank you very much for improving this! |
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
ExpressionVisitorAdapterandSelectVisitorAdapterskipped some child expressions and sub-selects. Every visitor built on them, includingStatementFeatureVisitor, therefore never saw a function call or subquery in these positions:Columna[f()],t.a[1:f()]Functionsubstring(x FROM 2 FOR 3),position(x IN y),overlay(x PLACING y FROM 2); an attribute expressionTrimFunctionFROMexpression:trim(LEADING 'x' FROM f())AnyComparisonExpression= ANY (...),> ALL (...),= SOME (...)LikeExpressionESCAPEexpressionMemberOfExpressionTimezoneExpressiond AT TIME ZONE f()JsonExpression->,->>,#>,#>>JsonAggregateFunctionjson_objectagg(k : v), itsORDER BY,OVER (PARTITION BY .. ORDER BY ..)Values(select path)VALUES (...),IN (VALUES (...))PlainSelectLIMIT,LIMIT .. BY,START WITH .. CONNECT BYSetOperationListWITH,ORDER BY,LIMIT,OFFSET,FETCHParenthesedSelectOFFSET/FETCHgot anullcontext instead of the caller'sWhy
StatementFeatureVisitor.analyse(statement, pureFunctions)is meant for read-only guards: a function that is not proven pure leavesMODIFIES_DATA/MODIFIES_SCHEMApossible and is reported ingetUnresolvedReferences(). Withpg_read_filenot declared pure, each of these reported nothing before this change:The same gap hid row locks and data-modifying CTEs in these positions, e.g.
WHERE a = ANY (SELECT b FROM u FOR UPDATE)reported noMODIFIES_TRANSACTION, andVALUES ((WITH c AS (DELETE FROM u RETURNING b) SELECT b FROM c))reported noMODIFIES_DATA.The fix is in the adapters, not in
StatementFeatureVisitor, so every subclass of the adapters sees these children too.Testing
StatementFeatureVisitorTest: new nested classExpressionPositions:FOR UPDATEmust giveMODIFIES_TRANSACTION;MODIFIES_DATA;VALUES (1, 2)still reads nothing and returns rows.On base
26d3e02aall 36 parameterized cases fail and the control passes../gradlew checkon Windows 11 with the JDK 17 toolchain: 9,579 test cases, 0 failures, 0 errors, 25 skipped. Grammar ambiguity, Spotless, Checkstyle, PMD, SpotBugs and JaCoCo verification pass.Not run:
mvn verify, JMH (no grammar or parser change), Linux/macOS.Not changed
FromItemVisitorAdapter.visit(TableFunction)is still empty; table functions inFROMare handled in fix: inspect every table function in feature analysis and validation #2760.PlainSelectFOR UPDATE OF .. / WAIT ..and lateral views are still not visited (existing@todos).Origin
First observed with
com.manticore-projects.jsqlformatter:jsqlparser:5.4.104andDialect.POSTGRESQL. Reproduced on upstream master26d3e02a78e061f5fecf2eb2e783bf0482e10840with the default parser. No existing issue is linked.AI disclosure: this change was prepared with an AI coding agent (Claude Code) and reviewed by me.