A data partition turns out to be corrupted, and models built from it may already be serving. Given the lineage graph of datasets, feature tables and models, return every artifact that must be rebuilt, in an order that rebuilds parents before children, and the production models among them.
Implement lineage_impact(artifacts, edges, bad, production):
artifacts: a dict mapping each artifact name to its kind, "dataset", "features" or "model".edges: a list of (upstream, downstream) pairs meaning downstream was built from upstream. The graph has no cycles. A pair may appear more than once.bad: a list of artifact names found to be corrupted.production: a list of model names currently serving.An artifact is affected when it can be reached from any bad artifact by following one or more edges downstream. A bad artifact that is not itself downstream of another bad one is repaired at its source and is not in the result.
Return a dict with:
rebuild: every affected artifact, in rebuild order: at each step take the alphabetically smallest affected artifact none of whose affected parents is still waiting to be rebuilt. Parents that are not affected do not hold anything back.models: the affected artifacts of kind "model", in rebuild order.production_hit: the affected models that are in production, sorted alphabetically.