Skip to content

sql: parse EXECUTE UNIT TEST#36410

Merged
sjwiesman merged 3 commits into
MaterializeInc:mainfrom
sjwiesman:parser-execute-unit-test
May 11, 2026
Merged

sql: parse EXECUTE UNIT TEST#36410
sjwiesman merged 3 commits into
MaterializeInc:mainfrom
sjwiesman:parser-execute-unit-test

Conversation

@sjwiesman
Copy link
Copy Markdown
Contributor

@sjwiesman sjwiesman commented May 5, 2026

Summary

Adds parser support for EXECUTE UNIT TEST, a SQL-level construct for
declarative unit testing of views and materialized views. The plan side returns
unsupported.

Syntax

 EXECUTE UNIT TEST <test_name>
      FOR <target_name>
      [AT TIME <expr>]
      [MOCK <mock_name> ( <col_def> [, ...] ) AS ( <query> ) ,]...
      EXPECTED ( <col_def> [, ...] ) AS ( <query> )
  • <test_name> — identifier, reported in test output.
  • FOR <view> — fully-qualified name of the view or materialized view
    under test.
  • AT TIME <expr> (optional) — time at which to evaluate the view, for
    testing temporal logic.
  • MOCK <input_view> (cols) AS <query> (zero or more) — substitutes
    <input_view> with the rows produced by <query> for the duration of
    this test. Column list defines the schema the test expects from the
    mocked input.
  • EXPECTED (cols) AS <query> (required, exactly one) — the rows the
    view under test must produce.

Example

  EXECUTE UNIT TEST t FOR v
      MOCK a(x int) AS (SELECT 1),
      MOCK b(y int) AS (SELECT 2)
      EXPECTED (z int) AS (SELECT 3);

Scope

  • New keywords: UNIT, TEST, MOCK, EXPECTED (src/sql-lexer).
  • New AST nodes: ExecuteUnitTestStatement, MockViewDef,
    ExpectedResultDef (src/sql-parser/ast/defs/statement.rs).
  • Parser entry from EXECUTE UNIT TEST ... (src/sql-parser/parser.rs).
  • Plan side returns unsupported — execution is intentionally out of
    scope for this PR.

🤖 Generated with Claude Code

@sjwiesman sjwiesman requested a review from a team as a code owner May 5, 2026 20:17
@sjwiesman sjwiesman requested a review from ggevay May 5, 2026 20:17
@sjwiesman
Copy link
Copy Markdown
Contributor Author

Purposefully left this undocumented because you can't actually run it.

Copy link
Copy Markdown
Contributor

@def- def- left a comment

Choose a reason for hiding this comment

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

MOCK and EXPECTED need to be added in is_reserved_in_column_alias or is_reserved_in_table_alias

Multiple MOCK ..., MOCK... don't parse:

ERR: Expected left parenthesis, found MOCK

f.write_str(" MOCK ");
f.write_node(mock);
}
f.write_str(" EXPECTED");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
f.write_str(" EXPECTED");
f.write_str(" EXPECTED ");

@sjwiesman
Copy link
Copy Markdown
Contributor Author

Thanks for the review. I realized the grammar was not as restrictive as I intended. Made a slightly different change but should still handle your case.

Copy link
Copy Markdown
Contributor

@ggevay ggevay left a comment

Choose a reason for hiding this comment

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

Requiring the parens was a good idea to avoid adding stuff to is_reserved_in_column_alias/is_reserved_in_table_alias!

Looks good to me now, only some minor things:

  • Might be a bit surprising that a comma is needed even after the final MOCK, i.e., before the EXPECTED.
  • You could add a few more tests. (also negative ones)

@sjwiesman
Copy link
Copy Markdown
Contributor Author

Happy to make both updates before merging!

@ggevay
Copy link
Copy Markdown
Contributor

ggevay commented May 7, 2026

Thanks, looks great to me!

@def-, it seems my approval is not overriding your "Changes requested" review, so I think you need to drop it (if you agree with the fix).

Copy link
Copy Markdown
Contributor

@def- def- left a comment

Choose a reason for hiding this comment

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

The PR author can dismiss a review with a reason I think.

@sjwiesman
Copy link
Copy Markdown
Contributor Author

@def- TIL!

@sjwiesman sjwiesman merged commit dcf6105 into MaterializeInc:main May 11, 2026
119 checks passed
@sjwiesman sjwiesman deleted the parser-execute-unit-test branch May 11, 2026 14:27
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.

3 participants