From 8c8c6284fb504e9b4af01bfa2ed27c7c7fb855b4 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Fri, 22 Mar 2024 11:49:47 -0700 Subject: [PATCH] Allow metrics in semantic layer filters (#9773) * Tests for metrics in filters * Bump DSI version * Update test * Changelog --- .changes/unreleased/Features-20240322-103124.yaml | 6 ++++++ core/setup.py | 2 +- tests/functional/metrics/fixtures.py | 8 ++++++++ tests/functional/saved_queries/fixtures.py | 1 + .../functional/saved_queries/test_saved_query_parsing.py | 2 +- 5 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 .changes/unreleased/Features-20240322-103124.yaml diff --git a/.changes/unreleased/Features-20240322-103124.yaml b/.changes/unreleased/Features-20240322-103124.yaml new file mode 100644 index 00000000000..735dd44bdbc --- /dev/null +++ b/.changes/unreleased/Features-20240322-103124.yaml @@ -0,0 +1,6 @@ +kind: Features +body: Allow metrics in semantic layer filters. +time: 2024-03-22T10:31:24.76978-07:00 +custom: + Author: courtneyholcomb + Issue: "9804" diff --git a/core/setup.py b/core/setup.py index e49ad973568..eef7dae7fe4 100644 --- a/core/setup.py +++ b/core/setup.py @@ -73,7 +73,7 @@ # Accept patches but avoid automatically updating past a set minor version range. "dbt-extractor>=0.5.0,<=0.6", "minimal-snowplow-tracker>=0.0.2,<0.1", - "dbt-semantic-interfaces>=0.5.0,<0.6", + "dbt-semantic-interfaces>=0.5.1,<0.6", # Minor versions for these are expected to be backwards-compatible "dbt-common<2.0", "dbt-adapters>=0.1.0a2,<2.0", diff --git a/tests/functional/metrics/fixtures.py b/tests/functional/metrics/fixtures.py index 95cc5caa0e5..c9d2d0ab190 100644 --- a/tests/functional/metrics/fixtures.py +++ b/tests/functional/metrics/fixtures.py @@ -88,6 +88,14 @@ metrics: - average_tenure expr: "average_tenure + 1" + + - name: tenured_people + label: Tenured People + description: People who have been here more than 1 year + type: simple + type_params: + measure: people + filter: "{{ Metric('collective_tenure', ['id']) }} > 2" """ metricflow_time_spine_sql = """ diff --git a/tests/functional/saved_queries/fixtures.py b/tests/functional/saved_queries/fixtures.py index fd1f6168a4b..b2025ba208a 100644 --- a/tests/functional/saved_queries/fixtures.py +++ b/tests/functional/saved_queries/fixtures.py @@ -17,6 +17,7 @@ where: - "{{ Dimension('user__ds', 'DAY') }} <= now()" - "{{ Dimension('user__ds', 'DAY') }} >= '2023-01-01'" + - "{{ Metric('txn_revenue', ['id']) }} > 1" exports: - name: my_export config: diff --git a/tests/functional/saved_queries/test_saved_query_parsing.py b/tests/functional/saved_queries/test_saved_query_parsing.py index f6343637160..9c02b7c5418 100644 --- a/tests/functional/saved_queries/test_saved_query_parsing.py +++ b/tests/functional/saved_queries/test_saved_query_parsing.py @@ -41,7 +41,7 @@ def test_semantic_model_parsing(self, project): assert saved_query.name == "test_saved_query" assert len(saved_query.query_params.metrics) == 1 assert len(saved_query.query_params.group_by) == 1 - assert len(saved_query.query_params.where.where_filters) == 2 + assert len(saved_query.query_params.where.where_filters) == 3 assert len(saved_query.depends_on.nodes) == 1 assert saved_query.description == "My SavedQuery Description" assert len(saved_query.exports) == 1