From 9203d459e197e94cdb703514de548c025e2dbc20 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Mon, 29 Jul 2024 17:31:57 -0700 Subject: [PATCH] Add new measures/metrics for testing metrics that join to time spine with sub-daily granularities --- .../semantic_models/user_sm_source.yaml | 52 +++++++++++++++++++ ...linkable_element_set_as_spec_set__set0.txt | 2 + .../dict/test_get_names__result0.txt | 1 + ...linkable_elements_for_measure__result0.txt | 2 + ...elements_for_no_metrics_query__result0.txt | 4 ++ ...nversion_count_with_no_group_by__plan0.xml | 4 +- ...timespine_and_fill_nulls_with_0__plan0.xml | 4 +- .../test_conversion_rate__plan0.xml | 4 +- ...n_rate_with_constant_properties__plan0.xml | 4 +- ...onversion_rate_with_no_group_by__plan0.xml | 4 +- ...est_conversion_rate_with_window__plan0.xml | 4 +- ...mantic_model_ratio_metrics_plan__dfp_0.xml | 2 +- ...o_from_multiple_semantic_models__plan0.xml | 2 +- ...with_joined_sub_daily_dimension__plan0.sql | 1 + ...metric_with_sub_daily_dimension__plan0.sql | 1 + .../test_sub_daily_dimension__plan0.sql | 1 + ...rsion_metric_predicate_pushdown__dfp_0.xml | 4 +- .../DuckDB/test_partitioned_join__plan0.sql | 1 + 18 files changed, 81 insertions(+), 16 deletions(-) diff --git a/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/simple_manifest/semantic_models/user_sm_source.yaml b/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/simple_manifest/semantic_models/user_sm_source.yaml index dacb9689cf..3a08a7234b 100644 --- a/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/simple_manifest/semantic_models/user_sm_source.yaml +++ b/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/simple_manifest/semantic_models/user_sm_source.yaml @@ -54,3 +54,55 @@ semantic_model: expr: "1" agg: SUM create_metric: true + - name: archived_users + expr: "1" + agg: SUM + create_metric: true + agg_time_dimension: archived_at +--- +metric: + name: subdaily_cumulative_window_metric + description: cumulative window metric with a sub-daily agg time dim + type: cumulative + type_params: + measure: archived_users + cumulative_type_params: + window: 3 hours +--- +metric: + name: subdaily_cumulative_grain_to_date_metric + description: cumulative grain to date metric with a sub-daily agg time dim + type: cumulative + type_params: + measure: archived_users + cumulative_type_params: + grain_to_date: hour +--- +metric: + name: subdaily_offset_window_metric + description: offset window metric with a sub-daily agg time dim + type: derived + type_params: + expr: archived_users + metrics: + - name: archived_users + offset_window: 1 hour +--- +metric: + name: subdaily_offset_grain_to_date_metric + description: offset grain to date metric with a sub-daily agg time dim + type: derived + type_params: + expr: archived_users + metrics: + - name: archived_users + offset_to_grain: hour +--- +metric: + name: subdaily_join_to_time_spine_metric + description: simple metric with sub-daily agg time dim that joins to time spine + type: simple + type_params: + measure: + name: archived_users + join_to_timespine: true \ No newline at end of file diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_linkable_spec_resolver.py/list/test_linkable_element_set_as_spec_set__set0.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_linkable_spec_resolver.py/list/test_linkable_element_set_as_spec_set__set0.txt index 81f7d1538e..3c2e4a6bfe 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_linkable_spec_resolver.py/list/test_linkable_element_set_as_spec_set__set0.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_linkable_spec_resolver.py/list/test_linkable_element_set_as_spec_set__set0.txt @@ -186,6 +186,7 @@ 'user__archived_at__quarter', 'user__archived_at__week', 'user__archived_at__year', + 'user__archived_users', 'user__bio_added_ts__day', 'user__bio_added_ts__extract_day', 'user__bio_added_ts__extract_day', @@ -456,6 +457,7 @@ 'user__revenue_instance__user__revenue', 'user__revenue_instance__user__revenue_all_time', 'user__smallest_listing', + 'user__subdaily_join_to_time_spine_metric', 'user__total_account_balance_first_day', 'user__verification__user__identity_verifications', 'user__view__user__views', diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_semantic_model_container.py/dict/test_get_names__result0.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_semantic_model_container.py/dict/test_get_names__result0.txt index f52d494f84..6204c4d106 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_semantic_model_container.py/dict/test_get_names__result0.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_semantic_model_container.py/dict/test_get_names__result0.txt @@ -24,6 +24,7 @@ 'account_balance', 'approximate_continuous_booking_value_p99', 'approximate_discrete_booking_value_p99', + 'archived_users', 'average_booking_value', 'bookers', 'booking_payments', diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_semantic_model_container.py/str/test_linkable_elements_for_measure__result0.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_semantic_model_container.py/str/test_linkable_elements_for_measure__result0.txt index fa3dcb7aae..49910102bd 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_semantic_model_container.py/str/test_linkable_elements_for_measure__result0.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_semantic_model_container.py/str/test_linkable_elements_for_measure__result0.txt @@ -177,6 +177,7 @@ Model Join-Path Entity Links ('listings_latest',) ("('user',)", "('revenue_instance', 'user')") revenue ['JOINED', 'METRIC'] ('listings_latest',) ("('user',)", "('revenue_instance', 'user')") revenue_all_time ['JOINED', 'METRIC'] ('listings_latest',) ("('user',)", "('user',)") active_listings ['JOINED', 'METRIC'] +('listings_latest',) ("('user',)", "('user',)") archived_users ['JOINED', 'METRIC'] ('listings_latest',) ("('user',)", "('user',)") current_account_balance_by_user ['JOINED', 'METRIC'] ('listings_latest',) ("('user',)", "('user',)") identity_verifications ['JOINED', 'METRIC'] ('listings_latest',) ("('user',)", "('user',)") largest_listing ['JOINED', 'METRIC'] @@ -188,6 +189,7 @@ Model Join-Path Entity Links ('listings_latest',) ("('user',)", "('user',)") revenue ['JOINED', 'METRIC'] ('listings_latest',) ("('user',)", "('user',)") revenue_all_time ['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'] ('listings_latest',) ("('user',)", "('user',)") views ['JOINED', 'METRIC'] ('listings_latest',) ("('user',)", "('user',)") visit_buy_conversion_rate ['JOINED', 'METRIC'] diff --git a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_semantic_model_container.py/tuple/test_linkable_elements_for_no_metrics_query__result0.txt b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_semantic_model_container.py/tuple/test_linkable_elements_for_no_metrics_query__result0.txt index 8d687dd5cd..6f9396a6e5 100644 --- a/metricflow-semantics/tests_metricflow_semantics/snapshots/test_semantic_model_container.py/tuple/test_linkable_elements_for_no_metrics_query__result0.txt +++ b/metricflow-semantics/tests_metricflow_semantics/snapshots/test_semantic_model_container.py/tuple/test_linkable_elements_for_no_metrics_query__result0.txt @@ -88,6 +88,7 @@ 'company__listing__user__company__views_times_booking_value', 'company__user', 'company__user__company__active_listings', + 'company__user__company__archived_users', 'company__user__company__current_account_balance_by_user', 'company__user__company__identity_verifications', 'company__user__company__largest_listing', @@ -99,6 +100,7 @@ 'company__user__company__revenue', 'company__user__company__revenue_all_time', 'company__user__company__smallest_listing', + 'company__user__company__subdaily_join_to_time_spine_metric', 'company__user__company__total_account_balance_first_day', 'company__user__company__views', 'company__user__company__visit_buy_conversion_rate', @@ -452,6 +454,7 @@ 'user__archived_at__extract_quarter', 'user__archived_at__extract_year', 'user__archived_at__hour', + 'user__archived_users', 'user__bio_added_ts__extract_day', 'user__bio_added_ts__extract_dow', 'user__bio_added_ts__extract_doy', @@ -568,6 +571,7 @@ 'user__revenue_instance__user__revenue', 'user__revenue_instance__user__revenue_all_time', 'user__smallest_listing', + 'user__subdaily_join_to_time_spine_metric', 'user__total_account_balance_first_day', 'user__verification__user__identity_verifications', 'user__view__user__views', diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_count_with_no_group_by__plan0.xml b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_count_with_no_group_by__plan0.xml index 34342ed5c4..8793465e07 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_count_with_no_group_by__plan0.xml +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_count_with_no_group_by__plan0.xml @@ -239,7 +239,7 @@ - + @@ -694,7 +694,7 @@ - + diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.xml b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.xml index 714dda14f3..05827c801d 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.xml +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_metric_join_to_timespine_and_fill_nulls_with_0__plan0.xml @@ -321,7 +321,7 @@ - + @@ -860,7 +860,7 @@ - + diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate__plan0.xml b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate__plan0.xml index d93ede7dd6..4f1a1debb6 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate__plan0.xml +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate__plan0.xml @@ -267,7 +267,7 @@ - + @@ -753,7 +753,7 @@ - + diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate_with_constant_properties__plan0.xml b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate_with_constant_properties__plan0.xml index bf2e7fd549..0e47d15bbd 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate_with_constant_properties__plan0.xml +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate_with_constant_properties__plan0.xml @@ -290,7 +290,7 @@ - + @@ -813,7 +813,7 @@ - + diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate_with_no_group_by__plan0.xml b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate_with_no_group_by__plan0.xml index 60fbf4b0f4..f18c79eea4 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate_with_no_group_by__plan0.xml +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate_with_no_group_by__plan0.xml @@ -242,7 +242,7 @@ - + @@ -697,7 +697,7 @@ - + diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate_with_window__plan0.xml b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate_with_window__plan0.xml index e4c825e0bb..f63906f119 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate_with_window__plan0.xml +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate_with_window__plan0.xml @@ -290,7 +290,7 @@ - + @@ -801,7 +801,7 @@ - + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_multi_semantic_model_ratio_metrics_plan__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_multi_semantic_model_ratio_metrics_plan__dfp_0.xml index 1b05350e56..dae988091d 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_multi_semantic_model_ratio_metrics_plan__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_multi_semantic_model_ratio_metrics_plan__dfp_0.xml @@ -115,7 +115,7 @@ - + diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.xml b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.xml index 159530b266..6582795a6b 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.xml @@ -2183,7 +2183,7 @@ - + diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_metric_with_joined_sub_daily_dimension__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_metric_with_joined_sub_daily_dimension__plan0.sql index 2319c7e1f9..c2505892cd 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_metric_with_joined_sub_daily_dimension__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_metric_with_joined_sub_daily_dimension__plan0.sql @@ -1105,6 +1105,7 @@ FROM ( -- Read Elements From Semantic Model 'users_ds_source' SELECT 1 AS new_users + , 1 AS archived_users , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_metric_with_sub_daily_dimension__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_metric_with_sub_daily_dimension__plan0.sql index 712a3c0a08..e1d3b4b02c 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_metric_with_sub_daily_dimension__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_metric_with_sub_daily_dimension__plan0.sql @@ -208,6 +208,7 @@ FROM ( -- Read Elements From Semantic Model 'users_ds_source' SELECT 1 AS new_users + , 1 AS archived_users , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_sub_daily_dimension__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_sub_daily_dimension__plan0.sql index 4784321669..e10224debe 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_sub_daily_dimension__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_sub_daily_dimension__plan0.sql @@ -5,6 +5,7 @@ FROM ( -- Read Elements From Semantic Model 'users_ds_source' SELECT 1 AS new_users + , 1 AS archived_users , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_conversion_metric_predicate_pushdown__dfp_0.xml b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_conversion_metric_predicate_pushdown__dfp_0.xml index a8488b82d8..36a3aaae53 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_conversion_metric_predicate_pushdown__dfp_0.xml +++ b/tests_metricflow/snapshots/test_predicate_pushdown_optimizer.py/DataflowPlan/test_conversion_metric_predicate_pushdown__dfp_0.xml @@ -153,7 +153,7 @@ - + @@ -257,7 +257,7 @@ - + diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_partitioned_join__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_partitioned_join__plan0.sql index 11f19b0691..9331570241 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_partitioned_join__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_partitioned_join__plan0.sql @@ -349,6 +349,7 @@ FROM ( -- Read Elements From Semantic Model 'users_ds_source' SELECT 1 AS new_users + , 1 AS archived_users , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month