dbt Documentation
repository·main·Indexed 41 days ago
https://github.com/dbt-labs/dbt-docsTools and source code for generating a visual, searchable documentation website for dbt projects. Includes functionality to visualize models, tests, and data lineage via a web interface, with commands like `dbt docs generate` and `dbt docs serve` to create and host project metadata.
What's inside dbt
- dbt-docs is the codebase responsible for generating the documentation website for dbt projects. It transforms dbt project metadata into a visual, searchable documentation site that helps analysts understand their models, tests, and data lineage.
Generate and serve dbt documentation
mainTo view the documentation site for your dbt project, you must first generate the documentation artifacts and then start a local web server to host them. Run these commands from within your dbt project directory:
dbt docs generate: This command parses your project and generates the necessary JSON files containing your project's metadata, models, tests, and lineage.dbt docs serve: This command starts a local web server to view the generated documentation in your browser.
dbt docs generate dbt docs serveRetrieve descendant nodes with descendentNodes()
mainThe
descendentNodes(dag, node, max_hops, hop_index)function traverses the DAG downwards from a given node to find its successors.dag: The graph object (must support.successors(node)).node: The starting node.max_hops(optional): The maximum number of levels to traverse downwards.hop_index(optional): Internal tracker for recursion depth.
Returns an array of unique descendant nodes.
// Get all descendants up to 2 hops away const descendants = descendentNodes(dag, node, 2);Select a node and its related lineage with selectAt()
mainThe
selectAt(dag, node)function returns a collection of nodes representing a specific lineage pattern: it includes the target node, all of its descendants, and all ancestors of those descendants. This is useful for highlighting a node and its entire upstream/downstream impact area within a Directed Acyclic Graph (DAG).// Returns all parents of all children of the node const selectedNodes = selectAt(dag, node);Retrieve ancestor nodes with ancestorNodes()
mainThe
ancestorNodes(dag, node, max_hops, hop_index)function traverses the DAG upwards from a given node to find its predecessors.dag: The graph object (must support.predecessors(node)).node: The starting node.max_hops(optional): The maximum number of levels to traverse upwards.hop_index(optional): Internal tracker for recursion depth.
Returns an array of unique ancestor nodes.
// Get all ancestors up to 3 hops away const ancestors = ancestorNodes(dag, node, 3);