Skip to content

feat(trino): parse WHILE/DO/END WHILE routine statements [CLAUDE] - #8122

Merged
georgesittas merged 1 commit into
tobymao:mainfrom
rusackas:trino-udf-6-while
Aug 11, 2026
Merged

feat(trino): parse WHILE/DO/END WHILE routine statements [CLAUDE]#8122
georgesittas merged 1 commit into
tobymao:mainfrom
rusackas:trino-udf-6-while

Conversation

@rusackas

@rusackas rusackas commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

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 WHILE routine statement (https://trino.io/docs/current/udf/sql/while.html).

Design

Reuses the existing exp.WhileBlock (already used by T-SQL's WHILE ... BEGIN ... END) rather than inventing a new statement type, extending it with an optional label arg for Trino's label: WHILE ... END WHILE naming syntax - the label lets a later LEAVE/ITERATE phase 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 (same exp.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 IF and CASE, and that a label repeated after END WHILE is rejected (matching the docs, which only show the label once, before WHILE). WHILE as 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 trailing RETURN).

Remaining phases

  • LOOP/REPEAT/ITERATE/LEAVE

Related: apache/superset#26162

make unit and make style pass 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.

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).

@georgesittas georgesittas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, thank you.

@georgesittas
georgesittas merged commit 31f3751 into tobymao:main Aug 11, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants