-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
21f738b
commit 94e03dd
Showing
9 changed files
with
1,626 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
tests_metricflow/integration/query_output/test_query_output.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,63 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
from _pytest.fixtures import FixtureRequest | ||
from metricflow_semantics.specs.query_param_implementations import MetricParameter | ||
from metricflow_semantics.test_helpers.config_helpers import MetricFlowTestConfiguration | ||
|
||
from metricflow.engine.metricflow_engine import MetricFlowQueryRequest | ||
from metricflow.protocols.sql_client import SqlClient | ||
from tests_metricflow.integration.conftest import IntegrationTestHelpers | ||
from tests_metricflow.snapshot_utils import assert_str_snapshot_equal | ||
|
||
|
||
@pytest.mark.sql_engine_snapshot | ||
def test_metric_alias( # noqa: D103 | ||
request: FixtureRequest, | ||
mf_test_configuration: MetricFlowTestConfiguration, | ||
sql_client: SqlClient, | ||
it_helpers: IntegrationTestHelpers, | ||
) -> None: | ||
query_result = it_helpers.mf_engine.query( | ||
MetricFlowQueryRequest.create_with_random_request_id( | ||
metrics=(MetricParameter(name="bookings", alias="bookings_alias"),), | ||
group_by_names=["metric_time__day"], | ||
order_by_names=["metric_time__day"], | ||
where_constraints=("{{ Metric('bookings', ['listing']) }} > 2",), | ||
) | ||
) | ||
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_derived_metric_alias( # noqa: D103 | ||
request: FixtureRequest, | ||
mf_test_configuration: MetricFlowTestConfiguration, | ||
sql_client: SqlClient, | ||
it_helpers: IntegrationTestHelpers, | ||
) -> None: | ||
query_result = it_helpers.mf_engine.query( | ||
MetricFlowQueryRequest.create_with_random_request_id( | ||
metrics=(MetricParameter(name="booking_fees", alias="bookings_alias"),), | ||
group_by_names=["metric_time__day"], | ||
order_by_names=["metric_time__day"], | ||
where_constraints=("{{ Metric('bookings', ['listing']) }} > 2",), | ||
) | ||
) | ||
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, | ||
) |
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
10 changes: 10 additions & 0 deletions
10
.../snapshots/test_engine_specific_rendering.py/SqlPlan/DuckDB/test_add_time_expr__plan0.sql
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,10 @@ | ||
test_name: test_add_time_expr | ||
test_filename: test_engine_specific_rendering.py | ||
docstring: | ||
Tests rendering of the SqlAddTimeExpr in a query. | ||
sql_engine: DuckDB | ||
--- | ||
-- Test Add Time Expression | ||
SELECT | ||
'2020-01-01' + INTERVAL (1 * 3) month AS add_time | ||
FROM foo.bar a |
12 changes: 12 additions & 0 deletions
12
...low/snapshots/test_query_output.py/str/DuckDB/test_derived_metric_alias__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,12 @@ | ||
test_name: test_derived_metric_alias | ||
test_filename: test_query_output.py | ||
--- | ||
bookings_alias metric_time__day | ||
---------------- ------------------- | ||
47.56 2019-12-01T00:00:00 | ||
284.93 2019-12-18T00:00:00 | ||
360.5 2019-12-19T00:00:00 | ||
0 2019-12-20T00:00:00 | ||
136.16 2020-01-01T00:00:00 | ||
132.78 2020-01-02T00:00:00 | ||
0 2020-01-03T00:00:00 |
12 changes: 12 additions & 0 deletions
12
..._metricflow/snapshots/test_query_output.py/str/DuckDB/test_metric_alias__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,12 @@ | ||
test_name: test_metric_alias | ||
test_filename: test_query_output.py | ||
--- | ||
bookings_alias metric_time__day | ||
---------------- ------------------- | ||
1 2019-12-01T00:00:00 | ||
10 2019-12-18T00:00:00 | ||
18 2019-12-19T00:00:00 | ||
2 2019-12-20T00:00:00 | ||
5 2020-01-01T00:00:00 | ||
9 2020-01-02T00:00:00 | ||
1 2020-01-03T00:00:00 |
Oops, something went wrong.