Skip to content

Commit

Permalink
fill_nulls_with behavior for multi-metric and derived.
Browse files Browse the repository at this point in the history
  • Loading branch information
plypaul committed Nov 16, 2023
1 parent 863352b commit ed9e57b
Show file tree
Hide file tree
Showing 6 changed files with 1,912 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -578,3 +578,13 @@ metric:
- name: bookings
offset_window: 14 days
alias: bookings_2_weeks_ago

---
metric:
name: twice_bookings_fill_nulls_with_0_without_time_spine
description: 2x twice_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
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ table_snapshot:
- ["2020-01-02", "l9658588-incomplete", "us", null, null, "u1004114"]
- ["2020-01-02", "l8912456-incomplete", null, null, null, "u1004114"]
- ["2020-01-02", "l7891283-incomplete", "ca", null, "False", "u1004114"]
- ["2020-01-04", "l7891283-incomplete", "ca", null, "False", "u1004114"]
37 changes: 37 additions & 0 deletions metricflow/test/plan_conversion/test_dataflow_to_sql_plan.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import logging
from typing import List

import pytest
Expand Down Expand Up @@ -112,6 +113,11 @@ def convert_and_check(
sql_client=sql_client,
)

rendered_sql = sql_client.sql_query_plan_renderer.render_sql_query_plan(sql_query_plan).sql
sql_result = sql_client.query(stmt=rendered_sql)

logger.error(f"SQL Result is:\n{sql_result.to_string(max_cols=200)}")


@pytest.mark.sql_engine_snapshot
def test_source_node( # noqa: D
Expand Down Expand Up @@ -1035,3 +1041,34 @@ def test_dimensions_requiring_join(
sql_client=sql_client,
node=dataflow_plan.sink_output_nodes[0].parent_node,
)


logger = logging.getLogger(__name__)


@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,
)
Loading

0 comments on commit ed9e57b

Please sign in to comment.