Repository navigation
feat(oracle): parse WITH FUNCTION PL/SQL declarations [CLAUDE] - #8673
Closed
ebarkhordar wants to merge 1 commit into
Closed
ebarkhordar wants to merge 1 commit into
ebarkhordar wants to merge 1 commit into
Conversation
Collaborator
|
I don't think this is the right approach. We already parse Trino inline UDFs, including their actual definition; we shouldn't store the function logic as plain-text. Also, this PR is doing a lot. We should split it into minimal PRs adding incremental support for this Oracle syntax. |
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.
Fixes #7663
Oracle allows PL/SQL function declarations at the start of a query's
WITHclause. Each one ends with its ownEND;, and any CTEs follow without a comma. The Oracle parser had no path for this, so the issue's query failed withExpecting (.This is Oracle-only, as suggested in the issue:
OracleParser._parse_withpicks upFUNCTION <name>entries before handing the rest to the base parser, so Trino'sWITH FUNCTIONpath is untouched. The signature (parameters,RETURNtype) is parsed into aFunctionSpecification, the same node Trino produces. The body afterIS/ASis kept verbatim as aVar, since there is no PL/SQL statement grammar to parse it with.The body's own semicolons split it across statement chunks, so the parser steps through the chunks to find the
ENDthat closes the function.BEGINandCASEopen a level, andEND IF/END LOOPare skipped. A nested function in the declaration section has its own body and is handled recursively. The existing block parser used byCREATE PROCEDUREdoesn't fit here, because it consumes every remaining statement and wouldn't stop before theSELECT.The generator writes the declarations back in Oracle form, and a body that is not PL/SQL (e.g. one parsed from Trino) is still reported as unsupported when generating Oracle. Function headings with options such as
DETERMINISTICorPIPELINED, andWITH PROCEDURE, are not handled yet and still fail to parse.Tests in
test_oracle.pycover the issue's query, several functions plus a CTE,AS, nested blocks and loops, a nested subprogram, a following statement, and the error cases. The unit suite passes on 3.9, 3.12 and 3.14, as do the mypyc build on 3.14, ruff and mypy. I used Claude to help write this, and I have not run these queries against a real Oracle instance.