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 fe83362
Show file tree
Hide file tree
Showing 4 changed files with 1,413 additions and 26 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
56 changes: 30 additions & 26 deletions tests_metricflow/integration/test_configured_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ def filter_not_supported_features(

@pytest.mark.parametrize(
"name",
CONFIGURED_INTEGRATION_TESTS_REPOSITORY.all_test_case_names,
# CONFIGURED_INTEGRATION_TESTS_REPOSITORY.all_test_case_names,
["itest_granularity.yaml/test_simple_metric_with_multi_hop_custom_granularity"],
ids=lambda name: f"name={name}",
)
def test_case(
Expand Down Expand Up @@ -280,37 +281,40 @@ def test_case(
limit=case.limit,
time_constraint_start=parser.parse(case.time_constraint[0]) if case.time_constraint else None,
time_constraint_end=parser.parse(case.time_constraint[1]) if case.time_constraint else None,
where_constraints=[
jinja2.Template(
case.where_filter,
undefined=jinja2.StrictUndefined,
).render(
source_schema=mf_test_configuration.mf_source_schema,
render_time_constraint=check_query_helpers.render_time_constraint,
TimeGranularity=TimeGranularity,
DatePart=DatePart,
render_date_sub=check_query_helpers.render_date_sub,
render_date_trunc=check_query_helpers.render_date_trunc,
render_extract=check_query_helpers.render_extract,
render_percentile_expr=check_query_helpers.render_percentile_expr,
mf_time_spine_source=time_spine_source.spine_table.sql,
double_data_type_name=check_query_helpers.double_data_type_name,
render_dimension_template=check_query_helpers.render_dimension_template,
render_entity_template=check_query_helpers.render_entity_template,
render_metric_template=check_query_helpers.render_metric_template,
render_time_dimension_template=check_query_helpers.render_time_dimension_template,
generate_random_uuid=check_query_helpers.generate_random_uuid,
cast_to_ts=check_query_helpers.cast_to_ts,
)
]
if case.where_filter
else None,
where_constraints=(
[
jinja2.Template(
case.where_filter,
undefined=jinja2.StrictUndefined,
).render(
source_schema=mf_test_configuration.mf_source_schema,
render_time_constraint=check_query_helpers.render_time_constraint,
TimeGranularity=TimeGranularity,
DatePart=DatePart,
render_date_sub=check_query_helpers.render_date_sub,
render_date_trunc=check_query_helpers.render_date_trunc,
render_extract=check_query_helpers.render_extract,
render_percentile_expr=check_query_helpers.render_percentile_expr,
mf_time_spine_source=time_spine_source.spine_table.sql,
double_data_type_name=check_query_helpers.double_data_type_name,
render_dimension_template=check_query_helpers.render_dimension_template,
render_entity_template=check_query_helpers.render_entity_template,
render_metric_template=check_query_helpers.render_metric_template,
render_time_dimension_template=check_query_helpers.render_time_dimension_template,
generate_random_uuid=check_query_helpers.generate_random_uuid,
cast_to_ts=check_query_helpers.cast_to_ts,
)
]
if case.where_filter
else None
),
order_by_names=case.order_bys,
min_max_only=case.min_max_only,
)
)

actual = query_result.result_df
# assert 0, query_result.sql

expected = sql_client.query(
jinja2.Template(
Expand Down
Loading

0 comments on commit fe83362

Please sign in to comment.