Skip to content

Commit

Permalink
Add new query output tests
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Oct 15, 2024
1 parent e50b64d commit 900d5d4
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -143,3 +143,68 @@ 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,
)
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
metric_time__day archived_users_join_to_time_spine
------------------- -----------------------------------
2020-01-01T00:00:00 12

0 comments on commit 900d5d4

Please sign in to comment.