Skip to content

Commit

Permalink
Add test metrics with default_granularity and adjust expected test re…
Browse files Browse the repository at this point in the history
…sults
  • Loading branch information
courtneyholcomb committed Jul 11, 2024
1 parent ad22365 commit 5b7b886
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ metric:
type: simple
type_params:
measure: largest_listing
default_granularity: month
---
metric:
name: "identity_verifications"
Expand Down Expand Up @@ -626,6 +627,7 @@ metric:
name: bookings
join_to_timespine: true
fill_nulls_with: 0
default_granularity: week
---
metric:
name: every_two_days_bookers_fill_nulls_with_0
Expand Down Expand Up @@ -780,3 +782,4 @@ metric:
denominator:
name: listings
filter: "{{ Metric('views', ['listing']) }} > 10"
default_granularity: week
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ integration_test:
---
integration_test:
name: daily_metric_with_monthly_time_dimension
description: Query a metric with a month-granularity time dimensions.
description: Query a metric with a month-granularity time dimensions. Filter should expand to requested granularity.
model: EXTENDED_DATE_MODEL
metrics: ["bookings"]
group_bys: ["metric_time__month"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ integration_test:
check_query: |
SELECT
MAX(capacity) as largest_listing
, created_at AS metric_time__day
, {{ render_date_trunc("created_at", TimeGranularity.MONTH) }} AS metric_time__month
FROM {{ source_schema }}.dim_listings_latest
GROUP BY
2
Expand Down
31 changes: 18 additions & 13 deletions tests_metricflow/integration/test_cases/itest_metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1143,17 +1143,22 @@ integration_test:
group_by_objs: [{"name": "metric_time"}]
check_query: |
SELECT
subq_5.ds AS metric_time__day
subq_4.metric_time__week
, COALESCE(subq_3.bookings, 0) AS bookings_fill_nulls_with_0
FROM {{ source_schema }}.mf_time_spine subq_5
FROM (
SELECT
{{ render_date_trunc("ds", TimeGranularity.WEEK) }} AS metric_time__week
FROM {{ source_schema }}.mf_time_spine subq_5
GROUP BY {{ render_date_trunc("ds", TimeGranularity.WEEK) }}
) subq_4
LEFT OUTER JOIN (
SELECT
{{ render_date_trunc("ds", TimeGranularity.DAY) }} AS metric_time__day
{{ render_date_trunc("ds", TimeGranularity.WEEK) }} AS metric_time__week
, SUM(1) AS bookings
FROM {{ source_schema }}.fct_bookings bookings_source_src_1
GROUP BY 1
FROM {{ source_schema }}.fct_bookings
GROUP BY {{ render_date_trunc("ds", TimeGranularity.WEEK) }}
) subq_3
ON subq_5.ds = subq_3.metric_time__day
ON subq_4.metric_time__week = subq_3.metric_time__week
---
integration_test:
name: simple_fill_nulls_with_0_month
Expand Down Expand Up @@ -1343,32 +1348,32 @@ integration_test:
group_by_objs: [{"name": "metric_time"}]
check_query: |
SELECT
COALESCE(subq_7.metric_time__day, subq_12.metric_time__day) AS metric_time__day
COALESCE(subq_7.metric_time__week, subq_12.metric_time__week) AS metric_time__week
, COALESCE(MAX(subq_7.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0
, MAX(subq_12.views) AS views
FROM (
SELECT
subq_5.ds AS metric_time__day
{{ render_date_trunc("subq_5.ds", TimeGranularity.WEEK) }} AS metric_time__week
, COALESCE(subq_3.bookings, 0) AS bookings_fill_nulls_with_0
FROM {{ source_schema }}.mf_time_spine subq_5
LEFT OUTER JOIN (
SELECT
{{ render_date_trunc("ds", TimeGranularity.DAY) }} AS metric_time__day
{{ render_date_trunc("ds", TimeGranularity.WEEK) }} AS metric_time__week
, SUM(1) AS bookings
FROM {{ source_schema }}.fct_bookings bookings_source_src_1
GROUP BY 1
) subq_3
ON subq_5.ds = subq_3.metric_time__day
ON {{ render_date_trunc("subq_5.ds", TimeGranularity.WEEK) }} = subq_3.metric_time__week
) subq_7
FULL OUTER JOIN (
SELECT
{{ render_date_trunc("ds", TimeGranularity.DAY) }} AS metric_time__day
{{ render_date_trunc("ds", TimeGranularity.WEEK) }} AS metric_time__week
, SUM(1) AS views
FROM {{ source_schema }}.fct_views views_source_src_9
GROUP BY 1
) subq_12
ON subq_7.metric_time__day = subq_12.metric_time__day
GROUP BY COALESCE(subq_7.metric_time__day, subq_12.metric_time__day)
ON subq_7.metric_time__week = subq_12.metric_time__week
GROUP BY COALESCE(subq_7.metric_time__week, subq_12.metric_time__week)
---
integration_test:
name: fill_nulls_with_0_multi_metric_query_with_nesting
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,8 @@
metric_time__day bookings_fill_nulls_with_0 views
metric_time__week bookings_fill_nulls_with_0 views
------------------- ---------------------------- -------
2019-11-27T00:00:00 0 None
2019-11-28T00:00:00 0 None
2019-11-29T00:00:00 0 None
2019-11-30T00:00:00 0 None
2019-12-01T00:00:00 1 None
2019-11-25T00:00:00 1 None
2019-12-02T00:00:00 0 None
2019-12-03T00:00:00 0 None
2019-12-04T00:00:00 0 None
2019-12-05T00:00:00 0 None
2019-12-06T00:00:00 0 None
2019-12-07T00:00:00 0 None
2019-12-08T00:00:00 0 None
2019-12-09T00:00:00 0 None
2019-12-10T00:00:00 0 None
2019-12-11T00:00:00 0 None
2019-12-12T00:00:00 0 None
2019-12-13T00:00:00 0 None
2019-12-14T00:00:00 0 None
2019-12-15T00:00:00 0 None
2019-12-16T00:00:00 0 None
2019-12-17T00:00:00 0 None
2019-12-18T00:00:00 10 None
2019-12-19T00:00:00 18 None
2019-12-20T00:00:00 2 None
2019-12-21T00:00:00 0 None
2019-12-22T00:00:00 0 None
2019-12-16T00:00:00 30 None
2019-12-23T00:00:00 0 None
2019-12-24T00:00:00 0 None
2019-12-25T00:00:00 0 None
2019-12-26T00:00:00 0 None
2019-12-27T00:00:00 0 None
2019-12-28T00:00:00 0 None
2019-12-29T00:00:00 0 None
2019-12-30T00:00:00 0 None
2019-12-31T00:00:00 0 None
2020-01-01T00:00:00 5 2
2020-01-02T00:00:00 9 5
2020-01-03T00:00:00 1 None
2020-01-04T00:00:00 0 1
2020-01-05T00:00:00 0 1
2019-12-30T00:00:00 15 9
Original file line number Diff line number Diff line change
@@ -1,42 +1,8 @@
metric_time__day bookings_fill_nulls_with_0
metric_time__week bookings_fill_nulls_with_0
------------------- ----------------------------
2019-11-27T00:00:00 0
2019-11-28T00:00:00 0
2019-11-29T00:00:00 0
2019-11-30T00:00:00 0
2019-12-01T00:00:00 1
2019-11-25T00:00:00 1
2019-12-02T00:00:00 0
2019-12-03T00:00:00 0
2019-12-04T00:00:00 0
2019-12-05T00:00:00 0
2019-12-06T00:00:00 0
2019-12-07T00:00:00 0
2019-12-08T00:00:00 0
2019-12-09T00:00:00 0
2019-12-10T00:00:00 0
2019-12-11T00:00:00 0
2019-12-12T00:00:00 0
2019-12-13T00:00:00 0
2019-12-14T00:00:00 0
2019-12-15T00:00:00 0
2019-12-16T00:00:00 0
2019-12-17T00:00:00 0
2019-12-18T00:00:00 10
2019-12-19T00:00:00 18
2019-12-20T00:00:00 2
2019-12-21T00:00:00 0
2019-12-22T00:00:00 0
2019-12-16T00:00:00 30
2019-12-23T00:00:00 0
2019-12-24T00:00:00 0
2019-12-25T00:00:00 0
2019-12-26T00:00:00 0
2019-12-27T00:00:00 0
2019-12-28T00:00:00 0
2019-12-29T00:00:00 0
2019-12-30T00:00:00 0
2019-12-31T00:00:00 0
2020-01-01T00:00:00 5
2020-01-02T00:00:00 9
2020-01-03T00:00:00 1
2020-01-04T00:00:00 0
2020-01-05T00:00:00 0
2019-12-30T00:00:00 15
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,38 @@ FROM (
subq_9.metric_time__day
, subq_9.bookings
FROM (
-- Constrain Output with WHERE
-- Join to Time Spine Dataset
SELECT
subq_8.metric_time__day
, subq_8.bookings
subq_7.metric_time__day AS metric_time__day
, subq_6.bookings AS bookings
FROM (
-- Join to Time Spine Dataset
-- Time Spine
SELECT
subq_6.metric_time__day AS metric_time__day
, subq_5.bookings AS bookings
subq_8.ds AS metric_time__day
FROM ***************************.mf_time_spine subq_8
WHERE subq_8.ds BETWEEN '2020-01-03' AND '2020-01-05'
) subq_7
LEFT OUTER JOIN (
-- Aggregate Measures
SELECT
subq_5.metric_time__day
, SUM(subq_5.bookings) AS bookings
FROM (
-- Time Spine
SELECT
subq_7.ds AS metric_time__day
FROM ***************************.mf_time_spine subq_7
WHERE subq_7.ds BETWEEN '2020-01-03' AND '2020-01-05'
) subq_6
LEFT OUTER JOIN (
-- Aggregate Measures
-- Pass Only Elements: ['bookings', 'metric_time__day']
SELECT
subq_4.metric_time__day
, SUM(subq_4.bookings) AS bookings
, subq_4.bookings
FROM (
-- Constrain Output with WHERE
SELECT
subq_3.metric_time__day
, subq_3.metric_time__week
, subq_3.bookings
FROM (
-- Pass Only Elements: ['bookings', 'metric_time__day']
-- Pass Only Elements: ['bookings', 'metric_time__day', 'metric_time__week']
SELECT
subq_2.metric_time__day
, subq_2.metric_time__week
, subq_2.bookings
FROM (
-- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00]
Expand Down Expand Up @@ -338,15 +340,14 @@ FROM (
WHERE subq_1.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05'
) subq_2
) subq_3
WHERE metric_time__day > '2020-01-01'
WHERE metric_time__week > '2020-01-01'
) subq_4
GROUP BY
subq_4.metric_time__day
) subq_5
ON
subq_6.metric_time__day = subq_5.metric_time__day
) subq_8
WHERE metric_time__day > '2020-01-01'
GROUP BY
subq_5.metric_time__day
) subq_6
ON
subq_7.metric_time__day = subq_6.metric_time__day
) subq_9
WHERE subq_9.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05'
) subq_10
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,42 @@ SELECT
metric_time__day
, COALESCE(bookings, 0) AS bookings_fill_nulls_with_0
FROM (
-- Constrain Output with WHERE
-- Join to Time Spine Dataset
-- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00]
SELECT
metric_time__day
, bookings
subq_18.metric_time__day AS metric_time__day
, subq_17.bookings AS bookings
FROM (
-- Join to Time Spine Dataset
-- Time Spine
SELECT
subq_17.metric_time__day AS metric_time__day
, subq_16.bookings AS bookings
ds AS metric_time__day
FROM ***************************.mf_time_spine subq_19
WHERE ds BETWEEN '2020-01-03' AND '2020-01-05'
) subq_18
LEFT OUTER JOIN (
-- Constrain Output with WHERE
-- Pass Only Elements: ['bookings', 'metric_time__day']
-- Aggregate Measures
SELECT
metric_time__day
, SUM(bookings) AS bookings
FROM (
-- Time Spine
SELECT
ds AS metric_time__day
FROM ***************************.mf_time_spine subq_18
WHERE ds BETWEEN '2020-01-03' AND '2020-01-05'
) subq_17
LEFT OUTER JOIN (
-- Constrain Output with WHERE
-- Aggregate Measures
-- Read Elements From Semantic Model 'bookings_source'
-- Metric Time Dimension 'ds'
-- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00]
-- Pass Only Elements: ['bookings', 'metric_time__day', 'metric_time__week']
SELECT
metric_time__day
, SUM(bookings) AS bookings
FROM (
-- Read Elements From Semantic Model 'bookings_source'
-- Metric Time Dimension 'ds'
-- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00]
-- Pass Only Elements: ['bookings', 'metric_time__day']
SELECT
DATE_TRUNC('day', ds) AS metric_time__day
, 1 AS bookings
FROM ***************************.fct_bookings bookings_source_src_28000
WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-03' AND '2020-01-05'
) subq_14
WHERE metric_time__day > '2020-01-01'
GROUP BY
metric_time__day
) subq_16
ON
subq_17.metric_time__day = subq_16.metric_time__day
) subq_19
WHERE (
metric_time__day BETWEEN '2020-01-03' AND '2020-01-05'
) AND (
metric_time__day > '2020-01-01'
)
DATE_TRUNC('day', ds) AS metric_time__day
, DATE_TRUNC('week', ds) AS metric_time__week
, 1 AS bookings
FROM ***************************.fct_bookings bookings_source_src_28000
WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-03' AND '2020-01-05'
) subq_14
WHERE metric_time__week > '2020-01-01'
GROUP BY
metric_time__day
) subq_17
ON
subq_18.metric_time__day = subq_17.metric_time__day
WHERE subq_18.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05'
) subq_21

0 comments on commit 5b7b886

Please sign in to comment.