feat(trino): parse WHILE/DO/END WHILE routine statements [CLAUDE] - #8122
Merged
Conversation
Reuses the existing exp.WhileBlock (already used by T-SQL's WHILE...BEGIN)
rather than inventing a new statement type, extending it with an optional
`label` arg for Trino's `label: WHILE ... END WHILE` naming syntax (which
LEAVE/ITERATE will target in a later phase). Parses the body through the
same _parse_routine_statements("END") helper used by BEGIN/IF/CASE, since
T-SQL's own _parse_whileblock()/_parse_block() can't be reused directly -
Trino's routine bodies need the chunk-continuation-aware statement list,
not the base parser's block parsing.
Confirmed against a real Trino instance: labeled and unlabeled forms,
nesting, combination with IF/CASE, and that a label repeated after END
WHILE is rejected (matching the docs, which only show it once, before
WHILE).
9 tasks
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.
We're almost to the end of the tunnel! Thanks for the reviews/merges thus far.
This is PR 6 of ~7, continuing #7934/#7981/#8004/#8044/#8068, building out Trino inline SQL UDF support (see the original roadmap in #7926, and apache/superset#26162).
This adds parsing/generation for Trino's
[label :] WHILE condition DO ... END WHILEroutine statement (https://trino.io/docs/current/udf/sql/while.html).Design
Reuses the existing
exp.WhileBlock(already used by T-SQL'sWHILE ... BEGIN ... END) rather than inventing a new statement type, extending it with an optionallabelarg for Trino'slabel: WHILE ... END WHILEnaming syntax - the label lets a laterLEAVE/ITERATEphase target a specific enclosing loop.The base parser's own
_parse_whileblock()/_parse_block()(used by T-SQL) can't be reused directly here, since Trino's routine bodies need the chunk-continuation-aware_parse_routine_statements("END")helper introduced back in #8044, not the base parser's block parsing. So_parse_routine_while()mirrors_parse_whileblock()'s shape (sameexp.WhileBlock(this, body)fields) rather than its implementation, the same way #8068's CASE mirrored_parse_case()'s shape without literally calling it.Verification
Confirmed against a real Trino instance: the docs' own example, the labeled form, nesting, combination with
IFandCASE, and that a label repeated afterEND WHILEis rejected (matching the docs, which only show the label once, beforeWHILE).WHILEas the literal last statement hits the same function-body completeness-check limitation noted on the IF/CASE phases (asserts round-trip grammar only, real Trino wants a literal trailingRETURN).Remaining phases
Related: apache/superset#26162
make unitandmake stylepass locally.Disclosure: Claude Code again, with me steering and doing the real-Trino verification myself. I'm a human, as far as I know, still... though I'm starting to believe I might be in the Matrix.