-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fill nulls for multi-metric queries (#850)
- Loading branch information
1 parent
9db0fe0
commit dc076a1
Showing
51 changed files
with
1,359 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Features | ||
body: Fill nulls for multi-metric queries | ||
time: 2023-11-06T15:00:14.37926-08:00 | ||
custom: | ||
Author: courtneyholcomb | ||
Issue: "850" |
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
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, | ||
) |
Oops, something went wrong.