-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add validation for missing
metric_time
when querying to/through SCD (…
…#1451) ## Summary This PR changes `MetricQueryValidationRule` to raise `ScdRequiresMetricTimeIssue` in case the user submits a query that uses an SCD but does not group by time. ## Implementation To make this happen, I: - refactored how `MetricQueryValidationRule` works to return a new `QueryAnalysisResult` and avoid creating a bunch of separate methods that return booleans - changed `MetricQueryValidationRule` to make it get the specs for all the joinable SCDs for the given metric, match the group by input against it and raise an issue if there's no `metric_time` in the query - created a new `LinkableElementProperty` called `SCD_HOP`, which indicates that you need to join to an SCD somewhere along the path to join to that element - changed the `ValidLinkableSpecResolver` to add `SCD_HOP` to all the linkable elements which go to/through SCDs - added tests for joins to an SCD and through an SCD
- Loading branch information
1 parent
804bee5
commit af045aa
Showing
12 changed files
with
326 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Fixes | ||
body: Add new validation that checks for SCDs in the join path to make grouping by `metric_time` required in this case. | ||
time: 2024-10-11T16:19:26.928496+02:00 | ||
custom: | ||
Author: serramatutu | ||
Issue: "1451" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
metricflow-semantics/metricflow_semantics/query/issues/parsing/scd_requires_metric_time.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from __future__ import annotations | ||
|
||
from collections.abc import Sequence | ||
from dataclasses import dataclass | ||
|
||
from typing_extensions import override | ||
|
||
from metricflow_semantics.query.group_by_item.resolution_path import MetricFlowQueryResolutionPath | ||
from metricflow_semantics.query.issues.issues_base import ( | ||
MetricFlowQueryIssueType, | ||
MetricFlowQueryResolutionIssue, | ||
) | ||
from metricflow_semantics.query.resolver_inputs.base_resolver_inputs import MetricFlowQueryResolverInput | ||
from metricflow_semantics.specs.instance_spec import InstanceSpec | ||
|
||
|
||
@dataclass(frozen=True) | ||
class ScdRequiresMetricTimeIssue(MetricFlowQueryResolutionIssue): | ||
"""Describes an issue with a query that includes a SCD group by but does not include metric_time.""" | ||
|
||
scds_in_query: Sequence[InstanceSpec] | ||
|
||
@override | ||
def ui_description(self, associated_input: MetricFlowQueryResolverInput) -> str: | ||
dim_str = ", ".join(f"'{scd.qualified_name}'" for scd in self.scds_in_query) | ||
return ( | ||
"Your query contains the following group bys, which are SCDs or contain SCDs " | ||
f"in the join path: [{dim_str}].\n\nA query containing SCDs must also contain " | ||
"the metric_time dimension in order to join the SCD table to the valid time " | ||
"range. Please add metric_time to the query and try again. If you're " | ||
"using agg_time_dimension, use metric_time instead." | ||
) | ||
|
||
@override | ||
def with_path_prefix(self, path_prefix: MetricFlowQueryResolutionPath) -> ScdRequiresMetricTimeIssue: | ||
return ScdRequiresMetricTimeIssue( | ||
issue_type=self.issue_type, | ||
parent_issues=self.parent_issues, | ||
query_resolution_path=self.query_resolution_path.with_path_prefix(path_prefix), | ||
scds_in_query=self.scds_in_query, | ||
) | ||
|
||
@staticmethod | ||
def from_parameters( # noqa: D102 | ||
scds_in_query: Sequence[InstanceSpec], query_resolution_path: MetricFlowQueryResolutionPath | ||
) -> ScdRequiresMetricTimeIssue: | ||
return ScdRequiresMetricTimeIssue( | ||
issue_type=MetricFlowQueryIssueType.ERROR, | ||
parent_issues=(), | ||
query_resolution_path=query_resolution_path, | ||
scds_in_query=scds_in_query, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.