Section 13.18

Data lineage

Definition

Data lineage is the record of which inputs and which transformations produced each dataset and each result. It is usually kept as a directed graph, a set of nodes joined by one-way arrows. A node is a dataset version, a transformation with its parameters, or a result such as a table or a plot; an arrow points from something used to what used it. Following arrows forward from a changed node finds everything that may change with it; following them backward finds everything a result depends on.

The idea

A parser, the program that turns raw log files into tables, is changed so that it counts failed trials differently. A report contains a dozen tables and plots, and some of them must now be computed again. Recomputing every table is slow. If the raw records survive, the analysis can still be repeated after the hardware is gone; collecting replacement observations may then be impossible. Guessing misses results that depend on the parser only indirectly, through an intermediate table. Data lineage settles which results to recompute from recorded dependencies, not from file names, folders or positions in the report.

A food recall is a fair picture. When one batch of flour turns out to be contaminated, the records of the supplier show which bakeries received that batch and which products they made from it, and only those products are recalled. The picture stops being accurate in one respect. Contaminated flour spoils every product made from it, but a changed dataset does not always change every result built from it: a table that uses only an unaffected column stays the same. Lineage finds the candidates for change; checking each candidate decides which ones actually changed.

How it works

Building and using lineage takes these steps.

  1. Identify every node by content and version. Identify a dataset by a digest of its bytes (a short value that a cryptographic hash function §5.1 computes from them), not by its file name: a renamed copy is the same data, and a filtered table saved under an old name is new data. Identify a transformation by its program version and parameters.

  2. Record the arrows while the work runs. Each time a transformation reads inputs and writes outputs, record an arrow from each input to the transformation and from the transformation to each output. Include the inputs that are easy to forget: configuration files, eligibility rules, library versions and every manual step.

  3. Never overwrite a version. A changed dataset or program becomes a new node. Nothing can then depend on its own later version, so the graph has no cycles: it is a directed acyclic graph §14.17.

  4. Find the impact of a change with a forward search: follow arrows from the changed node to every node reachable from it. These nodes are its descendants, and any graph reachability search §14.18 finds them.

  5. Decide for each candidate: compute it again, or keep it with a recorded reason. A simple reason is that the node was recomputed and its digest is unchanged; nothing that depends only on that node then needs recomputing.

  6. Find what a result depends on with a backward search from the result to its ancestors, which ends at the raw data §13.16.

Lineage can be recorded per file or per field, such as one column of a table. Per-file lineage finds more candidates than strictly necessary; that costs recomputation but misses nothing. A missing arrow is the dangerous error, because it hides a real dependency. The Incremental validation §10.42 entry applies the same forward search to code changes and the tests they affect.

Worked example

A report has seven nodes. For brevity, the parser and the table it writes are one node.

The arrows are A→BA \to B, B→CB \to C, B→DB \to D, C→SC \to S, E→FE \to F and F→SF \to S.

The parser changes its treatment of failed trials. Following arrows forward from BB reaches CC and DD in one step and SS in two steps, through CC. The descendants of BB are {C,D,S}\{C, D, S\}, and with BB itself, 1+3=41 + 3 = 4 of the 7 nodes are candidates. SS never reads the output of the parser, yet it is a candidate: it has a transitive dependency §10.43 on BB, an indirect one through CC. AA, EE and FF are not descendants of BB, so they cannot change, even though FF sits next to DD on the same page of the report.

Among the candidates, CC changes for certain, because its denominator, the number of trials counted, depends on how failed trials are treated, and SS changes with CC. DD uses only successful trials. If the change merely relabels failures, a recomputed DD has the same digest as before, and the old DD is kept with that comparison as its reason.

Stated precisely

Let VV be the set of nodes, and write u→vu \to v when vv was produced using uu. The descendants of a node xx, written desc(x)\mathrm{desc}(x), are the nodes that can be reached from xx by a path of one or more arrows. For a set Δ\Delta of changed nodes, the candidate set is Δ∪⋃x∈Δdesc(x).\Delta \cup \bigcup_{x \in \Delta} \mathrm{desc}(x). In the example, Δ={B}\Delta = \{B\} and the candidate set is {B,C,D,S}\{B, C, D, S\}, which is 4 of the 7 nodes.

The guarantee is that every node outside the candidate set is unchanged. It rests on three assumptions.

  1. Complete arrows: every input that influenced a node is recorded as an arrow, including parameters, library versions and manual steps.

  2. Deterministic transformations: the same inputs and parameters always give the same output.

  3. Immutable versions: no recorded node is ever changed in place.

Under these three assumptions, a node outside the candidate set has the same inputs and the same transformation as before, so it has the same content. The converse does not hold. A node inside the candidate set may be unchanged, and showing that it is unchanged needs either a recomputation or an argument about which parts of its inputs it uses.

Limits and common mistakes

Lineage is only as complete as its arrows. A manual edit, a setting read from the environment or an unrecorded library version is a missing arrow, and a result that depends on it can go stale without ever appearing in a search.

Arrows drawn afterwards from memory are a claim about history, not evidence of it.

A candidate is not a changed result. Lineage lists what may change; recomputation, or an argument about the fields a node uses, decides what did change.

Names are not identity. A copied file with the same bytes is the same data under any name, and a filtered table under an old name is new data. Identify nodes by digest.

Two results stored beside each other may use unrelated inputs. Conversely, a histogram and a mean computed from one set of readings share a dependency on those readings even when neither result feeds the other. Follow the arrows back to their common inputs.

Lineage records dependencies, not correctness. A result with complete lineage can still come from a wrong program.

Questions answered

Which plots change when one eligibility rule or parser changes?

The plots that can change are exactly the descendants of the changed rule or parser in the data lineage graph, the recorded graph of which inputs and transformations produced each dataset and result. To find them, start at the changed node and follow the recorded arrows forward, through every intermediate dataset, count, denominator and table, to every plot that is reached. A plot that depends on the change only indirectly, through an intermediate table, is included.

Plots that are not reached cannot change, provided that every real dependency was recorded, every transformation gives the same output for the same inputs, and no recorded dataset was edited in place. Being reached does not prove that a plot changed. Recompute each reached plot, or show that it uses only parts of its inputs that the change did not touch, and record that reason. A plot that merely sits near a changed plot, in the same folder or figure, is unaffected unless an arrow joins the two.

Related entries: Artifact provenance (§13.1), Raw data versus derived data (§13.16), Incremental validation (§10.42), Transitive dependency (§10.43), Directed acyclic graph (DAG) (§14.17), Graph reachability search (§14.18).