-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tests for Metric.time_granularity
#1325
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b72eb7e
Clean up outdated comments
courtneyholcomb 5d1e722
Add query parser tests
courtneyholcomb 8dbf00b
Add test metrics with default_granularity and adjust expected test re…
courtneyholcomb a2ddebb
Update engine snapshots
courtneyholcomb 4c7b6f2
Use new YAML field name + skip broken test
courtneyholcomb ec2a052
Move query_parser tests & add snapshots
courtneyholcomb 6d8a635
Remove unneeded metrics from query parsing tests
courtneyholcomb 2904939
Rename test metric + update snapshots
courtneyholcomb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
116 changes: 116 additions & 0 deletions
116
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,116 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
from _pytest.fixtures import FixtureRequest | ||
from metricflow_semantics.model.semantic_manifest_lookup import SemanticManifestLookup | ||
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 | ||
|
||
|
||
@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: D103 | ||
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: D103 | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,10 @@ | |
expr: "1" | ||
agg: sum | ||
create_metric: true | ||
- name: monthly_bookings | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be removed now? |
||
expr: "1" | ||
agg: sum | ||
agg_time_dimension: ds_month | ||
|
||
dimensions: | ||
- name: is_instant | ||
|
@@ -59,13 +63,43 @@ | |
type: time | ||
type_params: | ||
time_granularity: day | ||
- name: ds_month | ||
type: time | ||
type_params: | ||
time_granularity: month | ||
|
||
primary_entity: booking | ||
|
||
entities: | ||
- name: listing | ||
type: foreign | ||
expr: listing_id | ||
|
||
--- | ||
metric: | ||
name: instant_bookings | ||
description: instant bookings | ||
type: simple | ||
type_params: | ||
measure: bookings | ||
filter: "{{ Dimension('booking__is_instant') }}" | ||
--- | ||
metric: | ||
name: month_bookings | ||
description: monthly bookings | ||
type: simple | ||
type_params: | ||
measure: monthly_bookings | ||
--- | ||
metric: | ||
name: instant_plus_months_bookings | ||
description: instant plus month bookings | ||
type: derived | ||
type_params: | ||
expr: instant_bookings + month_bookings | ||
metrics: | ||
- name: instant_bookings | ||
- name: month_bookings | ||
""" | ||
) | ||
|
||
|
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, | ||
) |
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
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More like
...with_default_time_granularity
?