Skip to content

Commit

Permalink
Support using the measure label when using create_metric option
Browse files Browse the repository at this point in the history
  • Loading branch information
aliceliu committed Aug 7, 2024
1 parent 21a4633 commit 402c4c6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20240806-172110.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Propagate measure label when using create_metrics
time: 2024-08-06T17:21:10.265494-07:00
custom:
Author: aliceliu
Issue: "10536"
2 changes: 1 addition & 1 deletion core/dbt/parser/schema_yaml_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ def _create_metric(
) -> None:
unparsed_metric = UnparsedMetric(
name=measure.name,
label=measure.name,
label=measure.label or measure.name,
type="simple",
type_params=UnparsedMetricTypeParams(measure=measure.name, expr=measure.name),
description=measure.description or f"Metric created from measure {measure.name}",
Expand Down
6 changes: 6 additions & 0 deletions tests/functional/semantic_models/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@
agg: sum
agg_time_dimension: ds
create_metric: true
- name: txn_revenue_with_label
label: "Transaction Revenue with label"
expr: revenue
agg: sum
agg_time_dimension: ds
create_metric: true
- name: sum_of_things
expr: 2
agg: sum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def test_semantic_model_deleted_partial_parsing(self, project):

def test_semantic_model_flipping_create_metric_partial_parsing(self, project):
generated_metric = "metric.test.txn_revenue"
generated_metric_with_label = "metric.test.txn_revenue_with_label"
# First, use the default schema.yml to define our semantic model, and
# run the dbt parse command
write_file(schema_yml, project.project_root, "models", "schema.yml")
Expand All @@ -117,6 +118,11 @@ def test_semantic_model_flipping_create_metric_partial_parsing(self, project):
# Verify the metric created by `create_metric: true` exists
metric = result.result.metrics[generated_metric]
assert metric.name == "txn_revenue"
assert metric.label == "txn_revenue"

metric_with_label = result.result.metrics[generated_metric_with_label]
assert metric_with_label.name == "txn_revenue_with_label"
assert metric_with_label.label == "Transaction Revenue with label"

# --- Next, modify the default schema.yml to have no `create_metric: true` ---
no_create_metric_schema_yml = schema_yml.replace(
Expand Down

0 comments on commit 402c4c6

Please sign in to comment.