-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for querying with metric alias (#1573)
## Summary This PR introduces support for querying with aliased metrics. This is done by adding an `AliasSpecsNode` after the order by step in `DataflowPlanBuilder`. To make the alias information reach that point, I also had to modify some of the query interface classes to allow aliases in metrics. You can review commit by commit. --------- Co-authored-by: Courtney Holcomb <[email protected]> Co-authored-by: Will Deng <[email protected]>
- Loading branch information
1 parent
f6f63d7
commit a4cc831
Showing
204 changed files
with
2,535 additions
and
681 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: Features | ||
body: Allow setting aliases for queried metrics | ||
time: 2024-12-13T11:04:07.020346+01:00 | ||
custom: | ||
Author: serramatutu | ||
Issue: "1573" |
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
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
49 changes: 49 additions & 0 deletions
49
metricflow-semantics/metricflow_semantics/query/issues/parsing/duplicate_metric_alias.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,49 @@ | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
from typing import Sequence, Tuple | ||
|
||
from dbt_semantic_interfaces.references import MetricReference | ||
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 DuplicateMetricAliasIssue(MetricFlowQueryResolutionIssue): | ||
"""Describes when there are duplicate metric aliases in a query.""" | ||
|
||
duplicate_metric_references: Tuple[MetricReference, ...] | ||
|
||
@staticmethod | ||
def from_parameters( # noqa: D102 | ||
duplicate_metric_references: Sequence[MetricReference], | ||
query_resolution_path: MetricFlowQueryResolutionPath, | ||
) -> DuplicateMetricAliasIssue: | ||
return DuplicateMetricAliasIssue( | ||
issue_type=MetricFlowQueryIssueType.ERROR, | ||
parent_issues=(), | ||
duplicate_metric_references=tuple(duplicate_metric_references), | ||
query_resolution_path=query_resolution_path, | ||
) | ||
|
||
@override | ||
def ui_description(self, associated_input: MetricFlowQueryResolverInput) -> str: | ||
return ( | ||
f"Query contains duplicate metric aliases: " | ||
f"{[metric_reference.element_name for metric_reference in self.duplicate_metric_references]}" | ||
) | ||
|
||
@override | ||
def with_path_prefix(self, path_prefix: MetricFlowQueryResolutionPath) -> DuplicateMetricAliasIssue: | ||
return DuplicateMetricAliasIssue( | ||
issue_type=self.issue_type, | ||
parent_issues=tuple(issue.with_path_prefix(path_prefix) for issue in self.parent_issues), | ||
query_resolution_path=self.query_resolution_path.with_path_prefix(path_prefix), | ||
duplicate_metric_references=self.duplicate_metric_references, | ||
) |
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
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.