Add datasource quality and schema gates
This commit is contained in:
@@ -48,6 +48,7 @@ from govoplan_datasources.backend.payloads import (
|
||||
payload_for_materialization,
|
||||
validate_payload_size,
|
||||
)
|
||||
from govoplan_datasources.backend.quality import validate_stage
|
||||
from govoplan_datasources.backend.tabular import (
|
||||
MAX_READ_ROWS,
|
||||
MAX_STAGE_ROWS,
|
||||
@@ -427,6 +428,12 @@ class SqlDatasourceProvider:
|
||||
rows = normalize_rows(stage.rows)
|
||||
schema = infer_schema(rows)
|
||||
fingerprint = fingerprint_rows(rows, schema)
|
||||
validation = validate_stage(
|
||||
rows=rows,
|
||||
schema=schema,
|
||||
quality_policy=governance.quality_policy,
|
||||
baseline_schema=_fields(target.schema_) if target is not None else None,
|
||||
)
|
||||
item = DatasourceStageRecord(
|
||||
tenant_id=api_principal.tenant_id,
|
||||
target_datasource_id=target.id if target else None,
|
||||
@@ -436,7 +443,7 @@ class SqlDatasourceProvider:
|
||||
kind=stage.kind,
|
||||
mode=stage.mode,
|
||||
shape=stage.shape,
|
||||
state="ready",
|
||||
state="ready" if validation["valid"] else "invalid",
|
||||
provider=_clean_optional(stage.provider),
|
||||
provider_ref=_clean_optional(stage.provider_ref),
|
||||
schema_=[field_payload(field) for field in schema],
|
||||
@@ -444,7 +451,7 @@ class SqlDatasourceProvider:
|
||||
fingerprint=fingerprint,
|
||||
row_count=len(rows),
|
||||
byte_count=encoded_size(rows),
|
||||
validation_={"valid": True, "errors": [], "warnings": []},
|
||||
validation_=validation,
|
||||
provenance_=dict(stage.provenance),
|
||||
metadata_=dict(stage.metadata),
|
||||
governance_=governance.to_dict(),
|
||||
@@ -469,6 +476,10 @@ class SqlDatasourceProvider:
|
||||
tenant_id=api_principal.tenant_id,
|
||||
stage_ref=stage_ref,
|
||||
)
|
||||
if stage.validation_.get("valid") is not True:
|
||||
raise DatasourceValidationError(
|
||||
"The stage has blocking quality or schema diagnostics and cannot be promoted."
|
||||
)
|
||||
if stage.state != "ready":
|
||||
raise DatasourceValidationError("Only ready stages can be promoted.")
|
||||
datasource = (
|
||||
@@ -538,6 +549,7 @@ class SqlDatasourceProvider:
|
||||
provenance={
|
||||
**dict(stage.provenance_),
|
||||
"stage_ref": _stage_ref(stage.id),
|
||||
"stage_validation": dict(stage.validation_),
|
||||
},
|
||||
metadata=dict(stage.metadata_),
|
||||
set_current=True,
|
||||
|
||||
Reference in New Issue
Block a user