-
Notifications
You must be signed in to change notification settings - Fork 97
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
Fill nulls for multi-metric queries #850
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4de5d57
Update MetricInstance to take a singular defined_from object instead …
courtneyholcomb 5cd869e
Spelling fix
courtneyholcomb e8e1b17
Fill nulls post-metric join for multi-metric queries
courtneyholcomb 304b730
Changelog
courtneyholcomb 6abdf1c
Add method to get YAML-defined input measures
courtneyholcomb affea74
Add new test case & update source data
courtneyholcomb b8bc8dc
Write output tests for filling nulls
courtneyholcomb aa32059
Update Databricks snapshots
courtneyholcomb 6545bc1
Rename YAML -> config
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
Empty file.
145 changes: 145 additions & 0 deletions
145
metricflow/test/integration/query_output/test_fill_nulls_with_0.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,145 @@ | ||
from __future__ import annotations | ||
|
||
import datetime | ||
|
||
import pytest | ||
from _pytest.fixtures import FixtureRequest | ||
|
||
from metricflow.engine.metricflow_engine import MetricFlowQueryRequest | ||
from metricflow.protocols.sql_client import SqlClient | ||
from metricflow.test.fixtures.setup_fixtures import MetricFlowTestSessionState | ||
from metricflow.test.integration.conftest import IntegrationTestHelpers | ||
from metricflow.test.snapshot_utils import assert_object_snapshot_equal | ||
|
||
|
||
@pytest.mark.sql_engine_snapshot | ||
def test_simple_fill_nulls_with_0_metric_time( # noqa: D | ||
request: FixtureRequest, | ||
mf_test_session_state: MetricFlowTestSessionState, | ||
sql_client: SqlClient, | ||
it_helpers: IntegrationTestHelpers, | ||
) -> None: | ||
query_result = it_helpers.mf_engine.query( | ||
MetricFlowQueryRequest.create_with_random_request_id( | ||
metric_names=["bookings_fill_nulls_with_0"], | ||
group_by_names=["metric_time"], | ||
order_by_names=["metric_time"], | ||
time_constraint_start=datetime.datetime(2019, 11, 27), | ||
time_constraint_end=datetime.datetime(2020, 1, 5), | ||
) | ||
) | ||
assert query_result.result_df is not None, "Unexpected empty result." | ||
|
||
assert_object_snapshot_equal( | ||
request=request, | ||
mf_test_session_state=mf_test_session_state, | ||
obj_id="query_output", | ||
obj=query_result.result_df.to_string(), | ||
sql_client=sql_client, | ||
) | ||
|
||
|
||
@pytest.mark.sql_engine_snapshot | ||
def test_simple_fill_nulls_with_0_month( # noqa: D | ||
request: FixtureRequest, | ||
mf_test_session_state: MetricFlowTestSessionState, | ||
sql_client: SqlClient, | ||
it_helpers: IntegrationTestHelpers, | ||
) -> None: | ||
query_result = it_helpers.mf_engine.query( | ||
MetricFlowQueryRequest.create_with_random_request_id( | ||
metric_names=["bookings_fill_nulls_with_0"], | ||
group_by_names=["metric_time__month"], | ||
order_by_names=["metric_time__month"], | ||
time_constraint_start=datetime.datetime(2019, 1, 1), | ||
time_constraint_end=datetime.datetime(2020, 12, 1), | ||
) | ||
) | ||
assert query_result.result_df is not None, "Unexpected empty result." | ||
|
||
assert_object_snapshot_equal( | ||
request=request, | ||
mf_test_session_state=mf_test_session_state, | ||
obj_id="query_output", | ||
obj=query_result.result_df.to_string(), | ||
sql_client=sql_client, | ||
) | ||
|
||
|
||
@pytest.mark.sql_engine_snapshot | ||
def test_simple_join_to_time_spine( # noqa: D | ||
request: FixtureRequest, | ||
mf_test_session_state: MetricFlowTestSessionState, | ||
sql_client: SqlClient, | ||
it_helpers: IntegrationTestHelpers, | ||
) -> None: | ||
query_result = it_helpers.mf_engine.query( | ||
MetricFlowQueryRequest.create_with_random_request_id( | ||
metric_names=["bookings_join_to_time_spine"], | ||
group_by_names=["metric_time"], | ||
time_constraint_start=datetime.datetime(2019, 11, 27), | ||
time_constraint_end=datetime.datetime(2020, 1, 5), | ||
order_by_names=["metric_time"], | ||
) | ||
) | ||
assert query_result.result_df is not None, "Unexpected empty result." | ||
|
||
assert_object_snapshot_equal( | ||
request=request, | ||
mf_test_session_state=mf_test_session_state, | ||
obj_id="query_output", | ||
obj=query_result.result_df.to_string(), | ||
sql_client=sql_client, | ||
) | ||
|
||
|
||
@pytest.mark.sql_engine_snapshot | ||
def test_fill_nulls_with_0_multi_metric_query( # noqa: D | ||
request: FixtureRequest, | ||
mf_test_session_state: MetricFlowTestSessionState, | ||
sql_client: SqlClient, | ||
it_helpers: IntegrationTestHelpers, | ||
) -> None: | ||
query_result = it_helpers.mf_engine.query( | ||
MetricFlowQueryRequest.create_with_random_request_id( | ||
metric_names=["bookings_fill_nulls_with_0", "views"], | ||
group_by_names=["metric_time"], | ||
order_by_names=["metric_time"], | ||
time_constraint_start=datetime.datetime(2019, 11, 27), | ||
time_constraint_end=datetime.datetime(2020, 1, 5), | ||
) | ||
) | ||
assert query_result.result_df is not None, "Unexpected empty result." | ||
|
||
assert_object_snapshot_equal( | ||
request=request, | ||
mf_test_session_state=mf_test_session_state, | ||
obj_id="query_output", | ||
obj=query_result.result_df.to_string(), | ||
sql_client=sql_client, | ||
) | ||
|
||
|
||
@pytest.mark.sql_engine_snapshot | ||
def test_fill_nulls_with_0_multi_metric_query_with_categorical_dimension( # noqa: D | ||
request: FixtureRequest, | ||
mf_test_session_state: MetricFlowTestSessionState, | ||
sql_client: SqlClient, | ||
it_helpers: IntegrationTestHelpers, | ||
) -> None: | ||
query_result = it_helpers.mf_engine.query( | ||
MetricFlowQueryRequest.create_with_random_request_id( | ||
metric_names=["bookings_fill_nulls_with_0_without_time_spine", "views"], | ||
group_by_names=["metric_time", "listing__is_lux_latest"], | ||
order_by_names=["metric_time", "listing__is_lux_latest"], | ||
) | ||
) | ||
assert query_result.result_df is not None, "Unexpected empty result." | ||
|
||
assert_object_snapshot_equal( | ||
request=request, | ||
mf_test_session_state=mf_test_session_state, | ||
obj_id="query_output", | ||
obj=query_result.result_df.to_string(), | ||
sql_client=sql_client, | ||
) |
41 changes: 41 additions & 0 deletions
41
..._nulls_with_0.py/str/BigQuery/test_fill_nulls_with_0_multi_metric_query__query_output.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,41 @@ | ||
metric_time__day bookings_fill_nulls_with_0 views | ||
0 2019-11-27 0 NaN | ||
1 2019-11-28 0 NaN | ||
2 2019-11-29 0 NaN | ||
3 2019-11-30 0 NaN | ||
4 2019-12-01 1 NaN | ||
5 2019-12-02 0 NaN | ||
6 2019-12-03 0 NaN | ||
7 2019-12-04 0 NaN | ||
8 2019-12-05 0 NaN | ||
9 2019-12-06 0 NaN | ||
10 2019-12-07 0 NaN | ||
11 2019-12-08 0 NaN | ||
12 2019-12-09 0 NaN | ||
13 2019-12-10 0 NaN | ||
14 2019-12-11 0 NaN | ||
15 2019-12-12 0 NaN | ||
16 2019-12-13 0 NaN | ||
17 2019-12-14 0 NaN | ||
18 2019-12-15 0 NaN | ||
19 2019-12-16 0 NaN | ||
20 2019-12-17 0 NaN | ||
21 2019-12-18 10 NaN | ||
22 2019-12-19 18 NaN | ||
23 2019-12-20 2 NaN | ||
24 2019-12-21 0 NaN | ||
25 2019-12-22 0 NaN | ||
26 2019-12-23 0 NaN | ||
27 2019-12-24 0 NaN | ||
28 2019-12-25 0 NaN | ||
29 2019-12-26 0 NaN | ||
30 2019-12-27 0 NaN | ||
31 2019-12-28 0 NaN | ||
32 2019-12-29 0 NaN | ||
33 2019-12-30 0 NaN | ||
34 2019-12-31 0 NaN | ||
35 2020-01-01 5 2.0 | ||
36 2020-01-02 9 5.0 | ||
37 2020-01-03 1 NaN | ||
38 2020-01-04 0 1.0 | ||
39 2020-01-05 0 1.0 |
16 changes: 16 additions & 0 deletions
16
...ry/test_fill_nulls_with_0_multi_metric_query_with_categorical_dimension__query_output.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,16 @@ | ||
metric_time__day listing__is_lux_latest bookings_fill_nulls_with_0_without_time_spine views | ||
0 2019-12-01 True 1 NaN | ||
1 2019-12-18 False 4 NaN | ||
2 2019-12-18 True 6 NaN | ||
3 2019-12-19 None 6 NaN | ||
4 2019-12-19 False 6 NaN | ||
5 2019-12-19 True 6 NaN | ||
6 2019-12-20 True 2 NaN | ||
7 2020-01-01 False 2 NaN | ||
8 2020-01-01 True 3 2.0 | ||
9 2020-01-02 None 3 1.0 | ||
10 2020-01-02 False 3 3.0 | ||
11 2020-01-02 True 3 1.0 | ||
12 2020-01-03 True 1 NaN | ||
13 2020-01-04 False 0 1.0 | ||
14 2020-01-05 None 0 1.0 |
41 changes: 41 additions & 0 deletions
41
..._nulls_with_0.py/str/BigQuery/test_simple_fill_nulls_with_0_metric_time__query_output.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,41 @@ | ||
metric_time__day bookings_fill_nulls_with_0 | ||
0 2019-11-27 0 | ||
1 2019-11-28 0 | ||
2 2019-11-29 0 | ||
3 2019-11-30 0 | ||
4 2019-12-01 1 | ||
5 2019-12-02 0 | ||
6 2019-12-03 0 | ||
7 2019-12-04 0 | ||
8 2019-12-05 0 | ||
9 2019-12-06 0 | ||
10 2019-12-07 0 | ||
11 2019-12-08 0 | ||
12 2019-12-09 0 | ||
13 2019-12-10 0 | ||
14 2019-12-11 0 | ||
15 2019-12-12 0 | ||
16 2019-12-13 0 | ||
17 2019-12-14 0 | ||
18 2019-12-15 0 | ||
19 2019-12-16 0 | ||
20 2019-12-17 0 | ||
21 2019-12-18 10 | ||
22 2019-12-19 18 | ||
23 2019-12-20 2 | ||
24 2019-12-21 0 | ||
25 2019-12-22 0 | ||
26 2019-12-23 0 | ||
27 2019-12-24 0 | ||
28 2019-12-25 0 | ||
29 2019-12-26 0 | ||
30 2019-12-27 0 | ||
31 2019-12-28 0 | ||
32 2019-12-29 0 | ||
33 2019-12-30 0 | ||
34 2019-12-31 0 | ||
35 2020-01-01 5 | ||
36 2020-01-02 9 | ||
37 2020-01-03 1 | ||
38 2020-01-04 0 | ||
39 2020-01-05 0 |
25 changes: 25 additions & 0 deletions
25
...t_fill_nulls_with_0.py/str/BigQuery/test_simple_fill_nulls_with_0_month__query_output.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,25 @@ | ||
metric_time__month bookings_fill_nulls_with_0 | ||
0 2019-01-01 0 | ||
1 2019-02-01 0 | ||
2 2019-03-01 0 | ||
3 2019-04-01 0 | ||
4 2019-05-01 0 | ||
5 2019-06-01 0 | ||
6 2019-07-01 0 | ||
7 2019-08-01 0 | ||
8 2019-09-01 0 | ||
9 2019-10-01 0 | ||
10 2019-11-01 0 | ||
11 2019-12-01 31 | ||
12 2020-01-01 15 | ||
13 2020-02-01 0 | ||
14 2020-03-01 0 | ||
15 2020-04-01 0 | ||
16 2020-05-01 0 | ||
17 2020-06-01 0 | ||
18 2020-07-01 0 | ||
19 2020-08-01 0 | ||
20 2020-09-01 0 | ||
21 2020-10-01 0 | ||
22 2020-11-01 0 | ||
23 2020-12-01 0 |
41 changes: 41 additions & 0 deletions
41
...s/test_fill_nulls_with_0.py/str/BigQuery/test_simple_join_to_time_spine__query_output.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,41 @@ | ||
metric_time__day bookings_join_to_time_spine | ||
0 2019-11-27 NaN | ||
1 2019-11-28 NaN | ||
2 2019-11-29 NaN | ||
3 2019-11-30 NaN | ||
4 2019-12-01 1.0 | ||
5 2019-12-02 NaN | ||
6 2019-12-03 NaN | ||
7 2019-12-04 NaN | ||
8 2019-12-05 NaN | ||
9 2019-12-06 NaN | ||
10 2019-12-07 NaN | ||
11 2019-12-08 NaN | ||
12 2019-12-09 NaN | ||
13 2019-12-10 NaN | ||
14 2019-12-11 NaN | ||
15 2019-12-12 NaN | ||
16 2019-12-13 NaN | ||
17 2019-12-14 NaN | ||
18 2019-12-15 NaN | ||
19 2019-12-16 NaN | ||
20 2019-12-17 NaN | ||
21 2019-12-18 10.0 | ||
22 2019-12-19 18.0 | ||
23 2019-12-20 2.0 | ||
24 2019-12-21 NaN | ||
25 2019-12-22 NaN | ||
26 2019-12-23 NaN | ||
27 2019-12-24 NaN | ||
28 2019-12-25 NaN | ||
29 2019-12-26 NaN | ||
30 2019-12-27 NaN | ||
31 2019-12-28 NaN | ||
32 2019-12-29 NaN | ||
33 2019-12-30 NaN | ||
34 2019-12-31 NaN | ||
35 2020-01-01 5.0 | ||
36 2020-01-02 9.0 | ||
37 2020-01-03 1.0 | ||
38 2020-01-04 NaN | ||
39 2020-01-05 NaN |
41 changes: 41 additions & 0 deletions
41
...ll_nulls_with_0.py/str/DuckDB/test_fill_nulls_with_0_multi_metric_query__query_output.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,41 @@ | ||
metric_time__day bookings_fill_nulls_with_0 views | ||
0 2019-11-27 0 NaN | ||
1 2019-11-28 0 NaN | ||
2 2019-11-29 0 NaN | ||
3 2019-11-30 0 NaN | ||
4 2019-12-01 1 NaN | ||
5 2019-12-02 0 NaN | ||
6 2019-12-03 0 NaN | ||
7 2019-12-04 0 NaN | ||
8 2019-12-05 0 NaN | ||
9 2019-12-06 0 NaN | ||
10 2019-12-07 0 NaN | ||
11 2019-12-08 0 NaN | ||
12 2019-12-09 0 NaN | ||
13 2019-12-10 0 NaN | ||
14 2019-12-11 0 NaN | ||
15 2019-12-12 0 NaN | ||
16 2019-12-13 0 NaN | ||
17 2019-12-14 0 NaN | ||
18 2019-12-15 0 NaN | ||
19 2019-12-16 0 NaN | ||
20 2019-12-17 0 NaN | ||
21 2019-12-18 10 NaN | ||
22 2019-12-19 18 NaN | ||
23 2019-12-20 2 NaN | ||
24 2019-12-21 0 NaN | ||
25 2019-12-22 0 NaN | ||
26 2019-12-23 0 NaN | ||
27 2019-12-24 0 NaN | ||
28 2019-12-25 0 NaN | ||
29 2019-12-26 0 NaN | ||
30 2019-12-27 0 NaN | ||
31 2019-12-28 0 NaN | ||
32 2019-12-29 0 NaN | ||
33 2019-12-30 0 NaN | ||
34 2019-12-31 0 NaN | ||
35 2020-01-01 5 2.0 | ||
36 2020-01-02 9 5.0 | ||
37 2020-01-03 1 NaN | ||
38 2020-01-04 0 1.0 | ||
39 2020-01-05 0 1.0 |
16 changes: 16 additions & 0 deletions
16
...DB/test_fill_nulls_with_0_multi_metric_query_with_categorical_dimension__query_output.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,16 @@ | ||
metric_time__day listing__is_lux_latest bookings_fill_nulls_with_0_without_time_spine views | ||
0 2019-12-01 True 1 NaN | ||
1 2019-12-18 False 4 NaN | ||
2 2019-12-18 True 6 NaN | ||
3 2019-12-19 False 6 NaN | ||
4 2019-12-19 True 6 NaN | ||
5 2019-12-19 None 6 NaN | ||
6 2019-12-20 True 2 NaN | ||
7 2020-01-01 False 2 NaN | ||
8 2020-01-01 True 3 2.0 | ||
9 2020-01-02 False 3 3.0 | ||
10 2020-01-02 True 3 1.0 | ||
11 2020-01-02 None 3 1.0 | ||
12 2020-01-03 True 1 NaN | ||
13 2020-01-04 False 0 1.0 | ||
14 2020-01-05 None 0 1.0 |
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.
These snapshot tests are great, thanks for doing this!