Skip to content

Commit

Permalink
Add check query tests for simple metrics with sub-daily dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Jul 29, 2024
1 parent b9a0720 commit 9b8be29
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ semantic_model:
schema_name: $source_schema
alias: dim_users

defaults:
agg_time_dimension: created_at

dimensions:
- name: ds
type: time
Expand Down Expand Up @@ -45,3 +48,9 @@ semantic_model:
- name: user
type: primary
expr: user_id

measures:
- name: new_users
expr: "1"
agg: SUM
create_metric: true
52 changes: 52 additions & 0 deletions tests_metricflow/integration/test_cases/itest_metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2227,3 +2227,55 @@ integration_test:
FROM {{ source_schema }}.fct_bookings
WHERE ({{ render_date_trunc("ds", TimeGranularity.DAY) }} < '2012-12-20')
AND ({{ render_date_trunc("ds", TimeGranularity.WEEK) }} > '2019-12-18')
---
integration_test:
name: simple_metric_with_sub_daily_dimension
description: Tests querying a metric with a sub-daily dimension
model: SIMPLE_MODEL
metrics: ["new_users"]
group_bys: ["user__last_profile_edit_ts__millisecond"]
check_query: |
SELECT
{{ render_date_trunc("last_profile_edit_ts", TimeGranularity.MILLISECOND) }} AS user__last_profile_edit_ts__millisecond
, SUM(1) AS new_users
FROM {{ source_schema }}.dim_users
GROUP BY {{ render_date_trunc("last_profile_edit_ts", TimeGranularity.MILLISECOND) }}
---
integration_test:
name: simple_metric_with_joined_sub_daily_dimension
description: Tests querying a metric with a sub-daily dimension that requires a join
model: SIMPLE_MODEL
metrics: ["bookings"]
group_bys: ["user__last_login_ts__minute"]
check_query: |
SELECT
subq_8.user__last_login_ts__minute AS listing__user__last_login_ts__minute
, SUM(subq_2.bookings) AS bookings
FROM (
SELECT
{{ render_date_trunc("ds_partitioned", TimeGranularity.DAY) }} AS ds_partitioned__day
, listing_id AS listing
, 1 AS bookings
FROM {{ source_schema }}.fct_bookings
) subq_2
LEFT OUTER JOIN (
SELECT
{{ render_date_trunc("u.ds_partitioned", TimeGranularity.DAY) }} AS user__ds_partitioned__day
, {{ render_date_trunc("u.last_login_ts", TimeGranularity.MINUTE) }} AS user__last_login_ts__minute
, l.listing_id AS listing
FROM {{ source_schema }}.dim_listings_latest l
LEFT OUTER JOIN
{{ source_schema }}.dim_users u
ON
l.user_id = u.user_id
) subq_8
ON
(
subq_2.listing = subq_8.listing
) AND (
subq_2.ds_partitioned__day = subq_8.user__ds_partitioned__day
)
GROUP BY
subq_8.user__last_login_ts__minute
# Add simple simple query above this - user metric

0 comments on commit 9b8be29

Please sign in to comment.