How metrics macros work
mainThe dbt_metrics package uses a structured macro flow to ensure consistent SQL generation. The process begins with one of two primary entry-point macros:
calculate: The primary macro used by end-users to generate metric SQL.develop: A macro used for testing and simulating metrics by providing metric YAML files without including them in the full project.
Both macros follow a two-step execution lifecycle:
1. Validation
The macros validate that inputs are correct and match expected schemas. They also validate inputs against the existing metrics object in the dbt manifest to ensure dimensions are correct, time grains are permitted, and other constraints are met.
2. Variable Creation
Both macros generate two critical internal variables required for downstream SQL generation processes: metric_tree and metrics_dictionary.