diff --git a/core/dbt/parser/schema_yaml_readers.py b/core/dbt/parser/schema_yaml_readers.py index 2f2a3eb18e6..780a446cb71 100644 --- a/core/dbt/parser/schema_yaml_readers.py +++ b/core/dbt/parser/schema_yaml_readers.py @@ -491,6 +491,18 @@ def _get_non_additive_dimension( else: return None + def _create_metric(self, measure: UnparsedMeasure) -> None: + unparsed_metric = UnparsedMetric( + name=measure.name, + label=measure.name, + type="simple", + type_params=UnparsedMetricTypeParams(measure=measure.name, expr=measure.name), + description=measure.description or f"Metric created from measure {measure.name}", + ) + + parser = MetricParser(self.schema_parser, yaml=self.yaml) + parser.parse_metric(unparsed=unparsed_metric) + def _get_measures(self, unparsed_measures: List[UnparsedMeasure]) -> List[Measure]: measures: List[Measure] = [] for unparsed in unparsed_measures: @@ -507,6 +519,9 @@ def _get_measures(self, unparsed_measures: List[UnparsedMeasure]) -> List[Measur agg_time_dimension=unparsed.agg_time_dimension, ) ) + if unparsed.create_metric is True: + self._create_metric(unparsed) + return measures def parse_semantic_model(self, unparsed: UnparsedSemanticModel):