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
This likely won't be the final implementation, but a stepping stone.
The reason for that is: THIS DOESN'T ACCOUNT FOR PARTIAL PARSING. Not
accounting for partial parsing is problematic. There are 3 specific
cases that we need to keep in mind / figure out:

1. What happens when a measure maintains `create_metric = True` and
partial parsing happens? With this current workflow, a parsing error
is raised because the measure tries to create the metric again as it
has no way to know a metric has already been created

2. What happens when a measure changes from `create_metric = True` to
`create_metric = False` and partial parsing happens?? With this current
workflow, the metric will continue to exist because it doesn't know
to check if a metric needs to be removed, or even how to check for
that case.

3. What happens when a measure changes from `create_metric = False` to
`create_metric = True` and partial parsing? With the current workflow,
the metric gets created, which is what we want.
  • Loading branch information
QMalcolm committed Aug 3, 2023
1 parent eecc254 commit 8459820
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions core/dbt/parser/schema_yaml_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand Down

0 comments on commit 8459820

Please sign in to comment.