-
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.
Move query_parser tests & add snapshots
- Loading branch information
1 parent
72e1986
commit b794754
Showing
8 changed files
with
188 additions
and
32 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
119 changes: 119 additions & 0 deletions
119
metricflow-semantics/tests_metricflow_semantics/query/test_metric_time_granularity.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,119 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
|
||
import pytest | ||
from _pytest.fixtures import FixtureRequest | ||
from metricflow_semantics.model.semantic_manifest_lookup import SemanticManifestLookup | ||
from metricflow_semantics.query.query_exceptions import InvalidQueryException | ||
from metricflow_semantics.query.query_parser import MetricFlowQueryParser | ||
from metricflow_semantics.test_helpers.config_helpers import MetricFlowTestConfiguration | ||
from metricflow_semantics.test_helpers.snapshot_helpers import assert_object_snapshot_equal, assert_str_snapshot_equal | ||
|
||
|
||
@pytest.fixture | ||
def query_parser( # noqa: D103 | ||
simple_semantic_manifest_lookup: SemanticManifestLookup, | ||
) -> MetricFlowQueryParser: | ||
return MetricFlowQueryParser(semantic_manifest_lookup=simple_semantic_manifest_lookup) | ||
|
||
|
||
@pytest.fixture | ||
def ambiguous_resolution_query_parser( # noqa: D103 | ||
ambiguous_resolution_manifest_lookup: SemanticManifestLookup, | ||
) -> MetricFlowQueryParser: | ||
return MetricFlowQueryParser(semantic_manifest_lookup=ambiguous_resolution_manifest_lookup) | ||
|
||
|
||
def test_simple_metric_with_explicit_time_granularity( # noqa: D | ||
request: FixtureRequest, | ||
mf_test_configuration: MetricFlowTestConfiguration, | ||
query_parser: MetricFlowQueryParser, | ||
) -> None: | ||
query_spec = query_parser.parse_and_validate_query( | ||
metric_names=["largest_listing"], group_by_names=["metric_time"] | ||
).query_spec | ||
|
||
assert_object_snapshot_equal( | ||
request=request, | ||
mf_test_configuration=mf_test_configuration, | ||
obj_id="result_0", | ||
obj=query_spec, | ||
) | ||
|
||
|
||
def test_simple_metric_without_explicit_time_granularity( | ||
request: FixtureRequest, | ||
mf_test_configuration: MetricFlowTestConfiguration, | ||
ambiguous_resolution_query_parser: MetricFlowQueryParser, | ||
) -> None: | ||
"""Tests that a metric without default granularity uses the min granualrity for its agg_time_dim.""" | ||
query_spec = ambiguous_resolution_query_parser.parse_and_validate_query( | ||
metric_names=["monthly_metric_0"], | ||
group_by_names=["metric_time"], | ||
).query_spec | ||
|
||
assert_object_snapshot_equal( | ||
request=request, | ||
mf_test_configuration=mf_test_configuration, | ||
obj_id="result_0", | ||
obj=query_spec, | ||
) | ||
|
||
|
||
def test_derived_metric_with_explicit_time_granularity( | ||
request: FixtureRequest, | ||
mf_test_configuration: MetricFlowTestConfiguration, | ||
ambiguous_resolution_query_parser: MetricFlowQueryParser, | ||
) -> None: | ||
"""Tests that a derived metric with default granularity ignores the default granularities set on its input metrics.""" | ||
query_spec = ambiguous_resolution_query_parser.parse_and_validate_query( | ||
metric_names=["derived_metric_with_time_granularity"], | ||
group_by_names=["metric_time"], | ||
).query_spec | ||
|
||
assert_object_snapshot_equal( | ||
request=request, | ||
mf_test_configuration=mf_test_configuration, | ||
obj_id="result_0", | ||
obj=query_spec, | ||
) | ||
|
||
|
||
def test_derived_metric_without_explicit_time_granularity( | ||
request: FixtureRequest, | ||
mf_test_configuration: MetricFlowTestConfiguration, | ||
ambiguous_resolution_query_parser: MetricFlowQueryParser, | ||
) -> None: | ||
"""Tests a derived metric without explicit default granularity. | ||
Should ignore the default granularities set on its input metrics. | ||
""" | ||
query_spec = ambiguous_resolution_query_parser.parse_and_validate_query( | ||
metric_names=["derived_metric_without_time_granularity"], | ||
group_by_names=["metric_time"], | ||
).query_spec | ||
|
||
assert_object_snapshot_equal( | ||
request=request, | ||
mf_test_configuration=mf_test_configuration, | ||
obj_id="result_0", | ||
obj=query_spec, | ||
) | ||
|
||
|
||
def test_non_metric_time_ignores_default_granularity( # noqa: D | ||
request: FixtureRequest, | ||
mf_test_configuration: MetricFlowTestConfiguration, | ||
query_parser: MetricFlowQueryParser, | ||
) -> None: | ||
query_spec = query_parser.parse_and_validate_query( | ||
metric_names=["largest_listing"], group_by_names=["listing__ds"] | ||
).query_spec | ||
|
||
assert_object_snapshot_equal( | ||
request=request, | ||
mf_test_configuration=mf_test_configuration, | ||
obj_id="result_0", | ||
obj=query_spec, | ||
) |
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
7 changes: 7 additions & 0 deletions
7
...y.py/MetricFlowQuerySpec/test_derived_metric_with_explicit_time_granularity__result_0.txt
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,7 @@ | ||
MetricFlowQuerySpec( | ||
metric_specs=(MetricSpec(element_name='derived_metric_with_time_granularity'),), | ||
time_dimension_specs=(TimeDimensionSpec(element_name='metric_time', time_granularity=YEAR),), | ||
filter_intersection=PydanticWhereFilterIntersection(), | ||
filter_spec_resolution_lookup=FilterSpecResolutionLookUp(), | ||
min_max_only=False, | ||
) |
7 changes: 7 additions & 0 deletions
7
...y/MetricFlowQuerySpec/test_derived_metric_without_explicit_time_granularity__result_0.txt
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,7 @@ | ||
MetricFlowQuerySpec( | ||
metric_specs=(MetricSpec(element_name='derived_metric_without_time_granularity'),), | ||
time_dimension_specs=(TimeDimensionSpec(element_name='metric_time', time_granularity=MONTH),), | ||
filter_intersection=PydanticWhereFilterIntersection(), | ||
filter_spec_resolution_lookup=FilterSpecResolutionLookUp(), | ||
min_max_only=False, | ||
) |
13 changes: 13 additions & 0 deletions
13
...ity.py/MetricFlowQuerySpec/test_non_metric_time_ignores_default_granularity__result_0.txt
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,13 @@ | ||
MetricFlowQuerySpec( | ||
metric_specs=(MetricSpec(element_name='largest_listing'),), | ||
time_dimension_specs=( | ||
TimeDimensionSpec( | ||
element_name='ds', | ||
entity_links=(EntityReference(element_name='listing'),), | ||
time_granularity=DAY, | ||
), | ||
), | ||
filter_intersection=PydanticWhereFilterIntersection(), | ||
filter_spec_resolution_lookup=FilterSpecResolutionLookUp(), | ||
min_max_only=False, | ||
) |
7 changes: 7 additions & 0 deletions
7
...ty.py/MetricFlowQuerySpec/test_simple_metric_with_explicit_time_granularity__result_0.txt
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,7 @@ | ||
MetricFlowQuerySpec( | ||
metric_specs=(MetricSpec(element_name='largest_listing'),), | ||
time_dimension_specs=(TimeDimensionSpec(element_name='metric_time', time_granularity=MONTH),), | ||
filter_intersection=PydanticWhereFilterIntersection(), | ||
filter_spec_resolution_lookup=FilterSpecResolutionLookUp(), | ||
min_max_only=False, | ||
) |
7 changes: 7 additions & 0 deletions
7
...py/MetricFlowQuerySpec/test_simple_metric_without_explicit_time_granularity__result_0.txt
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,7 @@ | ||
MetricFlowQuerySpec( | ||
metric_specs=(MetricSpec(element_name='monthly_metric_0'),), | ||
time_dimension_specs=(TimeDimensionSpec(element_name='metric_time', time_granularity=MONTH),), | ||
filter_intersection=PydanticWhereFilterIntersection(), | ||
filter_spec_resolution_lookup=FilterSpecResolutionLookUp(), | ||
min_max_only=False, | ||
) |