Expand description
Validate a UnitTest and lower it into SQL Materialize can execute.
The lowered form is a sequence of CREATE TEMPORARY VIEW statements
(mocks, expected, target) followed by an assertion query whose rows
describe mismatches. An empty result means the test passed.
EXECUTE UNIT TEST test_name
FOR database.schema.view_name
[AT TIME 'timestamp'] -- optional, sets mz_now() during test
MOCK database.schema.mock1(col1 TYPE1, col2 TYPE2) AS (
SELECT * FROM VALUES (...)
),
MOCK database.schema.mock2(col TYPE) AS (
SELECT * FROM VALUES (...)
)
EXPECTED(col1 TYPE1, col2 TYPE2) AS (
SELECT * FROM VALUES (...)
);Structs§
- Expected
Schema Mismatch Error - Error: Expected output columns don’t match the target view schema.
- Invalid
AtTime Error - Error: The AT TIME value is not a valid timestamp.
- Mock
Schema Mismatch Error - Error: A mock’s columns don’t match the actual schema.
- Unmocked
Dependency Error - Error: A dependency of the target view is not mocked.
Enums§
- Test
Validation Error - Errors that can occur during unit test validation.
Functions§
- compare_
columns 🔒 - Compare test columns against actual schema columns.
- create_
expected_ 🔒view_ sql - create_
mock_ 🔒view_ sql - create_
target_ 🔒view_ sql - Create SQL for the target view as a temporary view with flattened naming.
- create_
test_ 🔒query_ sql - Create the test assertion query that returns failures.
- flatten_
fqn 🔒 - Quote a fully qualified name as a single identifier with dots.
- lower_
unit_ 🔒test - Lower a unit test into executable SQL statements.
- normalize_
fqn 🔒 - Normalize a potentially partial FQN to a fully qualified
ObjectIdusing the target’s context. - normalize_
type 🔒 - Normalize a SQL type for comparison.
- qualify_
mock_ 🔒name - Qualify a mock name with the target’s FQN context if it’s not already qualified.
- types_
match_ 🔒with_ bare_ containers - Check if two normalized types match when accounting for bare container types.
- validate_
unit_ 🔒test - Validate a unit test against the known types.