Skip to main content

Module lower

Module lower 

Source
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§

ExpectedSchemaMismatchError
Error: Expected output columns don’t match the target view schema.
InvalidAtTimeError
Error: The AT TIME value is not a valid timestamp.
MockSchemaMismatchError
Error: A mock’s columns don’t match the actual schema.
UnmockedDependencyError
Error: A dependency of the target view is not mocked.

Enums§

TestValidationError
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 ObjectId using 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.