-
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.
Merge pull request #840 from dbt-labs/11-02-Move_time_spine_and_fill_…
…nulls_rendering_tests Move time spine and fill nulls rendering tests to separate module
- Loading branch information
Showing
107 changed files
with
238 additions
and
8,507 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
190 changes: 190 additions & 0 deletions
190
metricflow/test/query_rendering/test_fill_nulls_with_rendering.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,190 @@ | ||
"""Tests query rendering for coalescing null measures by comparing rendered output against snapshot files.""" | ||
from __future__ import annotations | ||
|
||
import pytest | ||
from _pytest.fixtures import FixtureRequest | ||
from dbt_semantic_interfaces.references import EntityReference | ||
from dbt_semantic_interfaces.type_enums.time_granularity import TimeGranularity | ||
|
||
from metricflow.dataflow.builder.dataflow_plan_builder import DataflowPlanBuilder | ||
from metricflow.dataset.dataset import DataSet | ||
from metricflow.plan_conversion.dataflow_to_sql import DataflowToSqlQueryPlanConverter | ||
from metricflow.protocols.sql_client import SqlClient | ||
from metricflow.specs.specs import ( | ||
DimensionSpec, | ||
MetricFlowQuerySpec, | ||
MetricSpec, | ||
TimeDimensionSpec, | ||
) | ||
from metricflow.test.fixtures.setup_fixtures import MetricFlowTestSessionState | ||
from metricflow.test.query_rendering.compare_rendered_query import convert_and_check | ||
|
||
|
||
@pytest.mark.sql_engine_snapshot | ||
def test_simple_fill_nulls_with_0_metric_time( # noqa: D | ||
request: FixtureRequest, | ||
mf_test_session_state: MetricFlowTestSessionState, | ||
dataflow_plan_builder: DataflowPlanBuilder, | ||
dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter, | ||
sql_client: SqlClient, | ||
) -> None: | ||
dataflow_plan = dataflow_plan_builder.build_plan( | ||
MetricFlowQuerySpec( | ||
metric_specs=(MetricSpec(element_name="bookings_fill_nulls_with_0"),), | ||
time_dimension_specs=(DataSet.metric_time_dimension_spec(time_granularity=TimeGranularity.DAY),), | ||
) | ||
) | ||
|
||
convert_and_check( | ||
request=request, | ||
mf_test_session_state=mf_test_session_state, | ||
dataflow_to_sql_converter=dataflow_to_sql_converter, | ||
sql_client=sql_client, | ||
node=dataflow_plan.sink_output_nodes[0].parent_node, | ||
) | ||
|
||
|
||
@pytest.mark.sql_engine_snapshot | ||
def test_simple_fill_nulls_with_0_month( # noqa: D | ||
request: FixtureRequest, | ||
mf_test_session_state: MetricFlowTestSessionState, | ||
dataflow_plan_builder: DataflowPlanBuilder, | ||
dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter, | ||
sql_client: SqlClient, | ||
) -> None: | ||
dataflow_plan = dataflow_plan_builder.build_plan( | ||
MetricFlowQuerySpec( | ||
metric_specs=(MetricSpec(element_name="bookings_fill_nulls_with_0"),), | ||
time_dimension_specs=(DataSet.metric_time_dimension_spec(time_granularity=TimeGranularity.MONTH),), | ||
) | ||
) | ||
|
||
convert_and_check( | ||
request=request, | ||
mf_test_session_state=mf_test_session_state, | ||
dataflow_to_sql_converter=dataflow_to_sql_converter, | ||
sql_client=sql_client, | ||
node=dataflow_plan.sink_output_nodes[0].parent_node, | ||
) | ||
|
||
|
||
@pytest.mark.sql_engine_snapshot | ||
def test_simple_fill_nulls_with_0_with_non_metric_time( # noqa: D | ||
request: FixtureRequest, | ||
mf_test_session_state: MetricFlowTestSessionState, | ||
dataflow_plan_builder: DataflowPlanBuilder, | ||
dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter, | ||
sql_client: SqlClient, | ||
) -> None: | ||
dataflow_plan = dataflow_plan_builder.build_plan( | ||
MetricFlowQuerySpec( | ||
metric_specs=(MetricSpec(element_name="bookings_fill_nulls_with_0"),), | ||
time_dimension_specs=( | ||
TimeDimensionSpec(element_name="paid_at", entity_links=(EntityReference("booking"),)), | ||
), | ||
) | ||
) | ||
|
||
convert_and_check( | ||
request=request, | ||
mf_test_session_state=mf_test_session_state, | ||
dataflow_to_sql_converter=dataflow_to_sql_converter, | ||
sql_client=sql_client, | ||
node=dataflow_plan.sink_output_nodes[0].parent_node, | ||
) | ||
|
||
|
||
@pytest.mark.sql_engine_snapshot | ||
def test_simple_fill_nulls_with_0_with_categorical_dimension( # noqa: D | ||
request: FixtureRequest, | ||
mf_test_session_state: MetricFlowTestSessionState, | ||
dataflow_plan_builder: DataflowPlanBuilder, | ||
dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter, | ||
sql_client: SqlClient, | ||
) -> None: | ||
dataflow_plan = dataflow_plan_builder.build_plan( | ||
MetricFlowQuerySpec( | ||
metric_specs=(MetricSpec(element_name="bookings_fill_nulls_with_0"),), | ||
dimension_specs=(DimensionSpec(element_name="is_instant", entity_links=(EntityReference("booking"),)),), | ||
) | ||
) | ||
|
||
convert_and_check( | ||
request=request, | ||
mf_test_session_state=mf_test_session_state, | ||
dataflow_to_sql_converter=dataflow_to_sql_converter, | ||
sql_client=sql_client, | ||
node=dataflow_plan.sink_output_nodes[0].parent_node, | ||
) | ||
|
||
|
||
@pytest.mark.sql_engine_snapshot | ||
def test_simple_fill_nulls_without_time_spine( # noqa: D | ||
request: FixtureRequest, | ||
mf_test_session_state: MetricFlowTestSessionState, | ||
dataflow_plan_builder: DataflowPlanBuilder, | ||
dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter, | ||
sql_client: SqlClient, | ||
) -> None: | ||
dataflow_plan = dataflow_plan_builder.build_plan( | ||
MetricFlowQuerySpec( | ||
metric_specs=(MetricSpec(element_name="bookings_fill_nulls_with_0_without_time_spine"),), | ||
time_dimension_specs=(DataSet.metric_time_dimension_spec(time_granularity=TimeGranularity.DAY),), | ||
) | ||
) | ||
|
||
convert_and_check( | ||
request=request, | ||
mf_test_session_state=mf_test_session_state, | ||
dataflow_to_sql_converter=dataflow_to_sql_converter, | ||
sql_client=sql_client, | ||
node=dataflow_plan.sink_output_nodes[0].parent_node, | ||
) | ||
|
||
|
||
@pytest.mark.sql_engine_snapshot | ||
def test_cumulative_fill_nulls( # noqa: D | ||
request: FixtureRequest, | ||
mf_test_session_state: MetricFlowTestSessionState, | ||
dataflow_plan_builder: DataflowPlanBuilder, | ||
dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter, | ||
sql_client: SqlClient, | ||
) -> None: | ||
dataflow_plan = dataflow_plan_builder.build_plan( | ||
MetricFlowQuerySpec( | ||
metric_specs=(MetricSpec(element_name="every_two_days_bookers_fill_nulls_with_0"),), | ||
time_dimension_specs=(DataSet.metric_time_dimension_spec(time_granularity=TimeGranularity.DAY),), | ||
) | ||
) | ||
|
||
convert_and_check( | ||
request=request, | ||
mf_test_session_state=mf_test_session_state, | ||
dataflow_to_sql_converter=dataflow_to_sql_converter, | ||
sql_client=sql_client, | ||
node=dataflow_plan.sink_output_nodes[0].parent_node, | ||
) | ||
|
||
|
||
@pytest.mark.sql_engine_snapshot | ||
def test_derived_fill_nulls_for_one_input_metric( # noqa: D | ||
request: FixtureRequest, | ||
mf_test_session_state: MetricFlowTestSessionState, | ||
dataflow_plan_builder: DataflowPlanBuilder, | ||
dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter, | ||
sql_client: SqlClient, | ||
) -> None: | ||
dataflow_plan = dataflow_plan_builder.build_plan( | ||
MetricFlowQuerySpec( | ||
metric_specs=(MetricSpec(element_name="bookings_growth_2_weeks_fill_nulls_with_0_for_non_offset"),), | ||
time_dimension_specs=(DataSet.metric_time_dimension_spec(time_granularity=TimeGranularity.DAY),), | ||
) | ||
) | ||
|
||
convert_and_check( | ||
request=request, | ||
mf_test_session_state=mf_test_session_state, | ||
dataflow_to_sql_converter=dataflow_to_sql_converter, | ||
sql_client=sql_client, | ||
node=dataflow_plan.sink_output_nodes[0].parent_node, | ||
) |
Oops, something went wrong.