diff --git a/tests_metricflow/integration/query_output/test_fill_nulls_with_0.py b/tests_metricflow/integration/query_output/test_fill_nulls_with_0.py index 3847b3d572..3d6401884f 100644 --- a/tests_metricflow/integration/query_output/test_fill_nulls_with_0.py +++ b/tests_metricflow/integration/query_output/test_fill_nulls_with_0.py @@ -7,7 +7,7 @@ from metricflow_semantics.test_helpers.config_helpers import MetricFlowTestConfiguration from metricflow.engine.metricflow_engine import MetricFlowQueryRequest -from metricflow.protocols.sql_client import SqlClient +from metricflow.protocols.sql_client import SqlClient, SqlEngine from tests_metricflow.integration.conftest import IntegrationTestHelpers from tests_metricflow.snapshot_utils import assert_str_snapshot_equal @@ -143,3 +143,130 @@ def test_fill_nulls_with_0_multi_metric_query_with_categorical_dimension( # noq snapshot_str=query_result.result_df.text_format(), sql_engine=sql_client.sql_engine_type, ) + + +@pytest.mark.sql_engine_snapshot +def test_join_to_time_spine_with_filter_not_in_group_by( # noqa: D103 + request: FixtureRequest, + mf_test_configuration: MetricFlowTestConfiguration, + sql_client: SqlClient, + it_helpers: IntegrationTestHelpers, +) -> None: + if sql_client.sql_engine_type is SqlEngine.TRINO: + pytest.skip( + "Trino does not support the syntax used in this where filter, but it can't be made engine-agnostic." + ) + + query_result = it_helpers.mf_engine.query( + MetricFlowQueryRequest.create_with_random_request_id( + metric_names=["bookings_join_to_time_spine_with_tiered_filters"], + group_by_names=["metric_time__day"], + order_by_names=["metric_time__day"], + where_constraints=["{{ TimeDimension('metric_time', 'month') }} = '2020-01-01'"], + ) + ) + assert query_result.result_df is not None, "Unexpected empty result." + + assert_str_snapshot_equal( + request=request, + mf_test_configuration=mf_test_configuration, + snapshot_id="query_output", + snapshot_str=query_result.result_df.text_format(), + sql_engine=sql_client.sql_engine_type, + ) + + +@pytest.mark.sql_engine_snapshot +def test_join_to_time_spine_with_filter_smaller_than_group_by( # noqa: D103 + request: FixtureRequest, + mf_test_configuration: MetricFlowTestConfiguration, + sql_client: SqlClient, + it_helpers: IntegrationTestHelpers, +) -> None: + if sql_client.sql_engine_type is SqlEngine.TRINO: + pytest.skip( + "Trino does not support the syntax used in this where filter, but it can't be made engine-agnostic." + ) + + query_result = it_helpers.mf_engine.query( + MetricFlowQueryRequest.create_with_random_request_id( + metric_names=["archived_users_join_to_time_spine"], + group_by_names=["metric_time__day"], + order_by_names=["metric_time__day"], + where_constraints=[ + "{{ TimeDimension('metric_time', 'hour') }} >= '2020-01-01 00:09:00'", + "{{ TimeDimension('metric_time', 'day') }} = '2020-01-01'", + ], + ) + ) + assert query_result.result_df is not None, "Unexpected empty result." + + assert_str_snapshot_equal( + request=request, + mf_test_configuration=mf_test_configuration, + snapshot_id="query_output", + snapshot_str=query_result.result_df.text_format(), + sql_engine=sql_client.sql_engine_type, + ) + + +@pytest.mark.sql_engine_snapshot +def test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time( # noqa: D103 + request: FixtureRequest, + mf_test_configuration: MetricFlowTestConfiguration, + sql_client: SqlClient, + it_helpers: IntegrationTestHelpers, +) -> None: + if sql_client.sql_engine_type is SqlEngine.TRINO: + pytest.skip( + "Trino does not support the syntax used in this where filter, but it can't be made engine-agnostic." + ) + + query_result = it_helpers.mf_engine.query( + MetricFlowQueryRequest.create_with_random_request_id( + metric_names=["bookings_join_to_time_spine_with_tiered_filters"], + group_by_names=["booking__ds__day"], + order_by_names=["booking__ds__day"], + where_constraints=["{{ TimeDimension('booking__ds', 'month') }} = '2020-01-01'"], + ) + ) + assert query_result.result_df is not None, "Unexpected empty result." + + assert_str_snapshot_equal( + request=request, + mf_test_configuration=mf_test_configuration, + snapshot_id="query_output", + snapshot_str=query_result.result_df.text_format(), + sql_engine=sql_client.sql_engine_type, + ) + + +@pytest.mark.sql_engine_snapshot +def test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time( # noqa: D103 + request: FixtureRequest, + mf_test_configuration: MetricFlowTestConfiguration, + sql_client: SqlClient, + it_helpers: IntegrationTestHelpers, +) -> None: + if sql_client.sql_engine_type is SqlEngine.TRINO: + pytest.skip( + "Trino does not support the syntax used in this where filter, but it can't be made engine-agnostic." + ) + + query_result = it_helpers.mf_engine.query( + MetricFlowQueryRequest.create_with_random_request_id( + metric_names=["bookings_join_to_time_spine_with_tiered_filters"], + group_by_names=["metric_time__day"], + order_by_names=["metric_time__day"], + where_constraints=["{{ TimeDimension('booking__ds', 'month') }} = '2020-01-01'"], + ) + ) + assert query_result.result_df is not None, "Unexpected empty result." + + assert_str_snapshot_equal( + request=request, + mf_test_configuration=mf_test_configuration, + snapshot_id="query_output", + snapshot_str=query_result.result_df.text_format(), + sql_engine=sql_client.sql_engine_type, + ) diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by__query_output.txt new file mode 100644 index 0000000000..81e67fd874 --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by__query_output.txt @@ -0,0 +1,4 @@ +metric_time__day bookings_join_to_time_spine_with_tiered_filters +------------------- ------------------------------------------------- +2020-01-01T00:00:00 None +2020-01-02T00:00:00 9 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__query_output.txt new file mode 100644 index 0000000000..ce17a585db --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time__query_output.txt @@ -0,0 +1,4 @@ +booking__ds__day bookings_join_to_time_spine_with_tiered_filters +------------------- ------------------------------------------------- +2020-01-01T00:00:00 None +2020-01-02T00:00:00 9 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__query_output.txt new file mode 100644 index 0000000000..81e67fd874 --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_time_spine_with_filter_not_in_group_by_using_agg_time_and_metric_time__query_output.txt @@ -0,0 +1,4 @@ +metric_time__day bookings_join_to_time_spine_with_tiered_filters +------------------- ------------------------------------------------- +2020-01-01T00:00:00 None +2020-01-02T00:00:00 9 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_time_spine_with_filter_smaller_than_group_by__query_output.txt b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_time_spine_with_filter_smaller_than_group_by__query_output.txt new file mode 100644 index 0000000000..376133d04d --- /dev/null +++ b/tests_metricflow/snapshots/test_fill_nulls_with_0.py/str/DuckDB/test_join_to_time_spine_with_filter_smaller_than_group_by__query_output.txt @@ -0,0 +1,3 @@ +metric_time__day archived_users_join_to_time_spine +------------------- ----------------------------------- +2020-01-01T00:00:00 12