-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(pipeline): use pydantic validation
Currently validation differs between the pipeline and the api. The api relies on the schema validation, using pydantic. But the pipeline has its own sql-based validation. This can lead to inconsistencies between pipeline and api and duplicates code. This commit leverages plpython to reuse the schema validation in the pipeline. Validation is done at the source level. This commit also materializes validation errors in a dedicated model, rather than using dbt data tests, which are less convenient for products to use.
- Loading branch information
Showing
5 changed files
with
106 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
WITH services AS ( | ||
SELECT * FROM {{ ref('int__union_services') }} | ||
), | ||
|
||
structures AS ( | ||
SELECT * FROM {{ ref('int__union_structures') }} | ||
), | ||
|
||
services_errors AS ( | ||
SELECT | ||
services._di_surrogate_id AS "service_id", | ||
NULL AS "structure_id", | ||
errors.type AS "type", | ||
errors.loc AS "loc", | ||
errors.msg AS "msg", | ||
errors.input AS "input" | ||
FROM | ||
services, | ||
LATERAL (SELECT * FROM VALIDATE('service', TO_JSONB(services))) AS errors | ||
), | ||
|
||
structures_errors AS ( | ||
SELECT | ||
NULL AS "service_id", | ||
structures._di_surrogate_id AS "structure_id", | ||
errors.type AS "type", | ||
errors.loc AS "loc", | ||
errors.msg AS "msg", | ||
errors.input AS "input" | ||
FROM | ||
structures, | ||
LATERAL (SELECT * FROM VALIDATE('structure', TO_JSONB(structures))) AS errors | ||
), | ||
|
||
final AS ( | ||
SELECT * FROM services_errors | ||
UNION ALL | ||
SELECT * FROM structures_errors | ||
) | ||
|
||
SELECT * FROM final |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters