-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add validation rule for SCD query with no time
This commit adds a new step to `MetricTimeQueryValidationRule` which does the following: 1. Selects all the existing SCDs for the queried metric 2. Match them against the spec pattern of the group by input 3. Raise a `SCDRequiresMetricTimeIssue` if no `metric_time` was provided and there were matches To accomplish step 1, I had to create a new `LinkableElementProperty` called `SCD_HOP`. This new property indicates that the join path to the linkable element goes through an SCD at some point. I changed the `ValidLinkableSpecResolver` to add `SCD_HOP` to the properties of all the elements it finds whenever that element belongs to an SCD or if the path to it contains an SCD.
- Loading branch information
1 parent
d4ecffe
commit 3ccc016
Showing
11 changed files
with
281 additions
and
69 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
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(scd.qualified_name for scd in self.scds_in_query) | ||
return ( | ||
"Your query contains the group bys which are SCDs or contain SCDs in the " | ||
f"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, | ||
) |
2 changes: 1 addition & 1 deletion
2
metricflow-semantics/metricflow_semantics/query/validation_rules/base_validation_rule.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
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
Oops, something went wrong.