Skip to content

Commit

Permalink
Begin creating metrics from measures with create_metric = True
Browse files Browse the repository at this point in the history
  • Loading branch information
QMalcolm committed Aug 3, 2023
1 parent eecc254 commit 0ae1416
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions core/dbt/parser/schema_yaml_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,19 @@ def _get_measures(self, unparsed_measures: List[UnparsedMeasure]) -> List[Measur
)
return measures

def _create_metric(self, measure: UnparsedMeasure, enabled: bool) -> 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}",
config={"enabled": enabled},
)

parser = MetricParser(self.schema_parser, yaml=self.yaml)
parser.parse_metric(unparsed=unparsed_metric)

def parse_semantic_model(self, unparsed: UnparsedSemanticModel):
package_name = self.project.project_name
unique_id = f"{NodeType.SemanticModel}.{package_name}.{unparsed.name}"
Expand Down Expand Up @@ -550,6 +563,11 @@ def parse_semantic_model(self, unparsed: UnparsedSemanticModel):
# No ability to disable a semantic model at this time
self.manifest.add_semantic_model(self.yaml.file, parsed)

# Create a metric for each measure with `create_metric = True`
for measure in unparsed.measures:
if measure.create_metric is True:
self._create_metric(measure=measure, enabled=parsed.config.enabled)

def parse(self):
for data in self.get_key_dicts():
try:
Expand Down

0 comments on commit 0ae1416

Please sign in to comment.