Lineage
Trace a metric or field back to what it is built from
Anfra.lineage() traces fields upstream: the metrics and model fields a metric uses, their models, and the tables behind them. Use it to show where a number comes from, such as a definitions panel next to a chart.
Anfra.lineage() comes from the lineage plugin. anfra serve installs it, but another host may not.
Tracing fields
const { results: [revenue, country] } = await Anfra.lineage([
{ parent: 'ecommerce', child: 'revenue' }, // a dataset metric
{ parent: 'customers', child: 'country' }, // a model field
])Name each target by what holds it: a dataset and its metric, or a model and its field. Take the names from Anfra.datasets.
Anfra.lineage() is a plain promise, outside execute() and subscribe. Call it again when the reader picks another field. Check Anfra.plugins.has('lineage') before offering it: on a host without the plugin, Anfra.lineage is undefined.
Results
Each entry in results is { target, query, diagram }, or { target, query, error } when that field could not be traced. error is a string.
A diagram is a set of cards (models, datasets, tables) in layers, upstream first:
diagram.layers // [{ index, types, card_ids }, ...]
diagram.cards // [{ id, type, label, layer, props, links, sections }, ...]
diagram.total // matched entities, over every pageA card's sections hold its fields as nodes, which can have sections of their own. A link { to: B, type: 'refers' } on A means A uses B.
An empty diagram means nothing is upstream, as for a dimension that is a plain column.
Options and errors
limitandoffsetpage the results. Passsignalfrom anAbortControllerto cancel a call.- The promise rejects with a
ValidationErrorfor a malformed target list, aTransportErrorwhen lineage is unavailable, or aPermissionError.
Lineage reads the catalog built by anfra ingest. Run it after you change the AML, or lineage shows the old definitions.
Related
- Plugins: checking that the host installed
lineage. - Lineage: what lineage is for.
anfra lineage: trace a field from the terminal.