Skip to content

Commit

Permalink
Rendering & check query tests for custom grain with multi-hop join
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Oct 18, 2024
1 parent 29e2a10 commit e54a788
Show file tree
Hide file tree
Showing 4 changed files with 1,408 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 @@ -516,3 +516,21 @@ integration_test:
ON {{ render_date_trunc("l.created_at", TimeGranularity.DAY) }} = ts.ds
WHERE {{ render_time_constraint("ts.martian_day", start_time="2019-12-20") }}
GROUP BY ts.martian_day
---
integration_test:
name: test_simple_metric_with_multi_hop_custom_granularity
description: Test querying a simple metric with a custom grain on a multi-hop dimension
model: SIMPLE_MODEL
metrics: ["bookings"]
group_bys: ["listing__user__ds__martian_day"]
check_query: |
SELECT
ts.martian_day AS listing__user__ds__martian_day
, SUM(1) AS bookings
FROM {{ source_schema }}.fct_bookings b
LEFT OUTER JOIN {{ source_schema }}.dim_listings_latest l
LEFT OUTER JOIN {{ source_schema }}.dim_users u ON l.user_id = u.user_id
ON b.listing_id = l.listing_id
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
25 changes: 25 additions & 0 deletions tests_metricflow/query_rendering/test_custom_granularity.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,28 @@ def test_no_metrics_with_custom_granularity_in_filter_and_group_by(
dataflow_plan_builder=dataflow_plan_builder,
query_spec=query_spec,
)


@pytest.mark.sql_engine_snapshot
def test_simple_metric_with_multi_hop_custom_granularity(
request: FixtureRequest,
mf_test_configuration: MetricFlowTestConfiguration,
dataflow_plan_builder: DataflowPlanBuilder,
dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter,
sql_client: SqlClient,
query_parser: MetricFlowQueryParser,
) -> None:
"""Test simple metric with a multi hop dimension and custom grain."""
query_spec = query_parser.parse_and_validate_query(
metric_names=("bookings",),
group_by_names=("listing__user__ds__martian_day",),
).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 e54a788

Please sign in to comment.