-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow ambiguous entity-paths in group-by-item inputs.
This allows an input like "entity_0__country" to match group-by-items with longer paths like "entity_1__entity_0__country" if there's a single group-by-item with the shortest entity-path in the set of available items.
- Loading branch information
Showing
18 changed files
with
359 additions
and
7 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
69 changes: 69 additions & 0 deletions
69
metricflow/query/issues/group_by_item_resolver/multiple_join_paths.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,69 @@ | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
from typing import Sequence | ||
|
||
from typing_extensions import override | ||
|
||
from metricflow.mf_logging.formatting import indent | ||
from metricflow.mf_logging.pretty_print import mf_pformat | ||
from metricflow.naming.object_builder_scheme import ObjectBuilderNamingScheme | ||
from metricflow.query.group_by_item.candidate_push_down.group_by_item_candidate import GroupByItemCandidateSet | ||
from metricflow.query.group_by_item.resolution_path import MetricFlowQueryResolutionPath | ||
from metricflow.query.issues.issues_base import ( | ||
MetricFlowQueryIssueType, | ||
MetricFlowQueryResolutionIssue, | ||
) | ||
from metricflow.query.resolver_inputs.base_resolver_inputs import MetricFlowQueryResolverInput | ||
|
||
|
||
@dataclass(frozen=True) | ||
class MultipleMatchIssue(MetricFlowQueryResolutionIssue): | ||
"""Describes an issue during group-by-item resolution the input pattern matches multiple specs.""" | ||
|
||
candidate_set: GroupByItemCandidateSet | ||
|
||
@staticmethod | ||
def from_parameters( # noqa: D | ||
query_resolution_path: MetricFlowQueryResolutionPath, | ||
candidate_set: GroupByItemCandidateSet, | ||
parent_issues: Sequence[MetricFlowQueryResolutionIssue], | ||
) -> MultipleMatchIssue: | ||
return MultipleMatchIssue( | ||
issue_type=MetricFlowQueryIssueType.ERROR, | ||
query_resolution_path=query_resolution_path, | ||
candidate_set=candidate_set, | ||
parent_issues=tuple(parent_issues), | ||
) | ||
|
||
@override | ||
def ui_description(self, associated_input: MetricFlowQueryResolverInput) -> str: | ||
last_path_item = self.query_resolution_path.last_item | ||
naming_scheme = ( | ||
associated_input.input_pattern_description.naming_scheme | ||
if associated_input.input_pattern_description is not None | ||
else ObjectBuilderNamingScheme() | ||
) | ||
|
||
specs_as_strs = [] | ||
for spec in self.candidate_set.specs: | ||
input_str = naming_scheme.input_str(spec) | ||
if input_str is not None: | ||
specs_as_strs.append(input_str) | ||
else: | ||
specs_as_strs.append(f"<{repr(spec)}>") | ||
|
||
return ( | ||
f"The given input matches multiple group-by-items for {last_path_item.ui_description}:\n\n" | ||
f"{indent(mf_pformat(specs_as_strs))}\n\n" | ||
f"Please use a more specific input to resolve the ambiguity." | ||
) | ||
|
||
@override | ||
def with_path_prefix(self, path_prefix: MetricFlowQueryResolutionPath) -> MultipleMatchIssue: | ||
return MultipleMatchIssue( | ||
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), | ||
candidate_set=self.candidate_set.with_path_prefix(path_prefix), | ||
) |
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
16 changes: 16 additions & 0 deletions
16
...res/semantic_manifest_yamls/simple_multi_hop_join_manifest/entity_0_dimension_source.yaml
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,16 @@ | ||
--- | ||
semantic_model: | ||
name: entity_0_dimension_source | ||
description: Contains dimensions for "entity_0" | ||
|
||
node_relation: | ||
schema_name: $source_schema | ||
alias: entity_0_dimension_table | ||
|
||
dimensions: | ||
- name: country | ||
type: categorical | ||
|
||
entities: | ||
- name: entity_0 | ||
type: primary |
31 changes: 31 additions & 0 deletions
31
...c_manifest_yamls/simple_multi_hop_join_manifest/entity_1_and_entity_2_measure_source.yaml
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,31 @@ | ||
--- | ||
semantic_model: | ||
name: entity_1_and_entity_2_measure_source | ||
description: A measure source associated with "entity_1" and "entity_2". | ||
|
||
node_relation: | ||
schema_name: $source_schema | ||
alias: entity_1_and_entity_2_measure_table | ||
|
||
defaults: | ||
agg_time_dimension: ds | ||
|
||
measures: | ||
- name: entity_1_and_entity_2_measure | ||
agg: sum | ||
expr: "1" | ||
|
||
dimensions: | ||
- name: ds | ||
type: time | ||
type_params: | ||
time_granularity: day | ||
|
||
entities: | ||
- name: composite_entity | ||
type: primary | ||
expr: entity_1 || entity_2 | ||
- name: entity_1 | ||
type: foreign | ||
- name: entity_2 | ||
type: foreign |
25 changes: 25 additions & 0 deletions
25
...tures/semantic_manifest_yamls/simple_multi_hop_join_manifest/entity_1_measure_source.yaml
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,25 @@ | ||
--- | ||
semantic_model: | ||
name: entity_1_measure_source | ||
description: A measure source associated with "entity_1". | ||
|
||
node_relation: | ||
schema_name: $source_schema | ||
alias: entity_1_measure_table | ||
|
||
defaults: | ||
agg_time_dimension: ds | ||
|
||
measures: | ||
- name: entity_1_measure | ||
agg: sum | ||
|
||
dimensions: | ||
- name: ds | ||
type: time | ||
type_params: | ||
time_granularity: day | ||
|
||
entities: | ||
- name: entity_1 | ||
type: primary |
14 changes: 14 additions & 0 deletions
14
...ic_manifest_yamls/simple_multi_hop_join_manifest/entity_1_to_entity_0_mapping_source.yaml
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,14 @@ | ||
--- | ||
semantic_model: | ||
name: entity_1_to_entity_0_mapping_source | ||
description: Maps "entity_1" to "entity_0" | ||
|
||
node_relation: | ||
schema_name: $source_schema | ||
alias: entity_1_to_entity_0_mapping_table | ||
|
||
entities: | ||
- name: entity_1 | ||
type: primary | ||
- name: entity_0 | ||
type: foreign |
14 changes: 14 additions & 0 deletions
14
...ic_manifest_yamls/simple_multi_hop_join_manifest/entity_2_to_entity_0_mapping_source.yaml
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,14 @@ | ||
--- | ||
semantic_model: | ||
name: entity_2_to_entity_0_mapping_source | ||
description: Maps "entity_2" to "entity_0" | ||
|
||
node_relation: | ||
schema_name: $source_schema | ||
alias: entity_2_to_entity_0_mapping_table | ||
|
||
entities: | ||
- name: entity_2 | ||
type: primary | ||
- name: entity_0 | ||
type: foreign |
14 changes: 14 additions & 0 deletions
14
metricflow/test/fixtures/semantic_manifest_yamls/simple_multi_hop_join_manifest/metrics.yaml
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,14 @@ | ||
--- | ||
metric: | ||
name: entity_1_metric | ||
description: Metric based on a measure defined with "entity_1" | ||
type: simple | ||
type_params: | ||
measure: entity_1_measure | ||
--- | ||
metric: | ||
name: entity_1_and_entity_2_metric | ||
description: Metric based on a measure defined with "entity_1" and "entity_2" | ||
type: simple | ||
type_params: | ||
measure: entity_1_and_entity_2_measure |
1 change: 1 addition & 0 deletions
1
...ixtures/semantic_manifest_yamls/simple_multi_hop_join_manifest/project_configuration.yaml
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 @@ | ||
../shared/project_configuration.yaml |
11 changes: 11 additions & 0 deletions
11
...tures/source_table_snapshots/simple_multi_hop_join_manifest/entity_0_dimension_table.yaml
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,11 @@ | ||
--- | ||
table_snapshot: | ||
table_name: entity_0_dimension_source | ||
column_definitions: | ||
- name: entity_0 | ||
type: STRING | ||
- name: country | ||
type: STRING | ||
rows: | ||
- ["E0_0", "us"] | ||
- ["E0_1", "ca"] |
12 changes: 12 additions & 0 deletions
12
...e_table_snapshots/simple_multi_hop_join_manifest/entity_1_and_entity_2_measure_table.yaml
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,12 @@ | ||
--- | ||
table_snapshot: | ||
table_name: entity_1_and_entity_2_measure_table | ||
column_definitions: | ||
- name: entity_1 | ||
type: STRING | ||
- name: entity_2 | ||
type: STRING | ||
- name: ds | ||
type: TIME | ||
rows: | ||
- ["E0_0", "E1_0", "2020-01-01"] |
10 changes: 10 additions & 0 deletions
10
...ixtures/source_table_snapshots/simple_multi_hop_join_manifest/entity_1_measure_table.yaml
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,10 @@ | ||
--- | ||
table_snapshot: | ||
table_name: entity_1_measure_table | ||
column_definitions: | ||
- name: entity_1 | ||
type: STRING | ||
- name: ds | ||
type: TIME | ||
rows: | ||
- ["E1_0", "2020-01-01"] |
10 changes: 10 additions & 0 deletions
10
...ce_table_snapshots/simple_multi_hop_join_manifest/entity_1_to_entity_0_mapping_table.yaml
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,10 @@ | ||
--- | ||
table_snapshot: | ||
table_name: entity_1_to_entity_0_table | ||
column_definitions: | ||
- name: entity_1 | ||
type: STRING | ||
- name: entity_0 | ||
type: STRING | ||
rows: | ||
- ["E1_0", "E0_0"] |
10 changes: 10 additions & 0 deletions
10
...ixtures/source_table_snapshots/simple_multi_hop_join_manifest/entity_2_measure_table.yaml
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,10 @@ | ||
--- | ||
table_snapshot: | ||
table_name: entity_2_measure_table | ||
column_definitions: | ||
- name: entity_2 | ||
type: STRING | ||
- name: ds | ||
type: TIME | ||
rows: | ||
- ["E2_0", "2020-01-01"] |
10 changes: 10 additions & 0 deletions
10
...ce_table_snapshots/simple_multi_hop_join_manifest/entity_2_to_entity_0_mapping_table.yaml
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,10 @@ | ||
--- | ||
table_snapshot: | ||
table_name: entity_2_to_entity_0_mapping_table | ||
column_definitions: | ||
- name: entity_2 | ||
type: STRING | ||
- name: entity_0 | ||
type: STRING | ||
rows: | ||
- ["E2_0", "E0_1"] |
Oops, something went wrong.