sql: parse EXECUTE UNIT TEST#36410
Conversation
|
Purposefully left this undocumented because you can't actually run it. |
def-
left a comment
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
| f.write_str(" EXPECTED"); | |
| f.write_str(" EXPECTED "); |
|
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. |
There was a problem hiding this comment.
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 theEXPECTED. - You could add a few more tests. (also negative ones)
|
Happy to make both updates before merging! |
|
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). |
def-
left a comment
There was a problem hiding this comment.
The PR author can dismiss a review with a reason I think.
|
@def- TIL! |
Summary
Adds parser support for
EXECUTE UNIT TEST, a SQL-level construct fordeclarative unit testing of views and materialized views. The plan side returns
unsupported.Syntax
<test_name>— identifier, reported in test output.FOR <view>— fully-qualified name of the view or materialized viewunder test.
AT TIME <expr>(optional) — time at which to evaluate the view, fortesting temporal logic.
MOCK <input_view> (cols) AS <query>(zero or more) — substitutes<input_view>with the rows produced by<query>for the duration ofthis test. Column list defines the schema the test expects from the
mocked input.
EXPECTED (cols) AS <query>(required, exactly one) — the rows theview 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
UNIT,TEST,MOCK,EXPECTED(src/sql-lexer).ExecuteUnitTestStatement,MockViewDef,ExpectedResultDef(src/sql-parser/ast/defs/statement.rs).EXECUTE UNIT TEST ...(src/sql-parser/parser.rs).unsupported— execution is intentionally out ofscope for this PR.
🤖 Generated with Claude Code