Skip to content

Commit

Permalink
Rendering & check query tests for custom grain with offset metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Oct 18, 2024
1 parent 6a9cdea commit a2d0d59
Show file tree
Hide file tree
Showing 6 changed files with 840 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests_metricflow/integration/test_cases/itest_granularity.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -534,3 +534,21 @@ integration_test:
AND {{ render_date_trunc("b.ds_partitioned", TimeGranularity.DAY) }} = {{ render_date_trunc("u.ds_partitioned", TimeGranularity.DAY) }}
LEFT OUTER JOIN {{ source_schema }}.mf_time_spine ts ON {{ render_date_trunc("u.ds", TimeGranularity.DAY) }} = ts.ds
GROUP BY ts.martian_day
---
integration_test:
name: test_offset_metric_with_custom_granularity_filter_not_in_group_by
description: Test querying a simple metric with a custom grain on a multi-hop dimension
model: SIMPLE_MODEL
metrics: ["bookings_5_day_lag"]
group_bys: ["metric_time__day"]
where_filter: |
{{ render_time_constraint(render_time_dimension_template('metric_time', 'martian_day'), start_time="2020-01-01") }}
check_query: |
SELECT
ts.ds AS metric_time__day
, SUM(1) AS bookings_5_day_lag
FROM {{ source_schema }}.mf_time_spine ts
INNER JOIN {{ source_schema }}.fct_bookings b ON {{ render_date_sub("ts", "ds", 5, TimeGranularity.DAY) }} = {{ render_date_trunc("b.ds", TimeGranularity.DAY) }}
LEFT OUTER JOIN {{ source_schema }}.mf_time_spine ts1 ON ts.ds = ts1.ds
WHERE {{ render_time_constraint("ts1.martian_day", "2020-01-01") }}
GROUP BY ts.ds
50 changes: 50 additions & 0 deletions tests_metricflow/query_rendering/test_custom_granularity.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,53 @@ def test_simple_metric_with_multi_hop_custom_granularity(
dataflow_plan_builder=dataflow_plan_builder,
query_spec=query_spec,
)


@pytest.mark.sql_engine_snapshot
def test_offset_metric_with_custom_granularity( # noqa: D103
request: FixtureRequest,
mf_test_configuration: MetricFlowTestConfiguration,
dataflow_plan_builder: DataflowPlanBuilder,
dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter,
sql_client: SqlClient,
) -> None:
query_spec = MetricFlowQuerySpec(
metric_specs=(MetricSpec("bookings_5_day_lag"),),
time_dimension_specs=(normal_time_dim_with_custom_grain1,),
)

render_and_check(
request=request,
mf_test_configuration=mf_test_configuration,
dataflow_to_sql_converter=dataflow_to_sql_converter,
sql_client=sql_client,
dataflow_plan_builder=dataflow_plan_builder,
query_spec=query_spec,
)


@pytest.mark.sql_engine_snapshot
def test_offset_metric_with_custom_granularity_filter_not_in_group_by( # noqa: D103
request: FixtureRequest,
mf_test_configuration: MetricFlowTestConfiguration,
dataflow_plan_builder: DataflowPlanBuilder,
dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter,
sql_client: SqlClient,
query_parser: MetricFlowQueryParser,
) -> None:
query_spec = query_parser.parse_and_validate_query(
metric_names=("bookings_5_day_lag",),
group_by_names=("metric_time__day",),
where_constraints=[
PydanticWhereFilter(where_sql_template=("{{ TimeDimension('metric_time', 'martian_day') }} = '2020-01-01'"))
],
).query_spec

render_and_check(
request=request,
mf_test_configuration=mf_test_configuration,
dataflow_to_sql_converter=dataflow_to_sql_converter,
sql_client=sql_client,
dataflow_plan_builder=dataflow_plan_builder,
query_spec=query_spec,
)
Loading

0 comments on commit a2d0d59

Please sign in to comment.