Repository navigation
fix: check functions in PIVOT clauses of FROM items - #2945
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.
FromItemVisitorAdapternever walks thePIVOT/UNPIVOTclause the grammar attaches to a FROM item:visit(Table)returns immediately, and the derived table,LATERAL, table function, parenthesized join andVALUESvisits ignoregetPivot()/getUnPivot(), so onlyMATCH_RECOGNIZEwalked its pivot (SelectVisitorAdapterchecksPlainSelect.getPivot(), which the parser does not set for this syntax).StatementFeatureVisitoris built on that adapter, so the aggregate calls of an OraclePIVOTnever reach the pure-function check:SELECT * FROM t PIVOT (sum(purge_audit()) FOR a IN (1)), the same clause on a derived or joined table, and aPIVOT XMLIN subquery that calls a function come back withmayModifyData() == falseand no unresolved reference and pass the read-only guard in usage.rst, whileSELECT purge_audit() FROM tleavesMODIFIES_DATApossible withunresolved=[purge_audit]. Oracle takes any expression as the aggregate argument, and a user-defined aggregate in that position was not reported either. Validation had the matching gap:SelectValidator.visit(Pivot)only validated the FOR columns whilevisit(PivotXml)also validated the aggregate calls, so withFeature.pivotallowed andFeature.functionremoved,SELECT * FROM t PIVOT (max(upper(a)) FOR b IN (1))validated with no errors and thePIVOT XMLform did not. I found it while comparing the FROM-item clausesTablesNamesFinderwalks with the ones the adapter walks. The adapter now walks the pivot of every FROM item through thePivotVisitorAdapterit already used forMATCH_RECOGNIZE, andvisit(Pivot)validates the aggregate calls asvisit(PivotXml)does; the IN values are left out there, since SQL Server writes them as bracketed identifiers that are not columns. Four newfunctionIsCheckedcases and onetestValidateFunctionOutsideWherecase fail before (5 failures) and pass after; spotless, Checkstyle, PMD and SpotBugs pass, and the rest of./gradlew testis unchanged (the only local failures are 33 Mockito inline-mock-maker init errors and 2 temp-dir access errors, which fail the same way on master on this Windows machine).