Skip to content

build_schema_drift_records

Public callable

Convert schema drift results into metadata records for audit trails.

Parameters:

Name Type Description Default
drift_result Any

Value used by this callable.

required

Returns:

Type Description
list[dict]

Structured output produced by this callable.

Source code in src/fabricops_kit/metadata.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
def build_schema_drift_records(drift_result: dict, *, run_id: str, table_stage: str) -> list[dict]:
    """Convert schema drift results into metadata records for audit trails.

        Parameters
        ----------
        drift_result : Any
            Value used by this callable.

        Returns
        -------
        list[dict]
            Structured output produced by this callable.
    """
    base = {
        "run_id": run_id,
        "dataset_name": drift_result.get("dataset_name"),
        "table_name": drift_result.get("table_name"),
        "table_stage": table_stage,
        "baseline_engine": drift_result.get("baseline_engine"),
        "current_engine": drift_result.get("current_engine"),
        "status": drift_result.get("status"),
        "can_continue": drift_result.get("can_continue"),
    }
    changes = drift_result.get("changes", [])
    if not changes:
        return [
            to_jsonable(
                {
                    **base,
                    "drift_type": "none",
                    "column_name": None,
                    "previous_value": None,
                    "current_value": None,
                    "severity": "info",
                    "action": "allow",
                    "message": "No schema drift detected.",
                }
            )
        ]

    return [
        to_jsonable(
            {
                **base,
                "drift_type": change.get("drift_type"),
                "column_name": change.get("column_name"),
                "previous_value": change.get("previous_value"),
                "current_value": change.get("current_value"),
                "severity": change.get("severity"),
                "action": change.get("action"),
                "message": change.get("message"),
            }
        )
        for change in changes
    ]