-
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 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
a4ea534
commit 3d5170d
Showing
6 changed files
with
182 additions
and
13 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
51 changes: 51 additions & 0 deletions
51
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,51 @@ | ||
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 | ||
|
||
|
||
@dataclass(frozen=True) | ||
class SCDRequiresMetricTimeIssue(MetricFlowQueryResolutionIssue): | ||
"""Describes an issue with a query that includes a SCD group by but does not include metric_time.""" | ||
|
||
scd_qualified_names: Sequence[str] | ||
|
||
@override | ||
def ui_description(self, associated_input: MetricFlowQueryResolverInput) -> str: | ||
dim_str = ", ".join(self.scd_qualified_names) | ||
return ( | ||
f"Your query contains the Slowly Changing Dimensions (SCDs): [{dim_str}]. " | ||
"A 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), | ||
scd_qualified_names=self.scd_qualified_names, | ||
) | ||
|
||
@staticmethod | ||
def from_parameters( # noqa: D102 | ||
scd_qualified_names: Sequence[str], query_resolution_path: MetricFlowQueryResolutionPath | ||
) -> SCDRequiresMetricTimeIssue: | ||
return SCDRequiresMetricTimeIssue( | ||
issue_type=MetricFlowQueryIssueType.ERROR, | ||
parent_issues=(), | ||
query_resolution_path=query_resolution_path, | ||
scd_qualified_names=scd_qualified_names, | ||
) |
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