Skip to content

Commit

Permalink
Add check query tests
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed May 21, 2024
1 parent 630a6a7 commit ad98912
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions tests_metricflow/integration/test_cases/itest_metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2131,3 +2131,82 @@ integration_test:
) metric_subquery
ON t.customer_third_hop_id = metric_subquery.customer_third_hop_id
WHERE txn_count > 0
---
integration_test:
name: simple_join_to_time_spine_with_filter
description: Test a simple metric that joins to time spine, but doesn't fill nulls, filtered by a dimension that's not in the group by. Should apply constraint only once.
model: SIMPLE_MODEL
metrics: ["bookings_join_to_time_spine"]
group_by_objs: [{"name": "metric_time"}]
where_filter: "{{ render_dimension_template('booking__is_instant') }}"
check_query: |
SELECT
b.ds AS metric_time__day
, a.bookings AS bookings_join_to_time_spine
FROM {{ source_schema }}.mf_time_spine b
LEFT JOIN (
SELECT
{{ render_date_trunc("ds", TimeGranularity.DAY) }} AS ds
, SUM(1) AS bookings
FROM {{ source_schema }}.fct_bookings
WHERE is_instant
GROUP BY {{ render_date_trunc("ds", TimeGranularity.DAY) }}
) a ON b.ds = a.ds
---
integration_test:
name: simple_join_to_time_spine_with_queried_filter
description: Test a simple metric that joins to time spine, but doesn't fill nulls, filtered by a dimension that is in the group by. Should apply constraint twice.
model: SIMPLE_MODEL
metrics: ["bookings_join_to_time_spine"]
group_by_objs: [{"name": "metric_time"}, {"name": "booking__is_instant"}]
where_filter: "{{ render_dimension_template('booking__is_instant') }}"
check_query: |
SELECT
b.ds AS metric_time__day
, a.is_instant AS booking__is_instant
, a.bookings AS bookings_join_to_time_spine
FROM {{ source_schema }}.mf_time_spine b
LEFT JOIN (
SELECT
{{ render_date_trunc("ds", TimeGranularity.DAY) }} AS ds
, is_instant
, SUM(1) AS bookings
FROM {{ source_schema }}.fct_bookings
WHERE is_instant
GROUP BY {{ render_date_trunc("ds", TimeGranularity.DAY) }}, is_instant
) a ON b.ds = a.ds
WHERE is_instant
---
integration_test:
name: join_to_time_spine_with_time_constraint
description: Test join to time spine with time constraint that isn't in group by. Should skip both time spine join and second constraint.
model: SIMPLE_MODEL
metrics: ["bookings_join_to_time_spine"]
time_constraint: ["2020-01-03", "2020-01-03"]
check_query: |
SELECT
SUM(1) AS bookings_join_to_time_spine
FROM {{ source_schema }}.fct_bookings
WHERE {{ render_between_time_constraint("ds", "2020-01-03", "2020-01-03") }}
---
integration_test:
name: join_to_time_spine_with_queried_time_constraint
description: Test join to time spine with time constraint that isn't in group by. Should apply constraint twice.
model: SIMPLE_MODEL
metrics: ["bookings_join_to_time_spine"]
group_by_objs: [{"name": "metric_time"}]
time_constraint: ["2020-01-03", "2020-01-03"]
check_query: |
SELECT
b.ds AS metric_time__day
, a.bookings AS bookings_join_to_time_spine
FROM {{ source_schema }}.mf_time_spine b
LEFT JOIN (
SELECT
{{ render_date_trunc("ds", TimeGranularity.DAY) }} AS ds
, SUM(1) AS bookings
FROM {{ source_schema }}.fct_bookings
WHERE {{ render_between_time_constraint("ds", "2020-01-03", "2020-01-03") }}
GROUP BY {{ render_date_trunc("ds", TimeGranularity.DAY) }}
) a ON b.ds = a.ds
WHERE {{ render_between_time_constraint("b.ds", "2020-01-03", "2020-01-03") }}

0 comments on commit ad98912

Please sign in to comment.