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

Bug fix: filter by metrics in same semantic model as queried metrics #1115

Merged
merged 5 commits into from
Apr 9, 2024

Conversation

courtneyholcomb
Copy link
Contributor

@courtneyholcomb courtneyholcomb commented Apr 8, 2024

Description

In the initial release of Metrics as Dimensions, I overlooked some logic around local elements, resulting in a bug where you can't filter on a metric that's in the same semantic model as the metric you're querying. This fixes that!

Note that the commit Add METRIC property to all_properties() is duplicated in #1107, so I'll make sure to resolve any resulting merge conflicts based on whichever PR merges first.

@cla-bot cla-bot bot added the cla:yes label Apr 8, 2024
@courtneyholcomb courtneyholcomb force-pushed the court/metrics-as-dimensions-fix branch from f88c0f9 to e868eea Compare April 8, 2024 19:37
@dbt-labs dbt-labs deleted a comment from github-actions bot Apr 8, 2024
@courtneyholcomb courtneyholcomb marked this pull request as ready for review April 8, 2024 19:56
@courtneyholcomb courtneyholcomb added the Run Tests With Other SQL Engines Runs the test suite against the SQL engines in our target environment label Apr 8, 2024
@github-actions github-actions bot removed the Run Tests With Other SQL Engines Runs the test suite against the SQL engines in our target environment label Apr 8, 2024
@courtneyholcomb courtneyholcomb mentioned this pull request Apr 9, 2024
Copy link
Contributor

@tlento tlento left a comment

Choose a reason for hiding this comment

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

Assuming I'm understanding this correctly this looks good to me modulo that one static method reference update. If I'm NOT understanding this correctly (see inline), we probably need to check in and at least update the PR description with more details on why this fix does what we need it to do.

@@ -699,7 +721,7 @@ def _get_metric_time_elements(self, measure_reference: Optional[MeasureReference
measure_agg_time_dimension_reference = measure_semantic_model.checked_agg_time_dimension_for_measure(
measure_reference=measure_reference
)
defined_granularity = ValidLinkableSpecResolver._get_time_granularity_for_dimension(
defined_granularity = self._get_time_granularity_for_dimension(
Copy link
Contributor

Choose a reason for hiding this comment

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

That's still a static method, I don't think we need this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is totally unrelated and was just a piece of cleanup. It's not necessary but it doesn't impact the code at all. The reason I added this was for developer-friendliness. Basically, when I'm searching for uses of the class, this clutters my search results. So I'm curious if you have a reason to object to this syntax?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But also I should have left a comment on the PR explaining / maybe made a separate commit for this!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tlento for the sake of getting the feature released I'm going to merge this, but if you have reasons for me to undo this in a follow up commit LMK and I'm happy to!

metric_time_elements = self._get_metric_time_elements(measure_reference)
joined_elements = self._get_joined_elements(measure_semantic_model)

return LinkableElementSet.merge_by_path_key(
(
elements_in_semantic_model,
metrics_linked_to_semantic_model,
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, so this because all of our other joinable metrics were pathing through an entity, so we were finding targets through the existing mechanisms, but since the metrics are a new linkable type they weren't getting included if there was no need for an additional join through an entity or whatever. Is that correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes correct!
This is basically adding "local linkable metrics" to the list of joinable metrics. Technically they aren't local since they aren't necessarily defined in the semantic model. But they are joined once via an entity local to the semantic model.

@courtneyholcomb courtneyholcomb merged commit e759782 into main Apr 9, 2024
28 checks passed
@courtneyholcomb courtneyholcomb deleted the court/metrics-as-dimensions-fix branch April 9, 2024 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants