Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow metrics in semantic layer filters #9773

Merged
merged 4 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20240322-103124.yaml
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not backwards compatible with 0.5.0? Should we be pinning a range here or a specific version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is backwards compatible! Basically, I want to ensure that this feature is available for all users on core 1.8 once that gets released. We could leave the existing version range, but it might cause confusion for users if they somehow end up on DSI 0.5.0 and wonder why this feature isn't available!

Copy link
Contributor

@QMalcolm QMalcolm Mar 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case it looks like a feature was added in the patch version bump to 0.5.1 from 0.5.0, specifically a feature allowing metrics to be referenced in filter attributes of semantic layer objects. Arguably, this should have constituted a 0.6.0, but the release of 0.5.1 has already happened. This makes 0.5.1 not fully backwards compatible with 0.5.0 in that if someone were to specify a metric in a filter, parsing would break if 0.5.0 is the installed DSI version.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we'll want to get this change in prior to the final release of core 1.8.0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguably, this should have constituted a 0.6.0, but the release of 0.5.1 has already happened.

This makes sense. As long as in future we try to follow semver more closely I'll ✅ this. Since 1.7 is on 0.4 anyways it's low risk.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just me over her conflating backwards compatibility with being a purely additive change - sorry for the confusion!
And yes @QMalcolm point taken - we can do some work on the SL side to clean up our OSS versioning story in the future 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick review - would one of y'all mind merging? I don't have permission.

# Minor versions for these are expected to be backwards-compatible
"dbt-common<2.0",
"dbt-adapters>=0.1.0a2,<2.0",
Expand Down
8 changes: 8 additions & 0 deletions tests/functional/metrics/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand Down
1 change: 1 addition & 0 deletions tests/functional/saved_queries/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading