Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New test cases for fill_nulls_with #1037

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -704,3 +704,39 @@ metric:
expr: bookings
metrics:
- name: bookings
---
metric:
name: twice_bookings_fill_nulls_with_0_without_time_spine
description: 2x twice_bookings_fill_nulls_with_0_without_time_spine
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: 2x bookings_fill_nulls_with_0_without_time_spine

type: derived
type_params:
expr: 2 * bookings_fill_nulls_with_0_without_time_spine
metrics:
- name: bookings_fill_nulls_with_0_without_time_spine
---
metric:
name: nested_fill_nulls_without_time_spine
description: 2x twice_bookings_fill_nulls_with_0_without_time_spine but then x3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same nit, but this time maybe strike the 2x

type: derived
type_params:
expr: 3 * twice_bookings_fill_nulls_with_0_without_time_spine
metrics:
- name: twice_bookings_fill_nulls_with_0_without_time_spine
---
metric:
name: visit_buy_conversion_rate_7days_fill_nulls_with_0
description: conversion rate on visits-buys on a 7 day window, filling nulls with 0 for both input measures
type: conversion
type_params:
conversion_type_params:
base_measure:
name: visits
fill_nulls_with: 0
join_to_timespine: true
conversion_measure:
name: buys
fill_nulls_with: 0
join_to_timespine: true
window: 7 days
entity: user
calculation: conversion_rate
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,32 @@ def test_conversion_rate_with_constant_properties(
sql_client=sql_client,
node=dataflow_plan.sink_output_nodes[0].parent_node,
)


@pytest.mark.sql_engine_snapshot
def test_conversion_metric_fill_nulls_with_0(
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
dataflow_plan_builder: DataflowPlanBuilder,
dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter,
sql_client: SqlClient,
) -> None:
"""Test conversion metric with constant properties by data flow plan rendering."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's update the docstring here and in the other test cases to indicate any weirdness. Like if this won't fill nulls at every level, we can put that in with a note that this should highlight the relevant changes if/when we alter that behavior.

metric_spec = MetricSpec(element_name="visit_buy_conversion_rate_7days_fill_nulls_with_0")
metric_time_spec = TimeDimensionSpec(
element_name="metric_time", entity_links=(), time_granularity=TimeGranularity.DAY
)
dataflow_plan = dataflow_plan_builder.build_plan(
query_spec=MetricFlowQuerySpec(
metric_specs=(metric_spec,),
time_dimension_specs=(metric_time_spec,),
),
)

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,
)
81 changes: 81 additions & 0 deletions metricflow/test/query_rendering/test_derived_metric_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,3 +620,84 @@ def test_derived_offset_metric_with_agg_time_dim( # noqa: D
sql_client=sql_client,
node=dataflow_plan.sink_output_nodes[0].parent_node,
)


@pytest.mark.sql_engine_snapshot
def test_multi_metric_fill_null( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
dataflow_plan_builder: DataflowPlanBuilder,
dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter,
sql_client: SqlClient,
create_source_tables: bool,
) -> None:
dataflow_plan = dataflow_plan_builder.build_plan(
query_spec=MetricFlowQuerySpec(
metric_specs=(
MetricSpec(element_name="twice_bookings_fill_nulls_with_0_without_time_spine"),
MetricSpec(element_name="listings"),
),
time_dimension_specs=(MTD_SPEC_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_nested_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,
create_source_tables: bool,
) -> None:
dataflow_plan = dataflow_plan_builder.build_plan(
query_spec=MetricFlowQuerySpec(
metric_specs=(MetricSpec(element_name="nested_fill_nulls_without_time_spine"),),
time_dimension_specs=(MTD_SPEC_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_nested_fill_nulls_without_time_spine_multi_metric( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
dataflow_plan_builder: DataflowPlanBuilder,
dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter,
sql_client: SqlClient,
create_source_tables: bool,
) -> None:
dataflow_plan = dataflow_plan_builder.build_plan(
query_spec=MetricFlowQuerySpec(
metric_specs=(
MetricSpec(element_name="nested_fill_nulls_without_time_spine"),
MetricSpec(element_name="listings"),
),
time_dimension_specs=(MTD_SPEC_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,
)
Loading
Loading