Skip to content

Commit

Permalink
Sub-daily granularity test additions (#1366)
Browse files Browse the repository at this point in the history
This PR handles some PR feedback related to testing for sub-daily
granularity that I wanted to add at the top of the stack to avoid too
many issues with rebasing. Updates:
- Changes the dates of the test time spine data to span across multiple
days
- Adds tests related to the interactions between sub-daily granularity
and metric default granularity

---------

Co-authored-by: Thomas Lento <[email protected]>
  • Loading branch information
courtneyholcomb and tlento authored Aug 16, 2024
1 parent 423513d commit 89537d0
Show file tree
Hide file tree
Showing 26 changed files with 3,222 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,20 @@ metric:
measure:
name: archived_users
join_to_timespine: true
---
metric:
name: simple_subdaily_metric_default_day
description: simple metric with sub-daily agg time dim that doesn't specify default granularity
type: simple
type_params:
measure:
name: archived_users
---
metric:
name: simple_subdaily_metric_default_hour
description: simple metric with sub-daily agg time dim that has an explicit default granularity
type: simple
type_params:
measure:
name: archived_users
time_granularity: hour
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,8 @@
'user__revenue_all_time',
'user__revenue_instance__user__revenue',
'user__revenue_instance__user__revenue_all_time',
'user__simple_subdaily_metric_default_day',
'user__simple_subdaily_metric_default_hour',
'user__smallest_listing',
'user__subdaily_join_to_time_spine_metric',
'user__total_account_balance_first_day',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ Model Join-Path Entity Links
('listings_latest',) ("('user',)", "('user',)") regional_starting_balance_ratios ['JOINED', 'METRIC']
('listings_latest',) ("('user',)", "('user',)") revenue ['JOINED', 'METRIC']
('listings_latest',) ("('user',)", "('user',)") revenue_all_time ['JOINED', 'METRIC']
('listings_latest',) ("('user',)", "('user',)") simple_subdaily_metric_default_day ['JOINED', 'METRIC']
('listings_latest',) ("('user',)", "('user',)") simple_subdaily_metric_default_hour ['JOINED', 'METRIC']
('listings_latest',) ("('user',)", "('user',)") smallest_listing ['JOINED', 'METRIC']
('listings_latest',) ("('user',)", "('user',)") subdaily_join_to_time_spine_metric ['JOINED', 'METRIC']
('listings_latest',) ("('user',)", "('user',)") total_account_balance_first_day ['JOINED', 'METRIC']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@
'company__user__company__regional_starting_balance_ratios',
'company__user__company__revenue',
'company__user__company__revenue_all_time',
'company__user__company__simple_subdaily_metric_default_day',
'company__user__company__simple_subdaily_metric_default_hour',
'company__user__company__smallest_listing',
'company__user__company__subdaily_join_to_time_spine_metric',
'company__user__company__total_account_balance_first_day',
Expand Down Expand Up @@ -570,6 +572,8 @@
'user__revenue_all_time',
'user__revenue_instance__user__revenue',
'user__revenue_instance__user__revenue_all_time',
'user__simple_subdaily_metric_default_day',
'user__simple_subdaily_metric_default_hour',
'user__smallest_listing',
'user__subdaily_join_to_time_spine_metric',
'user__total_account_balance_first_day',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ table_snapshot:
- ["2020-01-01 07:00:00"]
- ["2020-01-01 08:00:00"]
- ["2020-01-01 09:00:00"]
- ["2020-01-01 010:00:00"]
- ["2020-01-01 10:00:00"]
- ["2020-01-01 11:00:00"]
- ["2020-01-01 12:00:00"]
- ["2020-01-02 01:00:00"]
Expand All @@ -25,7 +25,7 @@ table_snapshot:
- ["2020-01-02 07:00:00"]
- ["2020-01-02 08:00:00"]
- ["2020-01-02 09:00:00"]
- ["2020-01-02 010:00:00"]
- ["2020-01-02 10:00:00"]
- ["2020-01-02 11:00:00"]
- ["2020-01-02 12:00:00"]
- ["2020-01-03 01:00:00"]
Expand All @@ -37,6 +37,6 @@ table_snapshot:
- ["2020-01-03 07:00:00"]
- ["2020-01-03 08:00:00"]
- ["2020-01-03 09:00:00"]
- ["2020-01-03 010:00:00"]
- ["2020-01-03 10:00:00"]
- ["2020-01-03 11:00:00"]
- ["2020-01-03 12:00:00"]
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ table_snapshot:
- ["2020-01-01 00:00:00.000008"]
- ["2020-01-01 00:00:00.000009"]
- ["2020-01-01 00:00:00.000010"]
- ["2020-01-01 00:00:00.000011"]
- ["2020-01-01 00:00:00.000012"]
- ["2020-01-01 00:00:00.000013"]
- ["2020-01-01 00:00:00.000014"]
- ["2020-01-01 00:00:00.000015"]
- ["2020-01-01 00:00:00.000016"]
- ["2020-01-01 00:00:00.000017"]
- ["2020-01-01 00:00:00.000018"]
- ["2020-01-01 00:00:00.000019"]
- ["2020-01-01 00:00:00.000020"]
- ["2020-01-01 00:00:00.000021"]
- ["2020-01-01 00:00:00.000022"]
- ["2020-01-01 00:00:00.000023"]
- ["2020-01-01 00:00:00.000024"]
- ["2020-01-01 00:00:00.000025"]
- ["2020-01-01 00:00:00.000026"]
- ["2020-01-01 00:00:00.000027"]
- ["2020-01-01 00:00:00.000028"]
- ["2020-01-01 00:00:00.000029"]
- ["2020-01-01 00:00:00.000030"]
- ["2020-01-02 00:00:00.000011"]
- ["2020-01-02 00:00:00.000012"]
- ["2020-01-02 00:00:00.000013"]
- ["2020-01-02 00:00:00.000014"]
- ["2020-01-02 00:00:00.000015"]
- ["2020-01-02 00:00:00.000016"]
- ["2020-01-02 00:00:00.000017"]
- ["2020-01-02 00:00:00.000018"]
- ["2020-01-02 00:00:00.000019"]
- ["2020-01-02 00:00:00.000020"]
- ["2020-01-03 00:00:00.000021"]
- ["2020-01-03 00:00:00.000022"]
- ["2020-01-03 00:00:00.000023"]
- ["2020-01-03 00:00:00.000024"]
- ["2020-01-03 00:00:00.000025"]
- ["2020-01-03 00:00:00.000026"]
- ["2020-01-04 00:00:00.000027"]
- ["2020-01-05 00:00:00.000028"]
- ["2020-01-06 00:00:00.000029"]
- ["2020-01-07 00:00:00.000030"]
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ table_snapshot:
- ["2020-01-01 00:00:00.008"]
- ["2020-01-01 00:00:00.009"]
- ["2020-01-01 00:00:00.010"]
- ["2020-01-01 00:00:00.011"]
- ["2020-01-01 00:00:00.012"]
- ["2020-01-01 00:00:00.013"]
- ["2020-01-01 00:00:00.014"]
- ["2020-01-01 00:00:00.015"]
- ["2020-01-01 00:00:00.016"]
- ["2020-01-01 00:00:00.017"]
- ["2020-01-01 00:00:00.018"]
- ["2020-01-01 00:00:00.019"]
- ["2020-01-01 00:00:00.020"]
- ["2020-01-01 00:00:00.021"]
- ["2020-01-01 00:00:00.022"]
- ["2020-01-01 00:00:00.023"]
- ["2020-01-01 00:00:00.024"]
- ["2020-01-01 00:00:00.025"]
- ["2020-01-01 00:00:00.026"]
- ["2020-01-01 00:00:00.027"]
- ["2020-01-01 00:00:00.028"]
- ["2020-01-01 00:00:00.029"]
- ["2020-01-01 00:00:00.030"]
- ["2020-01-02 00:00:00.011"]
- ["2020-01-02 00:00:00.012"]
- ["2020-01-02 00:00:00.013"]
- ["2020-01-02 00:00:00.014"]
- ["2020-01-02 00:00:00.015"]
- ["2020-01-02 00:00:00.016"]
- ["2020-01-02 00:00:00.017"]
- ["2020-01-02 00:00:00.018"]
- ["2020-01-02 00:00:00.019"]
- ["2020-01-02 00:00:00.020"]
- ["2020-01-03 00:00:00.021"]
- ["2020-01-03 00:00:00.022"]
- ["2020-01-03 00:00:00.023"]
- ["2020-01-03 00:00:00.024"]
- ["2020-01-03 00:00:00.025"]
- ["2020-01-03 00:00:00.026"]
- ["2020-01-03 00:00:00.027"]
- ["2020-01-04 00:00:00.028"]
- ["2020-01-04 00:00:00.029"]
- ["2020-01-04 00:00:00.030"]
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ table_snapshot:
- ["2020-01-01 00:08:00"]
- ["2020-01-01 00:09:00"]
- ["2020-01-01 00:10:00"]
- ["2020-01-01 00:11:00"]
- ["2020-01-01 00:12:00"]
- ["2020-01-01 00:13:00"]
- ["2020-01-01 00:14:00"]
- ["2020-01-01 00:15:00"]
- ["2020-01-01 00:16:00"]
- ["2020-01-01 00:17:00"]
- ["2020-01-01 00:18:00"]
- ["2020-01-01 00:19:00"]
- ["2020-01-01 00:20:00"]
- ["2020-01-01 00:21:00"]
- ["2020-01-01 00:22:00"]
- ["2020-01-01 00:23:00"]
- ["2020-01-01 00:24:00"]
- ["2020-01-01 00:25:00"]
- ["2020-01-01 00:26:00"]
- ["2020-01-01 00:27:00"]
- ["2020-01-01 00:28:00"]
- ["2020-01-01 00:29:00"]
- ["2020-01-01 00:30:00"]
- ["2020-01-02 00:11:00"]
- ["2020-01-02 00:12:00"]
- ["2020-01-02 00:13:00"]
- ["2020-01-02 00:14:00"]
- ["2020-01-02 00:15:00"]
- ["2020-01-02 00:16:00"]
- ["2020-01-02 00:17:00"]
- ["2020-01-02 00:18:00"]
- ["2020-01-02 00:19:00"]
- ["2020-01-02 00:20:00"]
- ["2020-01-03 00:21:00"]
- ["2020-01-03 00:22:00"]
- ["2020-01-03 00:23:00"]
- ["2020-01-03 00:24:00"]
- ["2020-01-03 00:25:00"]
- ["2020-01-03 00:26:00"]
- ["2020-01-03 00:27:00"]
- ["2020-01-04 00:28:00"]
- ["2020-01-04 00:29:00"]
- ["2020-01-04 00:30:00"]
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ table_snapshot:
- ["2020-01-01 00:00:00.000000008"]
- ["2020-01-01 00:00:00.000000009"]
- ["2020-01-01 00:00:00.000000010"]
- ["2020-01-01 00:00:00.000000011"]
- ["2020-01-01 00:00:00.000000012"]
- ["2020-01-01 00:00:00.000000013"]
- ["2020-01-01 00:00:00.000000014"]
- ["2020-01-01 00:00:00.000000015"]
- ["2020-01-01 00:00:00.000000016"]
- ["2020-01-01 00:00:00.000000017"]
- ["2020-01-01 00:00:00.000000018"]
- ["2020-01-01 00:00:00.000000019"]
- ["2020-01-01 00:00:00.000000020"]
- ["2020-01-01 00:00:00.000000021"]
- ["2020-01-01 00:00:00.000000022"]
- ["2020-01-01 00:00:00.000000023"]
- ["2020-01-01 00:00:00.000000024"]
- ["2020-01-01 00:00:00.000000025"]
- ["2020-01-01 00:00:00.000000026"]
- ["2020-01-01 00:00:00.000000027"]
- ["2020-01-01 00:00:00.000000028"]
- ["2020-01-01 00:00:00.000000029"]
- ["2020-01-01 00:00:00.000000030"]
- ["2020-01-02 00:00:00.000000011"]
- ["2020-01-02 00:00:00.000000012"]
- ["2020-01-02 00:00:00.000000013"]
- ["2020-01-02 00:00:00.000000014"]
- ["2020-01-02 00:00:00.000000015"]
- ["2020-01-02 00:00:00.000000016"]
- ["2020-01-02 00:00:00.000000017"]
- ["2020-01-03 00:00:00.000000018"]
- ["2020-01-03 00:00:00.000000019"]
- ["2020-01-03 00:00:00.000000020"]
- ["2020-01-03 00:00:00.000000021"]
- ["2020-01-03 00:00:00.000000022"]
- ["2020-01-04 00:00:00.000000023"]
- ["2020-01-04 00:00:00.000000024"]
- ["2020-01-04 00:00:00.000000025"]
- ["2020-01-04 00:00:00.000000026"]
- ["2020-01-04 00:00:00.000000027"]
- ["2020-01-04 00:00:00.000000028"]
- ["2020-01-04 00:00:00.000000029"]
- ["2020-01-05 00:00:00.000000030"]
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ table_snapshot:
- ["2020-01-01 00:00:08"]
- ["2020-01-01 00:00:09"]
- ["2020-01-01 00:00:10"]
- ["2020-01-01 00:00:11"]
- ["2020-01-01 00:00:12"]
- ["2020-01-01 00:00:13"]
- ["2020-01-01 00:00:14"]
- ["2020-01-01 00:00:15"]
- ["2020-01-01 00:00:16"]
- ["2020-01-01 00:00:17"]
- ["2020-01-01 00:00:18"]
- ["2020-01-01 00:00:19"]
- ["2020-01-01 00:00:20"]
- ["2020-01-01 00:00:21"]
- ["2020-01-01 00:00:22"]
- ["2020-01-01 00:00:23"]
- ["2020-01-01 00:00:24"]
- ["2020-01-01 00:00:25"]
- ["2020-01-01 00:00:26"]
- ["2020-01-01 00:00:27"]
- ["2020-01-01 00:00:28"]
- ["2020-01-01 00:00:29"]
- ["2020-01-01 00:00:30"]
- ["2020-01-02 00:00:11"]
- ["2020-01-02 00:00:12"]
- ["2020-01-02 00:00:13"]
- ["2020-01-02 00:00:14"]
- ["2020-01-02 00:00:15"]
- ["2020-01-02 00:00:16"]
- ["2020-01-02 00:00:17"]
- ["2020-01-02 00:00:18"]
- ["2020-01-02 00:00:19"]
- ["2020-01-02 00:00:20"]
- ["2020-01-03 00:00:21"]
- ["2020-01-03 00:00:22"]
- ["2020-01-03 00:00:23"]
- ["2020-01-03 00:00:24"]
- ["2020-01-03 00:00:25"]
- ["2020-01-03 00:00:26"]
- ["2020-01-03 00:00:27"]
- ["2020-01-03 00:00:28"]
- ["2020-01-04 00:00:29"]
- ["2020-01-04 00:00:30"]
26 changes: 26 additions & 0 deletions tests_metricflow/integration/test_cases/itest_metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2330,3 +2330,29 @@ integration_test:
GROUP BY metric_time__hour
) subq_3
ON subq_5.ts = subq_3.metric_time__hour
---
integration_test:
name: subdaily_metric_defaults_to_day_granularity
description: test that a subdaily metric without explicit default granularity defaults to DAY
model: SIMPLE_MODEL
metrics: ["simple_subdaily_metric_default_day"]
group_bys: ["metric_time"]
check_query: |
SELECT
{{ render_date_trunc("archived_at", TimeGranularity.DAY) }} AS metric_time__day
, SUM(1) AS simple_subdaily_metric_default_day
FROM {{ source_schema }}.dim_users
GROUP BY {{ render_date_trunc("archived_at", TimeGranularity.DAY) }}
---
integration_test:
name: subdaily_metric_default_granularity
description: test that a subdaily metric with an explicit default granularity uses its specified default
model: SIMPLE_MODEL
metrics: ["simple_subdaily_metric_default_hour"]
group_bys: ["metric_time"]
check_query: |
SELECT
{{ render_date_trunc("archived_at", TimeGranularity.HOUR) }} AS metric_time__hour
, SUM(1) AS simple_subdaily_metric_default_hour
FROM {{ source_schema }}.dim_users
GROUP BY {{ render_date_trunc("archived_at", TimeGranularity.HOUR) }}
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,26 @@ def test_subdaily_time_constraint_with_metric( # noqa: D103
dataflow_plan_builder=dataflow_plan_builder,
query_spec=query_spec,
)


@pytest.mark.sql_engine_snapshot
def test_subdaily_granularity_overrides_metric_default_granularity( # noqa: D103
request: FixtureRequest,
mf_test_configuration: MetricFlowTestConfiguration,
dataflow_plan_builder: DataflowPlanBuilder,
dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter,
sql_client: SqlClient,
) -> None:
query_spec = MetricFlowQuerySpec(
metric_specs=(MetricSpec("subdaily_join_to_time_spine_metric"),),
time_dimension_specs=(DataSet.metric_time_dimension_spec(time_granularity=TimeGranularity.HOUR),),
)

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 89537d0

Please sign in to comment.