From 93e0407ef2014c9194fdb718c2824bf108b09d25 Mon Sep 17 00:00:00 2001 From: Will Deng Date: Fri, 23 Aug 2024 13:00:42 -0400 Subject: [PATCH] snapshots --- ...t_conversion_metric_with_filter__plan0.sql | 383 ++++++++++++++++++ ...on_metric_with_filter__plan0_optimized.sql | 94 +++++ ...t_conversion_metric_with_filter__plan0.sql | 383 ++++++++++++++++++ ...on_metric_with_filter__plan0_optimized.sql | 94 +++++ ...t_conversion_metric_with_filter__plan0.sql | 383 ++++++++++++++++++ ...on_metric_with_filter__plan0_optimized.sql | 94 +++++ ...t_conversion_metric_with_filter__plan0.sql | 383 ++++++++++++++++++ ...on_metric_with_filter__plan0_optimized.sql | 94 +++++ ...t_conversion_metric_with_filter__plan0.sql | 383 ++++++++++++++++++ ...on_metric_with_filter__plan0_optimized.sql | 94 +++++ ...t_conversion_metric_with_filter__plan0.sql | 383 ++++++++++++++++++ ...on_metric_with_filter__plan0_optimized.sql | 94 +++++ ...t_conversion_metric_with_filter__plan0.sql | 383 ++++++++++++++++++ ...on_metric_with_filter__plan0_optimized.sql | 94 +++++ .../test_conversion_metric__query_output.txt | 10 + ..._with_categorical_filter__query_output.txt | 11 + ...h_filter_not_in_group_by__query_output.txt | 3 + ...ric_with_time_constraint__query_output.txt | 6 + ...rsion_metric_with_window__query_output.txt | 10 + ...ndow_and_time_constraint__query_output.txt | 8 + .../test_conversion_metric__query_output.txt | 10 + ..._with_categorical_filter__query_output.txt | 10 + ...h_filter_not_in_group_by__query_output.txt | 3 + ...ric_with_time_constraint__query_output.txt | 5 + ...rsion_metric_with_window__query_output.txt | 10 + ...ndow_and_time_constraint__query_output.txt | 7 + .../test_conversion_metric__query_output.txt | 10 + ..._with_categorical_filter__query_output.txt | 10 + ...h_filter_not_in_group_by__query_output.txt | 3 + ...ric_with_time_constraint__query_output.txt | 6 + ...rsion_metric_with_window__query_output.txt | 10 + ...ndow_and_time_constraint__query_output.txt | 8 + .../test_conversion_metric__query_output.txt | 10 + ..._with_categorical_filter__query_output.txt | 10 + ...h_filter_not_in_group_by__query_output.txt | 3 + ...ric_with_time_constraint__query_output.txt | 6 + ...rsion_metric_with_window__query_output.txt | 10 + ...ndow_and_time_constraint__query_output.txt | 8 + .../test_conversion_metric__query_output.txt | 10 + ..._with_categorical_filter__query_output.txt | 10 + ...h_filter_not_in_group_by__query_output.txt | 3 + ...ric_with_time_constraint__query_output.txt | 5 + ...rsion_metric_with_window__query_output.txt | 10 + ...ndow_and_time_constraint__query_output.txt | 7 + .../test_conversion_metric__query_output.txt | 10 + ..._with_categorical_filter__query_output.txt | 10 + ...h_filter_not_in_group_by__query_output.txt | 3 + ...ric_with_time_constraint__query_output.txt | 5 + ...rsion_metric_with_window__query_output.txt | 10 + ...ndow_and_time_constraint__query_output.txt | 7 + .../test_conversion_metric__query_output.txt | 10 + ..._with_categorical_filter__query_output.txt | 10 + ...h_filter_not_in_group_by__query_output.txt | 3 + ...ric_with_time_constraint__query_output.txt | 5 + ...rsion_metric_with_window__query_output.txt | 10 + ...ndow_and_time_constraint__query_output.txt | 7 + 56 files changed, 3661 insertions(+) create mode 100644 tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_filter__plan0.sql create mode 100644 tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_filter__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_filter__plan0.sql create mode 100644 tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_filter__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_filter__plan0.sql create mode 100644 tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_filter__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_filter__plan0.sql create mode 100644 tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_filter__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_filter__plan0.sql create mode 100644 tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_filter__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_filter__plan0.sql create mode 100644 tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_filter__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_filter__plan0.sql create mode 100644 tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_filter__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_categorical_filter__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_filter_not_in_group_by__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_time_constraint__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_window__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_window_and_time_constraint__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_categorical_filter__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_filter_not_in_group_by__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_time_constraint__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_window__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_window_and_time_constraint__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_categorical_filter__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_filter_not_in_group_by__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_time_constraint__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_window__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_window_and_time_constraint__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_categorical_filter__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_filter_not_in_group_by__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_time_constraint__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_window__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_window_and_time_constraint__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_categorical_filter__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_filter_not_in_group_by__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_time_constraint__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_window__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_window_and_time_constraint__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_categorical_filter__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_filter_not_in_group_by__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_time_constraint__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_window__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_window_and_time_constraint__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_categorical_filter__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_filter_not_in_group_by__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_time_constraint__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_window__query_output.txt create mode 100644 tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_window_and_time_constraint__query_output.txt diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_filter__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_filter__plan0.sql new file mode 100644 index 0000000000..6716fbea6c --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_filter__plan0.sql @@ -0,0 +1,383 @@ +-- Compute Metrics via Expressions +SELECT + CAST(subq_16.buys AS FLOAT64) / CAST(NULLIF(subq_16.visits, 0) AS FLOAT64) AS visit_buy_conversion_rate +FROM ( + -- Combine Aggregated Outputs + SELECT + MAX(subq_5.visits) AS visits + , MAX(subq_15.buys) AS buys + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_4.visits) AS visits + FROM ( + -- Pass Only Elements: ['visits',] + SELECT + subq_3.visits + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__day + , subq_2.visits + FROM ( + -- Pass Only Elements: ['visits', 'metric_time__day'] + SELECT + subq_1.metric_time__day + , subq_1.visits + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.visit__ds__day + , subq_0.visit__ds__week + , subq_0.visit__ds__month + , subq_0.visit__ds__quarter + , subq_0.visit__ds__year + , subq_0.visit__ds__extract_year + , subq_0.visit__ds__extract_quarter + , subq_0.visit__ds__extract_month + , subq_0.visit__ds__extract_day + , subq_0.visit__ds__extract_dow + , subq_0.visit__ds__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.user + , subq_0.session + , subq_0.visit__user + , subq_0.visit__session + , subq_0.referrer_id + , subq_0.visit__referrer_id + , subq_0.visits + , subq_0.visitors + FROM ( + -- Read Elements From Semantic Model 'visits_source' + SELECT + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS ds__day + , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS ds__week + , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS ds__month + , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS visit__ds__day + , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS visit__ds__week + , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS visit__ds__month + , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS visit__ds__quarter + , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS visit__ds__extract_dow + , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + WHERE metric_time__day = '2020-01-01' + ) subq_3 + ) subq_4 + ) subq_5 + CROSS JOIN ( + -- Aggregate Measures + SELECT + SUM(subq_14.buys) AS buys + FROM ( + -- Pass Only Elements: ['buys',] + SELECT + subq_13.buys + FROM ( + -- Find conversions for user within the range of INF + SELECT + subq_12.ds__day + , subq_12.metric_time__day + , subq_12.user + , subq_12.buys + , subq_12.visits + FROM ( + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + FIRST_VALUE(subq_8.visits) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visits + , FIRST_VALUE(subq_8.ds__day) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS ds__day + , FIRST_VALUE(subq_8.metric_time__day) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS metric_time__day + , FIRST_VALUE(subq_8.user) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user + , subq_11.mf_internal_uuid AS mf_internal_uuid + , subq_11.buys AS buys + FROM ( + -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user'] + SELECT + subq_7.ds__day + , subq_7.metric_time__day + , subq_7.user + , subq_7.visits + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_6.ds__day + , subq_6.ds__week + , subq_6.ds__month + , subq_6.ds__quarter + , subq_6.ds__year + , subq_6.ds__extract_year + , subq_6.ds__extract_quarter + , subq_6.ds__extract_month + , subq_6.ds__extract_day + , subq_6.ds__extract_dow + , subq_6.ds__extract_doy + , subq_6.visit__ds__day + , subq_6.visit__ds__week + , subq_6.visit__ds__month + , subq_6.visit__ds__quarter + , subq_6.visit__ds__year + , subq_6.visit__ds__extract_year + , subq_6.visit__ds__extract_quarter + , subq_6.visit__ds__extract_month + , subq_6.visit__ds__extract_day + , subq_6.visit__ds__extract_dow + , subq_6.visit__ds__extract_doy + , subq_6.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , subq_6.user + , subq_6.session + , subq_6.visit__user + , subq_6.visit__session + , subq_6.referrer_id + , subq_6.visit__referrer_id + , subq_6.visits + , subq_6.visitors + FROM ( + -- Read Elements From Semantic Model 'visits_source' + SELECT + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS ds__day + , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS ds__week + , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS ds__month + , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATETIME_TRUNC(visits_source_src_28000.ds, day) AS visit__ds__day + , DATETIME_TRUNC(visits_source_src_28000.ds, isoweek) AS visit__ds__week + , DATETIME_TRUNC(visits_source_src_28000.ds, month) AS visit__ds__month + , DATETIME_TRUNC(visits_source_src_28000.ds, quarter) AS visit__ds__quarter + , DATETIME_TRUNC(visits_source_src_28000.ds, year) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , IF(EXTRACT(dayofweek FROM visits_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM visits_source_src_28000.ds) - 1) AS visit__ds__extract_dow + , EXTRACT(dayofyear FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_6 + ) subq_7 + ) subq_8 + INNER JOIN ( + -- Add column with generated UUID + SELECT + subq_10.ds__day + , subq_10.ds__week + , subq_10.ds__month + , subq_10.ds__quarter + , subq_10.ds__year + , subq_10.ds__extract_year + , subq_10.ds__extract_quarter + , subq_10.ds__extract_month + , subq_10.ds__extract_day + , subq_10.ds__extract_dow + , subq_10.ds__extract_doy + , subq_10.buy__ds__day + , subq_10.buy__ds__week + , subq_10.buy__ds__month + , subq_10.buy__ds__quarter + , subq_10.buy__ds__year + , subq_10.buy__ds__extract_year + , subq_10.buy__ds__extract_quarter + , subq_10.buy__ds__extract_month + , subq_10.buy__ds__extract_day + , subq_10.buy__ds__extract_dow + , subq_10.buy__ds__extract_doy + , subq_10.metric_time__day + , subq_10.metric_time__week + , subq_10.metric_time__month + , subq_10.metric_time__quarter + , subq_10.metric_time__year + , subq_10.metric_time__extract_year + , subq_10.metric_time__extract_quarter + , subq_10.metric_time__extract_month + , subq_10.metric_time__extract_day + , subq_10.metric_time__extract_dow + , subq_10.metric_time__extract_doy + , subq_10.user + , subq_10.session_id + , subq_10.buy__user + , subq_10.buy__session_id + , subq_10.buys + , subq_10.buyers + , GENERATE_UUID() AS mf_internal_uuid + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_9.ds__day + , subq_9.ds__week + , subq_9.ds__month + , subq_9.ds__quarter + , subq_9.ds__year + , subq_9.ds__extract_year + , subq_9.ds__extract_quarter + , subq_9.ds__extract_month + , subq_9.ds__extract_day + , subq_9.ds__extract_dow + , subq_9.ds__extract_doy + , subq_9.buy__ds__day + , subq_9.buy__ds__week + , subq_9.buy__ds__month + , subq_9.buy__ds__quarter + , subq_9.buy__ds__year + , subq_9.buy__ds__extract_year + , subq_9.buy__ds__extract_quarter + , subq_9.buy__ds__extract_month + , subq_9.buy__ds__extract_day + , subq_9.buy__ds__extract_dow + , subq_9.buy__ds__extract_doy + , subq_9.ds__day AS metric_time__day + , subq_9.ds__week AS metric_time__week + , subq_9.ds__month AS metric_time__month + , subq_9.ds__quarter AS metric_time__quarter + , subq_9.ds__year AS metric_time__year + , subq_9.ds__extract_year AS metric_time__extract_year + , subq_9.ds__extract_quarter AS metric_time__extract_quarter + , subq_9.ds__extract_month AS metric_time__extract_month + , subq_9.ds__extract_day AS metric_time__extract_day + , subq_9.ds__extract_dow AS metric_time__extract_dow + , subq_9.ds__extract_doy AS metric_time__extract_doy + , subq_9.user + , subq_9.session_id + , subq_9.buy__user + , subq_9.buy__session_id + , subq_9.buys + , subq_9.buyers + FROM ( + -- Read Elements From Semantic Model 'buys_source' + SELECT + 1 AS buys + , buys_source_src_28000.user_id AS buyers + , DATETIME_TRUNC(buys_source_src_28000.ds, day) AS ds__day + , DATETIME_TRUNC(buys_source_src_28000.ds, isoweek) AS ds__week + , DATETIME_TRUNC(buys_source_src_28000.ds, month) AS ds__month + , DATETIME_TRUNC(buys_source_src_28000.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(buys_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM buys_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM buys_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM buys_source_src_28000.ds) AS ds__extract_doy + , DATETIME_TRUNC(buys_source_src_28000.ds, day) AS buy__ds__day + , DATETIME_TRUNC(buys_source_src_28000.ds, isoweek) AS buy__ds__week + , DATETIME_TRUNC(buys_source_src_28000.ds, month) AS buy__ds__month + , DATETIME_TRUNC(buys_source_src_28000.ds, quarter) AS buy__ds__quarter + , DATETIME_TRUNC(buys_source_src_28000.ds, year) AS buy__ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day + , IF(EXTRACT(dayofweek FROM buys_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM buys_source_src_28000.ds) - 1) AS buy__ds__extract_dow + , EXTRACT(dayofyear FROM buys_source_src_28000.ds) AS buy__ds__extract_doy + , buys_source_src_28000.user_id AS user + , buys_source_src_28000.session_id + , buys_source_src_28000.user_id AS buy__user + , buys_source_src_28000.session_id AS buy__session_id + FROM ***************************.fct_buys buys_source_src_28000 + ) subq_9 + ) subq_10 + ) subq_11 + ON + ( + subq_8.user = subq_11.user + ) AND ( + (subq_8.ds__day <= subq_11.ds__day) + ) + ) subq_12 + ) subq_13 + ) subq_14 + ) subq_15 +) subq_16 diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_filter__plan0_optimized.sql new file mode 100644 index 0000000000..ef5c271636 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/BigQuery/test_conversion_metric_with_filter__plan0_optimized.sql @@ -0,0 +1,94 @@ +-- Combine Aggregated Outputs +-- Compute Metrics via Expressions +SELECT + CAST(MAX(subq_32.buys) AS FLOAT64) / CAST(NULLIF(MAX(subq_22.visits), 0) AS FLOAT64) AS visit_buy_conversion_rate +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['visits',] + -- Aggregate Measures + SELECT + SUM(visits) AS visits + FROM ( + -- Read Elements From Semantic Model 'visits_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['visits', 'metric_time__day'] + SELECT + DATETIME_TRUNC(ds, day) AS metric_time__day + , 1 AS visits + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_19 + WHERE metric_time__day = '2020-01-01' +) subq_22 +CROSS JOIN ( + -- Find conversions for user within the range of INF + -- Pass Only Elements: ['buys',] + -- Aggregate Measures + SELECT + SUM(buys) AS buys + FROM ( + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + FIRST_VALUE(subq_25.visits) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visits + , FIRST_VALUE(subq_25.ds__day) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS ds__day + , FIRST_VALUE(subq_25.metric_time__day) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS metric_time__day + , FIRST_VALUE(subq_25.user) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user + , subq_28.mf_internal_uuid AS mf_internal_uuid + , subq_28.buys AS buys + FROM ( + -- Read Elements From Semantic Model 'visits_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user'] + SELECT + DATETIME_TRUNC(ds, day) AS ds__day + , DATETIME_TRUNC(ds, day) AS metric_time__day + , user_id AS user + , 1 AS visits + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_25 + INNER JOIN ( + -- Read Elements From Semantic Model 'buys_source' + -- Metric Time Dimension 'ds' + -- Add column with generated UUID + SELECT + DATETIME_TRUNC(ds, day) AS ds__day + , user_id AS user + , 1 AS buys + , GENERATE_UUID() AS mf_internal_uuid + FROM ***************************.fct_buys buys_source_src_28000 + ) subq_28 + ON + ( + subq_25.user = subq_28.user + ) AND ( + (subq_25.ds__day <= subq_28.ds__day) + ) + ) subq_29 +) subq_32 diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_filter__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_filter__plan0.sql new file mode 100644 index 0000000000..a0f8e702e5 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_filter__plan0.sql @@ -0,0 +1,383 @@ +-- Compute Metrics via Expressions +SELECT + CAST(subq_16.buys AS DOUBLE) / CAST(NULLIF(subq_16.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate +FROM ( + -- Combine Aggregated Outputs + SELECT + MAX(subq_5.visits) AS visits + , MAX(subq_15.buys) AS buys + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_4.visits) AS visits + FROM ( + -- Pass Only Elements: ['visits',] + SELECT + subq_3.visits + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__day + , subq_2.visits + FROM ( + -- Pass Only Elements: ['visits', 'metric_time__day'] + SELECT + subq_1.metric_time__day + , subq_1.visits + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.visit__ds__day + , subq_0.visit__ds__week + , subq_0.visit__ds__month + , subq_0.visit__ds__quarter + , subq_0.visit__ds__year + , subq_0.visit__ds__extract_year + , subq_0.visit__ds__extract_quarter + , subq_0.visit__ds__extract_month + , subq_0.visit__ds__extract_day + , subq_0.visit__ds__extract_dow + , subq_0.visit__ds__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.user + , subq_0.session + , subq_0.visit__user + , subq_0.visit__session + , subq_0.referrer_id + , subq_0.visit__referrer_id + , subq_0.visits + , subq_0.visitors + FROM ( + -- Read Elements From Semantic Model 'visits_source' + SELECT + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + WHERE metric_time__day = '2020-01-01' + ) subq_3 + ) subq_4 + ) subq_5 + CROSS JOIN ( + -- Aggregate Measures + SELECT + SUM(subq_14.buys) AS buys + FROM ( + -- Pass Only Elements: ['buys',] + SELECT + subq_13.buys + FROM ( + -- Find conversions for user within the range of INF + SELECT + subq_12.ds__day + , subq_12.metric_time__day + , subq_12.user + , subq_12.buys + , subq_12.visits + FROM ( + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + FIRST_VALUE(subq_8.visits) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visits + , FIRST_VALUE(subq_8.ds__day) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS ds__day + , FIRST_VALUE(subq_8.metric_time__day) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS metric_time__day + , FIRST_VALUE(subq_8.user) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user + , subq_11.mf_internal_uuid AS mf_internal_uuid + , subq_11.buys AS buys + FROM ( + -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user'] + SELECT + subq_7.ds__day + , subq_7.metric_time__day + , subq_7.user + , subq_7.visits + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_6.ds__day + , subq_6.ds__week + , subq_6.ds__month + , subq_6.ds__quarter + , subq_6.ds__year + , subq_6.ds__extract_year + , subq_6.ds__extract_quarter + , subq_6.ds__extract_month + , subq_6.ds__extract_day + , subq_6.ds__extract_dow + , subq_6.ds__extract_doy + , subq_6.visit__ds__day + , subq_6.visit__ds__week + , subq_6.visit__ds__month + , subq_6.visit__ds__quarter + , subq_6.visit__ds__year + , subq_6.visit__ds__extract_year + , subq_6.visit__ds__extract_quarter + , subq_6.visit__ds__extract_month + , subq_6.visit__ds__extract_day + , subq_6.visit__ds__extract_dow + , subq_6.visit__ds__extract_doy + , subq_6.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , subq_6.user + , subq_6.session + , subq_6.visit__user + , subq_6.visit__session + , subq_6.referrer_id + , subq_6.visit__referrer_id + , subq_6.visits + , subq_6.visitors + FROM ( + -- Read Elements From Semantic Model 'visits_source' + SELECT + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_6 + ) subq_7 + ) subq_8 + INNER JOIN ( + -- Add column with generated UUID + SELECT + subq_10.ds__day + , subq_10.ds__week + , subq_10.ds__month + , subq_10.ds__quarter + , subq_10.ds__year + , subq_10.ds__extract_year + , subq_10.ds__extract_quarter + , subq_10.ds__extract_month + , subq_10.ds__extract_day + , subq_10.ds__extract_dow + , subq_10.ds__extract_doy + , subq_10.buy__ds__day + , subq_10.buy__ds__week + , subq_10.buy__ds__month + , subq_10.buy__ds__quarter + , subq_10.buy__ds__year + , subq_10.buy__ds__extract_year + , subq_10.buy__ds__extract_quarter + , subq_10.buy__ds__extract_month + , subq_10.buy__ds__extract_day + , subq_10.buy__ds__extract_dow + , subq_10.buy__ds__extract_doy + , subq_10.metric_time__day + , subq_10.metric_time__week + , subq_10.metric_time__month + , subq_10.metric_time__quarter + , subq_10.metric_time__year + , subq_10.metric_time__extract_year + , subq_10.metric_time__extract_quarter + , subq_10.metric_time__extract_month + , subq_10.metric_time__extract_day + , subq_10.metric_time__extract_dow + , subq_10.metric_time__extract_doy + , subq_10.user + , subq_10.session_id + , subq_10.buy__user + , subq_10.buy__session_id + , subq_10.buys + , subq_10.buyers + , UUID() AS mf_internal_uuid + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_9.ds__day + , subq_9.ds__week + , subq_9.ds__month + , subq_9.ds__quarter + , subq_9.ds__year + , subq_9.ds__extract_year + , subq_9.ds__extract_quarter + , subq_9.ds__extract_month + , subq_9.ds__extract_day + , subq_9.ds__extract_dow + , subq_9.ds__extract_doy + , subq_9.buy__ds__day + , subq_9.buy__ds__week + , subq_9.buy__ds__month + , subq_9.buy__ds__quarter + , subq_9.buy__ds__year + , subq_9.buy__ds__extract_year + , subq_9.buy__ds__extract_quarter + , subq_9.buy__ds__extract_month + , subq_9.buy__ds__extract_day + , subq_9.buy__ds__extract_dow + , subq_9.buy__ds__extract_doy + , subq_9.ds__day AS metric_time__day + , subq_9.ds__week AS metric_time__week + , subq_9.ds__month AS metric_time__month + , subq_9.ds__quarter AS metric_time__quarter + , subq_9.ds__year AS metric_time__year + , subq_9.ds__extract_year AS metric_time__extract_year + , subq_9.ds__extract_quarter AS metric_time__extract_quarter + , subq_9.ds__extract_month AS metric_time__extract_month + , subq_9.ds__extract_day AS metric_time__extract_day + , subq_9.ds__extract_dow AS metric_time__extract_dow + , subq_9.ds__extract_doy AS metric_time__extract_doy + , subq_9.user + , subq_9.session_id + , subq_9.buy__user + , subq_9.buy__session_id + , subq_9.buys + , subq_9.buyers + FROM ( + -- Read Elements From Semantic Model 'buys_source' + SELECT + 1 AS buys + , buys_source_src_28000.user_id AS buyers + , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM buys_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM buys_source_src_28000.ds) AS buy__ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy + , buys_source_src_28000.user_id AS user + , buys_source_src_28000.session_id + , buys_source_src_28000.user_id AS buy__user + , buys_source_src_28000.session_id AS buy__session_id + FROM ***************************.fct_buys buys_source_src_28000 + ) subq_9 + ) subq_10 + ) subq_11 + ON + ( + subq_8.user = subq_11.user + ) AND ( + (subq_8.ds__day <= subq_11.ds__day) + ) + ) subq_12 + ) subq_13 + ) subq_14 + ) subq_15 +) subq_16 diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_filter__plan0_optimized.sql new file mode 100644 index 0000000000..19432d0c5e --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Databricks/test_conversion_metric_with_filter__plan0_optimized.sql @@ -0,0 +1,94 @@ +-- Combine Aggregated Outputs +-- Compute Metrics via Expressions +SELECT + CAST(MAX(subq_32.buys) AS DOUBLE) / CAST(NULLIF(MAX(subq_22.visits), 0) AS DOUBLE) AS visit_buy_conversion_rate +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['visits',] + -- Aggregate Measures + SELECT + SUM(visits) AS visits + FROM ( + -- Read Elements From Semantic Model 'visits_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['visits', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS visits + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_19 + WHERE metric_time__day = '2020-01-01' +) subq_22 +CROSS JOIN ( + -- Find conversions for user within the range of INF + -- Pass Only Elements: ['buys',] + -- Aggregate Measures + SELECT + SUM(buys) AS buys + FROM ( + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + FIRST_VALUE(subq_25.visits) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visits + , FIRST_VALUE(subq_25.ds__day) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS ds__day + , FIRST_VALUE(subq_25.metric_time__day) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS metric_time__day + , FIRST_VALUE(subq_25.user) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user + , subq_28.mf_internal_uuid AS mf_internal_uuid + , subq_28.buys AS buys + FROM ( + -- Read Elements From Semantic Model 'visits_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user'] + SELECT + DATE_TRUNC('day', ds) AS ds__day + , DATE_TRUNC('day', ds) AS metric_time__day + , user_id AS user + , 1 AS visits + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_25 + INNER JOIN ( + -- Read Elements From Semantic Model 'buys_source' + -- Metric Time Dimension 'ds' + -- Add column with generated UUID + SELECT + DATE_TRUNC('day', ds) AS ds__day + , user_id AS user + , 1 AS buys + , UUID() AS mf_internal_uuid + FROM ***************************.fct_buys buys_source_src_28000 + ) subq_28 + ON + ( + subq_25.user = subq_28.user + ) AND ( + (subq_25.ds__day <= subq_28.ds__day) + ) + ) subq_29 +) subq_32 diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_filter__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_filter__plan0.sql new file mode 100644 index 0000000000..3c2f62ba16 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_filter__plan0.sql @@ -0,0 +1,383 @@ +-- Compute Metrics via Expressions +SELECT + CAST(subq_16.buys AS DOUBLE) / CAST(NULLIF(subq_16.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate +FROM ( + -- Combine Aggregated Outputs + SELECT + MAX(subq_5.visits) AS visits + , MAX(subq_15.buys) AS buys + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_4.visits) AS visits + FROM ( + -- Pass Only Elements: ['visits',] + SELECT + subq_3.visits + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__day + , subq_2.visits + FROM ( + -- Pass Only Elements: ['visits', 'metric_time__day'] + SELECT + subq_1.metric_time__day + , subq_1.visits + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.visit__ds__day + , subq_0.visit__ds__week + , subq_0.visit__ds__month + , subq_0.visit__ds__quarter + , subq_0.visit__ds__year + , subq_0.visit__ds__extract_year + , subq_0.visit__ds__extract_quarter + , subq_0.visit__ds__extract_month + , subq_0.visit__ds__extract_day + , subq_0.visit__ds__extract_dow + , subq_0.visit__ds__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.user + , subq_0.session + , subq_0.visit__user + , subq_0.visit__session + , subq_0.referrer_id + , subq_0.visit__referrer_id + , subq_0.visits + , subq_0.visitors + FROM ( + -- Read Elements From Semantic Model 'visits_source' + SELECT + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + WHERE metric_time__day = '2020-01-01' + ) subq_3 + ) subq_4 + ) subq_5 + CROSS JOIN ( + -- Aggregate Measures + SELECT + SUM(subq_14.buys) AS buys + FROM ( + -- Pass Only Elements: ['buys',] + SELECT + subq_13.buys + FROM ( + -- Find conversions for user within the range of INF + SELECT + subq_12.ds__day + , subq_12.metric_time__day + , subq_12.user + , subq_12.buys + , subq_12.visits + FROM ( + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + FIRST_VALUE(subq_8.visits) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visits + , FIRST_VALUE(subq_8.ds__day) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS ds__day + , FIRST_VALUE(subq_8.metric_time__day) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS metric_time__day + , FIRST_VALUE(subq_8.user) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user + , subq_11.mf_internal_uuid AS mf_internal_uuid + , subq_11.buys AS buys + FROM ( + -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user'] + SELECT + subq_7.ds__day + , subq_7.metric_time__day + , subq_7.user + , subq_7.visits + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_6.ds__day + , subq_6.ds__week + , subq_6.ds__month + , subq_6.ds__quarter + , subq_6.ds__year + , subq_6.ds__extract_year + , subq_6.ds__extract_quarter + , subq_6.ds__extract_month + , subq_6.ds__extract_day + , subq_6.ds__extract_dow + , subq_6.ds__extract_doy + , subq_6.visit__ds__day + , subq_6.visit__ds__week + , subq_6.visit__ds__month + , subq_6.visit__ds__quarter + , subq_6.visit__ds__year + , subq_6.visit__ds__extract_year + , subq_6.visit__ds__extract_quarter + , subq_6.visit__ds__extract_month + , subq_6.visit__ds__extract_day + , subq_6.visit__ds__extract_dow + , subq_6.visit__ds__extract_doy + , subq_6.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , subq_6.user + , subq_6.session + , subq_6.visit__user + , subq_6.visit__session + , subq_6.referrer_id + , subq_6.visit__referrer_id + , subq_6.visits + , subq_6.visitors + FROM ( + -- Read Elements From Semantic Model 'visits_source' + SELECT + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_6 + ) subq_7 + ) subq_8 + INNER JOIN ( + -- Add column with generated UUID + SELECT + subq_10.ds__day + , subq_10.ds__week + , subq_10.ds__month + , subq_10.ds__quarter + , subq_10.ds__year + , subq_10.ds__extract_year + , subq_10.ds__extract_quarter + , subq_10.ds__extract_month + , subq_10.ds__extract_day + , subq_10.ds__extract_dow + , subq_10.ds__extract_doy + , subq_10.buy__ds__day + , subq_10.buy__ds__week + , subq_10.buy__ds__month + , subq_10.buy__ds__quarter + , subq_10.buy__ds__year + , subq_10.buy__ds__extract_year + , subq_10.buy__ds__extract_quarter + , subq_10.buy__ds__extract_month + , subq_10.buy__ds__extract_day + , subq_10.buy__ds__extract_dow + , subq_10.buy__ds__extract_doy + , subq_10.metric_time__day + , subq_10.metric_time__week + , subq_10.metric_time__month + , subq_10.metric_time__quarter + , subq_10.metric_time__year + , subq_10.metric_time__extract_year + , subq_10.metric_time__extract_quarter + , subq_10.metric_time__extract_month + , subq_10.metric_time__extract_day + , subq_10.metric_time__extract_dow + , subq_10.metric_time__extract_doy + , subq_10.user + , subq_10.session_id + , subq_10.buy__user + , subq_10.buy__session_id + , subq_10.buys + , subq_10.buyers + , GEN_RANDOM_UUID() AS mf_internal_uuid + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_9.ds__day + , subq_9.ds__week + , subq_9.ds__month + , subq_9.ds__quarter + , subq_9.ds__year + , subq_9.ds__extract_year + , subq_9.ds__extract_quarter + , subq_9.ds__extract_month + , subq_9.ds__extract_day + , subq_9.ds__extract_dow + , subq_9.ds__extract_doy + , subq_9.buy__ds__day + , subq_9.buy__ds__week + , subq_9.buy__ds__month + , subq_9.buy__ds__quarter + , subq_9.buy__ds__year + , subq_9.buy__ds__extract_year + , subq_9.buy__ds__extract_quarter + , subq_9.buy__ds__extract_month + , subq_9.buy__ds__extract_day + , subq_9.buy__ds__extract_dow + , subq_9.buy__ds__extract_doy + , subq_9.ds__day AS metric_time__day + , subq_9.ds__week AS metric_time__week + , subq_9.ds__month AS metric_time__month + , subq_9.ds__quarter AS metric_time__quarter + , subq_9.ds__year AS metric_time__year + , subq_9.ds__extract_year AS metric_time__extract_year + , subq_9.ds__extract_quarter AS metric_time__extract_quarter + , subq_9.ds__extract_month AS metric_time__extract_month + , subq_9.ds__extract_day AS metric_time__extract_day + , subq_9.ds__extract_dow AS metric_time__extract_dow + , subq_9.ds__extract_doy AS metric_time__extract_doy + , subq_9.user + , subq_9.session_id + , subq_9.buy__user + , subq_9.buy__session_id + , subq_9.buys + , subq_9.buyers + FROM ( + -- Read Elements From Semantic Model 'buys_source' + SELECT + 1 AS buys + , buys_source_src_28000.user_id AS buyers + , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy + , buys_source_src_28000.user_id AS user + , buys_source_src_28000.session_id + , buys_source_src_28000.user_id AS buy__user + , buys_source_src_28000.session_id AS buy__session_id + FROM ***************************.fct_buys buys_source_src_28000 + ) subq_9 + ) subq_10 + ) subq_11 + ON + ( + subq_8.user = subq_11.user + ) AND ( + (subq_8.ds__day <= subq_11.ds__day) + ) + ) subq_12 + ) subq_13 + ) subq_14 + ) subq_15 +) subq_16 diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_filter__plan0_optimized.sql new file mode 100644 index 0000000000..0b7b89e4ae --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_filter__plan0_optimized.sql @@ -0,0 +1,94 @@ +-- Combine Aggregated Outputs +-- Compute Metrics via Expressions +SELECT + CAST(MAX(subq_32.buys) AS DOUBLE) / CAST(NULLIF(MAX(subq_22.visits), 0) AS DOUBLE) AS visit_buy_conversion_rate +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['visits',] + -- Aggregate Measures + SELECT + SUM(visits) AS visits + FROM ( + -- Read Elements From Semantic Model 'visits_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['visits', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS visits + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_19 + WHERE metric_time__day = '2020-01-01' +) subq_22 +CROSS JOIN ( + -- Find conversions for user within the range of INF + -- Pass Only Elements: ['buys',] + -- Aggregate Measures + SELECT + SUM(buys) AS buys + FROM ( + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + FIRST_VALUE(subq_25.visits) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visits + , FIRST_VALUE(subq_25.ds__day) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS ds__day + , FIRST_VALUE(subq_25.metric_time__day) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS metric_time__day + , FIRST_VALUE(subq_25.user) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user + , subq_28.mf_internal_uuid AS mf_internal_uuid + , subq_28.buys AS buys + FROM ( + -- Read Elements From Semantic Model 'visits_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user'] + SELECT + DATE_TRUNC('day', ds) AS ds__day + , DATE_TRUNC('day', ds) AS metric_time__day + , user_id AS user + , 1 AS visits + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_25 + INNER JOIN ( + -- Read Elements From Semantic Model 'buys_source' + -- Metric Time Dimension 'ds' + -- Add column with generated UUID + SELECT + DATE_TRUNC('day', ds) AS ds__day + , user_id AS user + , 1 AS buys + , GEN_RANDOM_UUID() AS mf_internal_uuid + FROM ***************************.fct_buys buys_source_src_28000 + ) subq_28 + ON + ( + subq_25.user = subq_28.user + ) AND ( + (subq_25.ds__day <= subq_28.ds__day) + ) + ) subq_29 +) subq_32 diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_filter__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_filter__plan0.sql new file mode 100644 index 0000000000..5a0f7f1bb0 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_filter__plan0.sql @@ -0,0 +1,383 @@ +-- Compute Metrics via Expressions +SELECT + CAST(subq_16.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_16.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate +FROM ( + -- Combine Aggregated Outputs + SELECT + MAX(subq_5.visits) AS visits + , MAX(subq_15.buys) AS buys + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_4.visits) AS visits + FROM ( + -- Pass Only Elements: ['visits',] + SELECT + subq_3.visits + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__day + , subq_2.visits + FROM ( + -- Pass Only Elements: ['visits', 'metric_time__day'] + SELECT + subq_1.metric_time__day + , subq_1.visits + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.visit__ds__day + , subq_0.visit__ds__week + , subq_0.visit__ds__month + , subq_0.visit__ds__quarter + , subq_0.visit__ds__year + , subq_0.visit__ds__extract_year + , subq_0.visit__ds__extract_quarter + , subq_0.visit__ds__extract_month + , subq_0.visit__ds__extract_day + , subq_0.visit__ds__extract_dow + , subq_0.visit__ds__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.user + , subq_0.session + , subq_0.visit__user + , subq_0.visit__session + , subq_0.referrer_id + , subq_0.visit__referrer_id + , subq_0.visits + , subq_0.visitors + FROM ( + -- Read Elements From Semantic Model 'visits_source' + SELECT + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + WHERE metric_time__day = '2020-01-01' + ) subq_3 + ) subq_4 + ) subq_5 + CROSS JOIN ( + -- Aggregate Measures + SELECT + SUM(subq_14.buys) AS buys + FROM ( + -- Pass Only Elements: ['buys',] + SELECT + subq_13.buys + FROM ( + -- Find conversions for user within the range of INF + SELECT + subq_12.ds__day + , subq_12.metric_time__day + , subq_12.user + , subq_12.buys + , subq_12.visits + FROM ( + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + FIRST_VALUE(subq_8.visits) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visits + , FIRST_VALUE(subq_8.ds__day) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS ds__day + , FIRST_VALUE(subq_8.metric_time__day) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS metric_time__day + , FIRST_VALUE(subq_8.user) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user + , subq_11.mf_internal_uuid AS mf_internal_uuid + , subq_11.buys AS buys + FROM ( + -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user'] + SELECT + subq_7.ds__day + , subq_7.metric_time__day + , subq_7.user + , subq_7.visits + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_6.ds__day + , subq_6.ds__week + , subq_6.ds__month + , subq_6.ds__quarter + , subq_6.ds__year + , subq_6.ds__extract_year + , subq_6.ds__extract_quarter + , subq_6.ds__extract_month + , subq_6.ds__extract_day + , subq_6.ds__extract_dow + , subq_6.ds__extract_doy + , subq_6.visit__ds__day + , subq_6.visit__ds__week + , subq_6.visit__ds__month + , subq_6.visit__ds__quarter + , subq_6.visit__ds__year + , subq_6.visit__ds__extract_year + , subq_6.visit__ds__extract_quarter + , subq_6.visit__ds__extract_month + , subq_6.visit__ds__extract_day + , subq_6.visit__ds__extract_dow + , subq_6.visit__ds__extract_doy + , subq_6.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , subq_6.user + , subq_6.session + , subq_6.visit__user + , subq_6.visit__session + , subq_6.referrer_id + , subq_6.visit__referrer_id + , subq_6.visits + , subq_6.visitors + FROM ( + -- Read Elements From Semantic Model 'visits_source' + SELECT + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_6 + ) subq_7 + ) subq_8 + INNER JOIN ( + -- Add column with generated UUID + SELECT + subq_10.ds__day + , subq_10.ds__week + , subq_10.ds__month + , subq_10.ds__quarter + , subq_10.ds__year + , subq_10.ds__extract_year + , subq_10.ds__extract_quarter + , subq_10.ds__extract_month + , subq_10.ds__extract_day + , subq_10.ds__extract_dow + , subq_10.ds__extract_doy + , subq_10.buy__ds__day + , subq_10.buy__ds__week + , subq_10.buy__ds__month + , subq_10.buy__ds__quarter + , subq_10.buy__ds__year + , subq_10.buy__ds__extract_year + , subq_10.buy__ds__extract_quarter + , subq_10.buy__ds__extract_month + , subq_10.buy__ds__extract_day + , subq_10.buy__ds__extract_dow + , subq_10.buy__ds__extract_doy + , subq_10.metric_time__day + , subq_10.metric_time__week + , subq_10.metric_time__month + , subq_10.metric_time__quarter + , subq_10.metric_time__year + , subq_10.metric_time__extract_year + , subq_10.metric_time__extract_quarter + , subq_10.metric_time__extract_month + , subq_10.metric_time__extract_day + , subq_10.metric_time__extract_dow + , subq_10.metric_time__extract_doy + , subq_10.user + , subq_10.session_id + , subq_10.buy__user + , subq_10.buy__session_id + , subq_10.buys + , subq_10.buyers + , GEN_RANDOM_UUID() AS mf_internal_uuid + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_9.ds__day + , subq_9.ds__week + , subq_9.ds__month + , subq_9.ds__quarter + , subq_9.ds__year + , subq_9.ds__extract_year + , subq_9.ds__extract_quarter + , subq_9.ds__extract_month + , subq_9.ds__extract_day + , subq_9.ds__extract_dow + , subq_9.ds__extract_doy + , subq_9.buy__ds__day + , subq_9.buy__ds__week + , subq_9.buy__ds__month + , subq_9.buy__ds__quarter + , subq_9.buy__ds__year + , subq_9.buy__ds__extract_year + , subq_9.buy__ds__extract_quarter + , subq_9.buy__ds__extract_month + , subq_9.buy__ds__extract_day + , subq_9.buy__ds__extract_dow + , subq_9.buy__ds__extract_doy + , subq_9.ds__day AS metric_time__day + , subq_9.ds__week AS metric_time__week + , subq_9.ds__month AS metric_time__month + , subq_9.ds__quarter AS metric_time__quarter + , subq_9.ds__year AS metric_time__year + , subq_9.ds__extract_year AS metric_time__extract_year + , subq_9.ds__extract_quarter AS metric_time__extract_quarter + , subq_9.ds__extract_month AS metric_time__extract_month + , subq_9.ds__extract_day AS metric_time__extract_day + , subq_9.ds__extract_dow AS metric_time__extract_dow + , subq_9.ds__extract_doy AS metric_time__extract_doy + , subq_9.user + , subq_9.session_id + , subq_9.buy__user + , subq_9.buy__session_id + , subq_9.buys + , subq_9.buyers + FROM ( + -- Read Elements From Semantic Model 'buys_source' + SELECT + 1 AS buys + , buys_source_src_28000.user_id AS buyers + , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy + , buys_source_src_28000.user_id AS user + , buys_source_src_28000.session_id + , buys_source_src_28000.user_id AS buy__user + , buys_source_src_28000.session_id AS buy__session_id + FROM ***************************.fct_buys buys_source_src_28000 + ) subq_9 + ) subq_10 + ) subq_11 + ON + ( + subq_8.user = subq_11.user + ) AND ( + (subq_8.ds__day <= subq_11.ds__day) + ) + ) subq_12 + ) subq_13 + ) subq_14 + ) subq_15 +) subq_16 diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_filter__plan0_optimized.sql new file mode 100644 index 0000000000..e513dc9a59 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Postgres/test_conversion_metric_with_filter__plan0_optimized.sql @@ -0,0 +1,94 @@ +-- Combine Aggregated Outputs +-- Compute Metrics via Expressions +SELECT + CAST(MAX(subq_32.buys) AS DOUBLE PRECISION) / CAST(NULLIF(MAX(subq_22.visits), 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['visits',] + -- Aggregate Measures + SELECT + SUM(visits) AS visits + FROM ( + -- Read Elements From Semantic Model 'visits_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['visits', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS visits + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_19 + WHERE metric_time__day = '2020-01-01' +) subq_22 +CROSS JOIN ( + -- Find conversions for user within the range of INF + -- Pass Only Elements: ['buys',] + -- Aggregate Measures + SELECT + SUM(buys) AS buys + FROM ( + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + FIRST_VALUE(subq_25.visits) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visits + , FIRST_VALUE(subq_25.ds__day) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS ds__day + , FIRST_VALUE(subq_25.metric_time__day) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS metric_time__day + , FIRST_VALUE(subq_25.user) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user + , subq_28.mf_internal_uuid AS mf_internal_uuid + , subq_28.buys AS buys + FROM ( + -- Read Elements From Semantic Model 'visits_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user'] + SELECT + DATE_TRUNC('day', ds) AS ds__day + , DATE_TRUNC('day', ds) AS metric_time__day + , user_id AS user + , 1 AS visits + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_25 + INNER JOIN ( + -- Read Elements From Semantic Model 'buys_source' + -- Metric Time Dimension 'ds' + -- Add column with generated UUID + SELECT + DATE_TRUNC('day', ds) AS ds__day + , user_id AS user + , 1 AS buys + , GEN_RANDOM_UUID() AS mf_internal_uuid + FROM ***************************.fct_buys buys_source_src_28000 + ) subq_28 + ON + ( + subq_25.user = subq_28.user + ) AND ( + (subq_25.ds__day <= subq_28.ds__day) + ) + ) subq_29 +) subq_32 diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_filter__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_filter__plan0.sql new file mode 100644 index 0000000000..11bf8691be --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_filter__plan0.sql @@ -0,0 +1,383 @@ +-- Compute Metrics via Expressions +SELECT + CAST(subq_16.buys AS DOUBLE PRECISION) / CAST(NULLIF(subq_16.visits, 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate +FROM ( + -- Combine Aggregated Outputs + SELECT + MAX(subq_5.visits) AS visits + , MAX(subq_15.buys) AS buys + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_4.visits) AS visits + FROM ( + -- Pass Only Elements: ['visits',] + SELECT + subq_3.visits + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__day + , subq_2.visits + FROM ( + -- Pass Only Elements: ['visits', 'metric_time__day'] + SELECT + subq_1.metric_time__day + , subq_1.visits + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.visit__ds__day + , subq_0.visit__ds__week + , subq_0.visit__ds__month + , subq_0.visit__ds__quarter + , subq_0.visit__ds__year + , subq_0.visit__ds__extract_year + , subq_0.visit__ds__extract_quarter + , subq_0.visit__ds__extract_month + , subq_0.visit__ds__extract_day + , subq_0.visit__ds__extract_dow + , subq_0.visit__ds__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.user + , subq_0.session + , subq_0.visit__user + , subq_0.visit__session + , subq_0.referrer_id + , subq_0.visit__referrer_id + , subq_0.visits + , subq_0.visitors + FROM ( + -- Read Elements From Semantic Model 'visits_source' + SELECT + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + WHERE metric_time__day = '2020-01-01' + ) subq_3 + ) subq_4 + ) subq_5 + CROSS JOIN ( + -- Aggregate Measures + SELECT + SUM(subq_14.buys) AS buys + FROM ( + -- Pass Only Elements: ['buys',] + SELECT + subq_13.buys + FROM ( + -- Find conversions for user within the range of INF + SELECT + subq_12.ds__day + , subq_12.metric_time__day + , subq_12.user + , subq_12.buys + , subq_12.visits + FROM ( + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + FIRST_VALUE(subq_8.visits) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visits + , FIRST_VALUE(subq_8.ds__day) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS ds__day + , FIRST_VALUE(subq_8.metric_time__day) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS metric_time__day + , FIRST_VALUE(subq_8.user) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user + , subq_11.mf_internal_uuid AS mf_internal_uuid + , subq_11.buys AS buys + FROM ( + -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user'] + SELECT + subq_7.ds__day + , subq_7.metric_time__day + , subq_7.user + , subq_7.visits + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_6.ds__day + , subq_6.ds__week + , subq_6.ds__month + , subq_6.ds__quarter + , subq_6.ds__year + , subq_6.ds__extract_year + , subq_6.ds__extract_quarter + , subq_6.ds__extract_month + , subq_6.ds__extract_day + , subq_6.ds__extract_dow + , subq_6.ds__extract_doy + , subq_6.visit__ds__day + , subq_6.visit__ds__week + , subq_6.visit__ds__month + , subq_6.visit__ds__quarter + , subq_6.visit__ds__year + , subq_6.visit__ds__extract_year + , subq_6.visit__ds__extract_quarter + , subq_6.visit__ds__extract_month + , subq_6.visit__ds__extract_day + , subq_6.visit__ds__extract_dow + , subq_6.visit__ds__extract_doy + , subq_6.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , subq_6.user + , subq_6.session + , subq_6.visit__user + , subq_6.visit__session + , subq_6.referrer_id + , subq_6.visit__referrer_id + , subq_6.visits + , subq_6.visitors + FROM ( + -- Read Elements From Semantic Model 'visits_source' + SELECT + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , CASE WHEN EXTRACT(dow FROM visits_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM visits_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM visits_source_src_28000.ds) END AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_6 + ) subq_7 + ) subq_8 + INNER JOIN ( + -- Add column with generated UUID + SELECT + subq_10.ds__day + , subq_10.ds__week + , subq_10.ds__month + , subq_10.ds__quarter + , subq_10.ds__year + , subq_10.ds__extract_year + , subq_10.ds__extract_quarter + , subq_10.ds__extract_month + , subq_10.ds__extract_day + , subq_10.ds__extract_dow + , subq_10.ds__extract_doy + , subq_10.buy__ds__day + , subq_10.buy__ds__week + , subq_10.buy__ds__month + , subq_10.buy__ds__quarter + , subq_10.buy__ds__year + , subq_10.buy__ds__extract_year + , subq_10.buy__ds__extract_quarter + , subq_10.buy__ds__extract_month + , subq_10.buy__ds__extract_day + , subq_10.buy__ds__extract_dow + , subq_10.buy__ds__extract_doy + , subq_10.metric_time__day + , subq_10.metric_time__week + , subq_10.metric_time__month + , subq_10.metric_time__quarter + , subq_10.metric_time__year + , subq_10.metric_time__extract_year + , subq_10.metric_time__extract_quarter + , subq_10.metric_time__extract_month + , subq_10.metric_time__extract_day + , subq_10.metric_time__extract_dow + , subq_10.metric_time__extract_doy + , subq_10.user + , subq_10.session_id + , subq_10.buy__user + , subq_10.buy__session_id + , subq_10.buys + , subq_10.buyers + , CONCAT(CAST(RANDOM()*100000000 AS INT)::VARCHAR,CAST(RANDOM()*100000000 AS INT)::VARCHAR) AS mf_internal_uuid + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_9.ds__day + , subq_9.ds__week + , subq_9.ds__month + , subq_9.ds__quarter + , subq_9.ds__year + , subq_9.ds__extract_year + , subq_9.ds__extract_quarter + , subq_9.ds__extract_month + , subq_9.ds__extract_day + , subq_9.ds__extract_dow + , subq_9.ds__extract_doy + , subq_9.buy__ds__day + , subq_9.buy__ds__week + , subq_9.buy__ds__month + , subq_9.buy__ds__quarter + , subq_9.buy__ds__year + , subq_9.buy__ds__extract_year + , subq_9.buy__ds__extract_quarter + , subq_9.buy__ds__extract_month + , subq_9.buy__ds__extract_day + , subq_9.buy__ds__extract_dow + , subq_9.buy__ds__extract_doy + , subq_9.ds__day AS metric_time__day + , subq_9.ds__week AS metric_time__week + , subq_9.ds__month AS metric_time__month + , subq_9.ds__quarter AS metric_time__quarter + , subq_9.ds__year AS metric_time__year + , subq_9.ds__extract_year AS metric_time__extract_year + , subq_9.ds__extract_quarter AS metric_time__extract_quarter + , subq_9.ds__extract_month AS metric_time__extract_month + , subq_9.ds__extract_day AS metric_time__extract_day + , subq_9.ds__extract_dow AS metric_time__extract_dow + , subq_9.ds__extract_doy AS metric_time__extract_doy + , subq_9.user + , subq_9.session_id + , subq_9.buy__user + , subq_9.buy__session_id + , subq_9.buys + , subq_9.buyers + FROM ( + -- Read Elements From Semantic Model 'buys_source' + SELECT + 1 AS buys + , buys_source_src_28000.user_id AS buyers + , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM buys_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM buys_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM buys_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day + , CASE WHEN EXTRACT(dow FROM buys_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM buys_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM buys_source_src_28000.ds) END AS buy__ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy + , buys_source_src_28000.user_id AS user + , buys_source_src_28000.session_id + , buys_source_src_28000.user_id AS buy__user + , buys_source_src_28000.session_id AS buy__session_id + FROM ***************************.fct_buys buys_source_src_28000 + ) subq_9 + ) subq_10 + ) subq_11 + ON + ( + subq_8.user = subq_11.user + ) AND ( + (subq_8.ds__day <= subq_11.ds__day) + ) + ) subq_12 + ) subq_13 + ) subq_14 + ) subq_15 +) subq_16 diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_filter__plan0_optimized.sql new file mode 100644 index 0000000000..1646548e6d --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Redshift/test_conversion_metric_with_filter__plan0_optimized.sql @@ -0,0 +1,94 @@ +-- Combine Aggregated Outputs +-- Compute Metrics via Expressions +SELECT + CAST(MAX(subq_32.buys) AS DOUBLE PRECISION) / CAST(NULLIF(MAX(subq_22.visits), 0) AS DOUBLE PRECISION) AS visit_buy_conversion_rate +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['visits',] + -- Aggregate Measures + SELECT + SUM(visits) AS visits + FROM ( + -- Read Elements From Semantic Model 'visits_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['visits', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS visits + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_19 + WHERE metric_time__day = '2020-01-01' +) subq_22 +CROSS JOIN ( + -- Find conversions for user within the range of INF + -- Pass Only Elements: ['buys',] + -- Aggregate Measures + SELECT + SUM(buys) AS buys + FROM ( + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + FIRST_VALUE(subq_25.visits) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visits + , FIRST_VALUE(subq_25.ds__day) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS ds__day + , FIRST_VALUE(subq_25.metric_time__day) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS metric_time__day + , FIRST_VALUE(subq_25.user) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user + , subq_28.mf_internal_uuid AS mf_internal_uuid + , subq_28.buys AS buys + FROM ( + -- Read Elements From Semantic Model 'visits_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user'] + SELECT + DATE_TRUNC('day', ds) AS ds__day + , DATE_TRUNC('day', ds) AS metric_time__day + , user_id AS user + , 1 AS visits + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_25 + INNER JOIN ( + -- Read Elements From Semantic Model 'buys_source' + -- Metric Time Dimension 'ds' + -- Add column with generated UUID + SELECT + DATE_TRUNC('day', ds) AS ds__day + , user_id AS user + , 1 AS buys + , CONCAT(CAST(RANDOM()*100000000 AS INT)::VARCHAR,CAST(RANDOM()*100000000 AS INT)::VARCHAR) AS mf_internal_uuid + FROM ***************************.fct_buys buys_source_src_28000 + ) subq_28 + ON + ( + subq_25.user = subq_28.user + ) AND ( + (subq_25.ds__day <= subq_28.ds__day) + ) + ) subq_29 +) subq_32 diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_filter__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_filter__plan0.sql new file mode 100644 index 0000000000..d2ea77b19c --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_filter__plan0.sql @@ -0,0 +1,383 @@ +-- Compute Metrics via Expressions +SELECT + CAST(subq_16.buys AS DOUBLE) / CAST(NULLIF(subq_16.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate +FROM ( + -- Combine Aggregated Outputs + SELECT + MAX(subq_5.visits) AS visits + , MAX(subq_15.buys) AS buys + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_4.visits) AS visits + FROM ( + -- Pass Only Elements: ['visits',] + SELECT + subq_3.visits + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__day + , subq_2.visits + FROM ( + -- Pass Only Elements: ['visits', 'metric_time__day'] + SELECT + subq_1.metric_time__day + , subq_1.visits + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.visit__ds__day + , subq_0.visit__ds__week + , subq_0.visit__ds__month + , subq_0.visit__ds__quarter + , subq_0.visit__ds__year + , subq_0.visit__ds__extract_year + , subq_0.visit__ds__extract_quarter + , subq_0.visit__ds__extract_month + , subq_0.visit__ds__extract_day + , subq_0.visit__ds__extract_dow + , subq_0.visit__ds__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.user + , subq_0.session + , subq_0.visit__user + , subq_0.visit__session + , subq_0.referrer_id + , subq_0.visit__referrer_id + , subq_0.visits + , subq_0.visitors + FROM ( + -- Read Elements From Semantic Model 'visits_source' + SELECT + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + WHERE metric_time__day = '2020-01-01' + ) subq_3 + ) subq_4 + ) subq_5 + CROSS JOIN ( + -- Aggregate Measures + SELECT + SUM(subq_14.buys) AS buys + FROM ( + -- Pass Only Elements: ['buys',] + SELECT + subq_13.buys + FROM ( + -- Find conversions for user within the range of INF + SELECT + subq_12.ds__day + , subq_12.metric_time__day + , subq_12.user + , subq_12.buys + , subq_12.visits + FROM ( + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + FIRST_VALUE(subq_8.visits) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visits + , FIRST_VALUE(subq_8.ds__day) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS ds__day + , FIRST_VALUE(subq_8.metric_time__day) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS metric_time__day + , FIRST_VALUE(subq_8.user) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user + , subq_11.mf_internal_uuid AS mf_internal_uuid + , subq_11.buys AS buys + FROM ( + -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user'] + SELECT + subq_7.ds__day + , subq_7.metric_time__day + , subq_7.user + , subq_7.visits + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_6.ds__day + , subq_6.ds__week + , subq_6.ds__month + , subq_6.ds__quarter + , subq_6.ds__year + , subq_6.ds__extract_year + , subq_6.ds__extract_quarter + , subq_6.ds__extract_month + , subq_6.ds__extract_day + , subq_6.ds__extract_dow + , subq_6.ds__extract_doy + , subq_6.visit__ds__day + , subq_6.visit__ds__week + , subq_6.visit__ds__month + , subq_6.visit__ds__quarter + , subq_6.visit__ds__year + , subq_6.visit__ds__extract_year + , subq_6.visit__ds__extract_quarter + , subq_6.visit__ds__extract_month + , subq_6.visit__ds__extract_day + , subq_6.visit__ds__extract_dow + , subq_6.visit__ds__extract_doy + , subq_6.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , subq_6.user + , subq_6.session + , subq_6.visit__user + , subq_6.visit__session + , subq_6.referrer_id + , subq_6.visit__referrer_id + , subq_6.visits + , subq_6.visitors + FROM ( + -- Read Elements From Semantic Model 'visits_source' + SELECT + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(dayofweekiso FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_6 + ) subq_7 + ) subq_8 + INNER JOIN ( + -- Add column with generated UUID + SELECT + subq_10.ds__day + , subq_10.ds__week + , subq_10.ds__month + , subq_10.ds__quarter + , subq_10.ds__year + , subq_10.ds__extract_year + , subq_10.ds__extract_quarter + , subq_10.ds__extract_month + , subq_10.ds__extract_day + , subq_10.ds__extract_dow + , subq_10.ds__extract_doy + , subq_10.buy__ds__day + , subq_10.buy__ds__week + , subq_10.buy__ds__month + , subq_10.buy__ds__quarter + , subq_10.buy__ds__year + , subq_10.buy__ds__extract_year + , subq_10.buy__ds__extract_quarter + , subq_10.buy__ds__extract_month + , subq_10.buy__ds__extract_day + , subq_10.buy__ds__extract_dow + , subq_10.buy__ds__extract_doy + , subq_10.metric_time__day + , subq_10.metric_time__week + , subq_10.metric_time__month + , subq_10.metric_time__quarter + , subq_10.metric_time__year + , subq_10.metric_time__extract_year + , subq_10.metric_time__extract_quarter + , subq_10.metric_time__extract_month + , subq_10.metric_time__extract_day + , subq_10.metric_time__extract_dow + , subq_10.metric_time__extract_doy + , subq_10.user + , subq_10.session_id + , subq_10.buy__user + , subq_10.buy__session_id + , subq_10.buys + , subq_10.buyers + , UUID_STRING() AS mf_internal_uuid + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_9.ds__day + , subq_9.ds__week + , subq_9.ds__month + , subq_9.ds__quarter + , subq_9.ds__year + , subq_9.ds__extract_year + , subq_9.ds__extract_quarter + , subq_9.ds__extract_month + , subq_9.ds__extract_day + , subq_9.ds__extract_dow + , subq_9.ds__extract_doy + , subq_9.buy__ds__day + , subq_9.buy__ds__week + , subq_9.buy__ds__month + , subq_9.buy__ds__quarter + , subq_9.buy__ds__year + , subq_9.buy__ds__extract_year + , subq_9.buy__ds__extract_quarter + , subq_9.buy__ds__extract_month + , subq_9.buy__ds__extract_day + , subq_9.buy__ds__extract_dow + , subq_9.buy__ds__extract_doy + , subq_9.ds__day AS metric_time__day + , subq_9.ds__week AS metric_time__week + , subq_9.ds__month AS metric_time__month + , subq_9.ds__quarter AS metric_time__quarter + , subq_9.ds__year AS metric_time__year + , subq_9.ds__extract_year AS metric_time__extract_year + , subq_9.ds__extract_quarter AS metric_time__extract_quarter + , subq_9.ds__extract_month AS metric_time__extract_month + , subq_9.ds__extract_day AS metric_time__extract_day + , subq_9.ds__extract_dow AS metric_time__extract_dow + , subq_9.ds__extract_doy AS metric_time__extract_doy + , subq_9.user + , subq_9.session_id + , subq_9.buy__user + , subq_9.buy__session_id + , subq_9.buys + , subq_9.buyers + FROM ( + -- Read Elements From Semantic Model 'buys_source' + SELECT + 1 AS buys + , buys_source_src_28000.user_id AS buyers + , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM buys_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day + , EXTRACT(dayofweekiso FROM buys_source_src_28000.ds) AS buy__ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy + , buys_source_src_28000.user_id AS user + , buys_source_src_28000.session_id + , buys_source_src_28000.user_id AS buy__user + , buys_source_src_28000.session_id AS buy__session_id + FROM ***************************.fct_buys buys_source_src_28000 + ) subq_9 + ) subq_10 + ) subq_11 + ON + ( + subq_8.user = subq_11.user + ) AND ( + (subq_8.ds__day <= subq_11.ds__day) + ) + ) subq_12 + ) subq_13 + ) subq_14 + ) subq_15 +) subq_16 diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_filter__plan0_optimized.sql new file mode 100644 index 0000000000..e1242849d6 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Snowflake/test_conversion_metric_with_filter__plan0_optimized.sql @@ -0,0 +1,94 @@ +-- Combine Aggregated Outputs +-- Compute Metrics via Expressions +SELECT + CAST(MAX(subq_32.buys) AS DOUBLE) / CAST(NULLIF(MAX(subq_22.visits), 0) AS DOUBLE) AS visit_buy_conversion_rate +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['visits',] + -- Aggregate Measures + SELECT + SUM(visits) AS visits + FROM ( + -- Read Elements From Semantic Model 'visits_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['visits', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS visits + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_19 + WHERE metric_time__day = '2020-01-01' +) subq_22 +CROSS JOIN ( + -- Find conversions for user within the range of INF + -- Pass Only Elements: ['buys',] + -- Aggregate Measures + SELECT + SUM(buys) AS buys + FROM ( + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + FIRST_VALUE(subq_25.visits) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visits + , FIRST_VALUE(subq_25.ds__day) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS ds__day + , FIRST_VALUE(subq_25.metric_time__day) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS metric_time__day + , FIRST_VALUE(subq_25.user) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user + , subq_28.mf_internal_uuid AS mf_internal_uuid + , subq_28.buys AS buys + FROM ( + -- Read Elements From Semantic Model 'visits_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user'] + SELECT + DATE_TRUNC('day', ds) AS ds__day + , DATE_TRUNC('day', ds) AS metric_time__day + , user_id AS user + , 1 AS visits + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_25 + INNER JOIN ( + -- Read Elements From Semantic Model 'buys_source' + -- Metric Time Dimension 'ds' + -- Add column with generated UUID + SELECT + DATE_TRUNC('day', ds) AS ds__day + , user_id AS user + , 1 AS buys + , UUID_STRING() AS mf_internal_uuid + FROM ***************************.fct_buys buys_source_src_28000 + ) subq_28 + ON + ( + subq_25.user = subq_28.user + ) AND ( + (subq_25.ds__day <= subq_28.ds__day) + ) + ) subq_29 +) subq_32 diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_filter__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_filter__plan0.sql new file mode 100644 index 0000000000..1931c024fa --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_filter__plan0.sql @@ -0,0 +1,383 @@ +-- Compute Metrics via Expressions +SELECT + CAST(subq_16.buys AS DOUBLE) / CAST(NULLIF(subq_16.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate +FROM ( + -- Combine Aggregated Outputs + SELECT + MAX(subq_5.visits) AS visits + , MAX(subq_15.buys) AS buys + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_4.visits) AS visits + FROM ( + -- Pass Only Elements: ['visits',] + SELECT + subq_3.visits + FROM ( + -- Constrain Output with WHERE + SELECT + subq_2.metric_time__day + , subq_2.visits + FROM ( + -- Pass Only Elements: ['visits', 'metric_time__day'] + SELECT + subq_1.metric_time__day + , subq_1.visits + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.visit__ds__day + , subq_0.visit__ds__week + , subq_0.visit__ds__month + , subq_0.visit__ds__quarter + , subq_0.visit__ds__year + , subq_0.visit__ds__extract_year + , subq_0.visit__ds__extract_quarter + , subq_0.visit__ds__extract_month + , subq_0.visit__ds__extract_day + , subq_0.visit__ds__extract_dow + , subq_0.visit__ds__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.user + , subq_0.session + , subq_0.visit__user + , subq_0.visit__session + , subq_0.referrer_id + , subq_0.visit__referrer_id + , subq_0.visits + , subq_0.visitors + FROM ( + -- Read Elements From Semantic Model 'visits_source' + SELECT + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + WHERE metric_time__day = '2020-01-01' + ) subq_3 + ) subq_4 + ) subq_5 + CROSS JOIN ( + -- Aggregate Measures + SELECT + SUM(subq_14.buys) AS buys + FROM ( + -- Pass Only Elements: ['buys',] + SELECT + subq_13.buys + FROM ( + -- Find conversions for user within the range of INF + SELECT + subq_12.ds__day + , subq_12.metric_time__day + , subq_12.user + , subq_12.buys + , subq_12.visits + FROM ( + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + FIRST_VALUE(subq_8.visits) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visits + , FIRST_VALUE(subq_8.ds__day) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS ds__day + , FIRST_VALUE(subq_8.metric_time__day) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS metric_time__day + , FIRST_VALUE(subq_8.user) OVER ( + PARTITION BY + subq_11.user + , subq_11.ds__day + , subq_11.mf_internal_uuid + ORDER BY subq_8.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user + , subq_11.mf_internal_uuid AS mf_internal_uuid + , subq_11.buys AS buys + FROM ( + -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user'] + SELECT + subq_7.ds__day + , subq_7.metric_time__day + , subq_7.user + , subq_7.visits + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_6.ds__day + , subq_6.ds__week + , subq_6.ds__month + , subq_6.ds__quarter + , subq_6.ds__year + , subq_6.ds__extract_year + , subq_6.ds__extract_quarter + , subq_6.ds__extract_month + , subq_6.ds__extract_day + , subq_6.ds__extract_dow + , subq_6.ds__extract_doy + , subq_6.visit__ds__day + , subq_6.visit__ds__week + , subq_6.visit__ds__month + , subq_6.visit__ds__quarter + , subq_6.visit__ds__year + , subq_6.visit__ds__extract_year + , subq_6.visit__ds__extract_quarter + , subq_6.visit__ds__extract_month + , subq_6.visit__ds__extract_day + , subq_6.visit__ds__extract_dow + , subq_6.visit__ds__extract_doy + , subq_6.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , subq_6.user + , subq_6.session + , subq_6.visit__user + , subq_6.visit__session + , subq_6.referrer_id + , subq_6.visit__referrer_id + , subq_6.visits + , subq_6.visitors + FROM ( + -- Read Elements From Semantic Model 'visits_source' + SELECT + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_6 + ) subq_7 + ) subq_8 + INNER JOIN ( + -- Add column with generated UUID + SELECT + subq_10.ds__day + , subq_10.ds__week + , subq_10.ds__month + , subq_10.ds__quarter + , subq_10.ds__year + , subq_10.ds__extract_year + , subq_10.ds__extract_quarter + , subq_10.ds__extract_month + , subq_10.ds__extract_day + , subq_10.ds__extract_dow + , subq_10.ds__extract_doy + , subq_10.buy__ds__day + , subq_10.buy__ds__week + , subq_10.buy__ds__month + , subq_10.buy__ds__quarter + , subq_10.buy__ds__year + , subq_10.buy__ds__extract_year + , subq_10.buy__ds__extract_quarter + , subq_10.buy__ds__extract_month + , subq_10.buy__ds__extract_day + , subq_10.buy__ds__extract_dow + , subq_10.buy__ds__extract_doy + , subq_10.metric_time__day + , subq_10.metric_time__week + , subq_10.metric_time__month + , subq_10.metric_time__quarter + , subq_10.metric_time__year + , subq_10.metric_time__extract_year + , subq_10.metric_time__extract_quarter + , subq_10.metric_time__extract_month + , subq_10.metric_time__extract_day + , subq_10.metric_time__extract_dow + , subq_10.metric_time__extract_doy + , subq_10.user + , subq_10.session_id + , subq_10.buy__user + , subq_10.buy__session_id + , subq_10.buys + , subq_10.buyers + , uuid() AS mf_internal_uuid + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_9.ds__day + , subq_9.ds__week + , subq_9.ds__month + , subq_9.ds__quarter + , subq_9.ds__year + , subq_9.ds__extract_year + , subq_9.ds__extract_quarter + , subq_9.ds__extract_month + , subq_9.ds__extract_day + , subq_9.ds__extract_dow + , subq_9.ds__extract_doy + , subq_9.buy__ds__day + , subq_9.buy__ds__week + , subq_9.buy__ds__month + , subq_9.buy__ds__quarter + , subq_9.buy__ds__year + , subq_9.buy__ds__extract_year + , subq_9.buy__ds__extract_quarter + , subq_9.buy__ds__extract_month + , subq_9.buy__ds__extract_day + , subq_9.buy__ds__extract_dow + , subq_9.buy__ds__extract_doy + , subq_9.ds__day AS metric_time__day + , subq_9.ds__week AS metric_time__week + , subq_9.ds__month AS metric_time__month + , subq_9.ds__quarter AS metric_time__quarter + , subq_9.ds__year AS metric_time__year + , subq_9.ds__extract_year AS metric_time__extract_year + , subq_9.ds__extract_quarter AS metric_time__extract_quarter + , subq_9.ds__extract_month AS metric_time__extract_month + , subq_9.ds__extract_day AS metric_time__extract_day + , subq_9.ds__extract_dow AS metric_time__extract_dow + , subq_9.ds__extract_doy AS metric_time__extract_doy + , subq_9.user + , subq_9.session_id + , subq_9.buy__user + , subq_9.buy__session_id + , subq_9.buys + , subq_9.buyers + FROM ( + -- Read Elements From Semantic Model 'buys_source' + SELECT + 1 AS buys + , buys_source_src_28000.user_id AS buyers + , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM buys_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM buys_source_src_28000.ds) AS buy__ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy + , buys_source_src_28000.user_id AS user + , buys_source_src_28000.session_id + , buys_source_src_28000.user_id AS buy__user + , buys_source_src_28000.session_id AS buy__session_id + FROM ***************************.fct_buys buys_source_src_28000 + ) subq_9 + ) subq_10 + ) subq_11 + ON + ( + subq_8.user = subq_11.user + ) AND ( + (subq_8.ds__day <= subq_11.ds__day) + ) + ) subq_12 + ) subq_13 + ) subq_14 + ) subq_15 +) subq_16 diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_filter__plan0_optimized.sql new file mode 100644 index 0000000000..c169f029ec --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/Trino/test_conversion_metric_with_filter__plan0_optimized.sql @@ -0,0 +1,94 @@ +-- Combine Aggregated Outputs +-- Compute Metrics via Expressions +SELECT + CAST(MAX(subq_32.buys) AS DOUBLE) / CAST(NULLIF(MAX(subq_22.visits), 0) AS DOUBLE) AS visit_buy_conversion_rate +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['visits',] + -- Aggregate Measures + SELECT + SUM(visits) AS visits + FROM ( + -- Read Elements From Semantic Model 'visits_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['visits', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS visits + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_19 + WHERE metric_time__day = '2020-01-01' +) subq_22 +CROSS JOIN ( + -- Find conversions for user within the range of INF + -- Pass Only Elements: ['buys',] + -- Aggregate Measures + SELECT + SUM(buys) AS buys + FROM ( + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + FIRST_VALUE(subq_25.visits) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visits + , FIRST_VALUE(subq_25.ds__day) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS ds__day + , FIRST_VALUE(subq_25.metric_time__day) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS metric_time__day + , FIRST_VALUE(subq_25.user) OVER ( + PARTITION BY + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user + , subq_28.mf_internal_uuid AS mf_internal_uuid + , subq_28.buys AS buys + FROM ( + -- Read Elements From Semantic Model 'visits_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user'] + SELECT + DATE_TRUNC('day', ds) AS ds__day + , DATE_TRUNC('day', ds) AS metric_time__day + , user_id AS user + , 1 AS visits + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_25 + INNER JOIN ( + -- Read Elements From Semantic Model 'buys_source' + -- Metric Time Dimension 'ds' + -- Add column with generated UUID + SELECT + DATE_TRUNC('day', ds) AS ds__day + , user_id AS user + , 1 AS buys + , uuid() AS mf_internal_uuid + FROM ***************************.fct_buys buys_source_src_28000 + ) subq_28 + ON + ( + subq_25.user = subq_28.user + ) AND ( + (subq_25.ds__day <= subq_28.ds__day) + ) + ) subq_29 +) subq_32 diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric__query_output.txt new file mode 100644 index 0000000000..d59c3ac1da --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric__query_output.txt @@ -0,0 +1,10 @@ +metric_time__day visit_buy_conversion_rate +------------------- --------------------------- +2020-01-01T00:00:00 0.50 +2020-01-02T00:00:00 0.50 +2020-01-03T00:00:00 0.67 +2020-01-04T00:00:00 None +2020-01-06T00:00:00 None +2020-01-07T00:00:00 1.00 +2020-01-10T00:00:00 1.00 +2020-01-12T00:00:00 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_categorical_filter__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_categorical_filter__query_output.txt new file mode 100644 index 0000000000..0f39eb3436 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_categorical_filter__query_output.txt @@ -0,0 +1,11 @@ +metric_time__day visit__referrer_id visit_buy_conversion_rate +------------------- -------------------- --------------------------- +2020-01-01T00:00:00 fb_ad_1 1.00 +2020-01-01T00:00:00 homepage_1 None +2020-01-02T00:00:00 fb_ad_1 None +2020-01-02T00:00:00 homepage_1 None +2020-01-02T00:00:00 user_2 None +2020-01-03T00:00:00 fb_ad_1 1.00 +2020-01-03T00:00:00 google_ad_1 None +2020-01-07T00:00:00 fb_ad_2 None +2020-01-10T00:00:00 google_ad_1 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_filter_not_in_group_by__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_filter_not_in_group_by__query_output.txt new file mode 100644 index 0000000000..e3046748a3 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_filter_not_in_group_by__query_output.txt @@ -0,0 +1,3 @@ + visit_buy_conversions +----------------------- + 3 diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_time_constraint__query_output.txt new file mode 100644 index 0000000000..0cba1a13ab --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_time_constraint__query_output.txt @@ -0,0 +1,6 @@ +visit__referrer_id visit_buy_conversion_rate +-------------------- --------------------------- +fb_ad_1 1.00 +fb_ad_3 None +homepage_1 None +user_2 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_window__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_window__query_output.txt new file mode 100644 index 0000000000..294fbf9259 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_window__query_output.txt @@ -0,0 +1,10 @@ +metric_time__day visit_buy_conversion_rate_7days +------------------- --------------------------------- +2020-01-01T00:00:00 0.50 +2020-01-02T00:00:00 0.50 +2020-01-03T00:00:00 0.67 +2020-01-04T00:00:00 None +2020-01-06T00:00:00 None +2020-01-07T00:00:00 1.00 +2020-01-10T00:00:00 1.00 +2020-01-12T00:00:00 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_window_and_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_window_and_time_constraint__query_output.txt new file mode 100644 index 0000000000..ee14ea3a19 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/BigQuery/test_conversion_metric_with_window_and_time_constraint__query_output.txt @@ -0,0 +1,8 @@ +metric_time__day visit__referrer_id visit_buy_conversion_rate_7days +------------------- -------------------- --------------------------------- +2020-01-01T00:00:00 fb_ad_1 2.00 +2020-01-01T00:00:00 homepage_1 None +2020-01-02T00:00:00 fb_ad_1 None +2020-01-02T00:00:00 fb_ad_3 None +2020-01-02T00:00:00 homepage_1 None +2020-01-02T00:00:00 user_2 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric__query_output.txt new file mode 100644 index 0000000000..d59c3ac1da --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric__query_output.txt @@ -0,0 +1,10 @@ +metric_time__day visit_buy_conversion_rate +------------------- --------------------------- +2020-01-01T00:00:00 0.50 +2020-01-02T00:00:00 0.50 +2020-01-03T00:00:00 0.67 +2020-01-04T00:00:00 None +2020-01-06T00:00:00 None +2020-01-07T00:00:00 1.00 +2020-01-10T00:00:00 1.00 +2020-01-12T00:00:00 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_categorical_filter__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_categorical_filter__query_output.txt new file mode 100644 index 0000000000..f01a3b3588 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_categorical_filter__query_output.txt @@ -0,0 +1,10 @@ +metric_time__day visit__referrer_id visit_buy_conversion_rate +------------------- -------------------- --------------------------- +2020-01-01T00:00:00 fb_ad_1 1.00 +2020-01-01T00:00:00 homepage_1 None +2020-01-02T00:00:00 fb_ad_1 1.00 +2020-01-02T00:00:00 homepage_1 None +2020-01-03T00:00:00 fb_ad_1 1.00 +2020-01-03T00:00:00 google_ad_1 None +2020-01-07T00:00:00 fb_ad_2 None +2020-01-10T00:00:00 google_ad_1 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_filter_not_in_group_by__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_filter_not_in_group_by__query_output.txt new file mode 100644 index 0000000000..e3046748a3 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_filter_not_in_group_by__query_output.txt @@ -0,0 +1,3 @@ + visit_buy_conversions +----------------------- + 3 diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_time_constraint__query_output.txt new file mode 100644 index 0000000000..560911418a --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_time_constraint__query_output.txt @@ -0,0 +1,5 @@ +visit__referrer_id visit_buy_conversion_rate +-------------------- --------------------------- +fb_ad_1 1.50 +fb_ad_3 None +homepage_1 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_window__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_window__query_output.txt new file mode 100644 index 0000000000..294fbf9259 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_window__query_output.txt @@ -0,0 +1,10 @@ +metric_time__day visit_buy_conversion_rate_7days +------------------- --------------------------------- +2020-01-01T00:00:00 0.50 +2020-01-02T00:00:00 0.50 +2020-01-03T00:00:00 0.67 +2020-01-04T00:00:00 None +2020-01-06T00:00:00 None +2020-01-07T00:00:00 1.00 +2020-01-10T00:00:00 1.00 +2020-01-12T00:00:00 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_window_and_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_window_and_time_constraint__query_output.txt new file mode 100644 index 0000000000..ca279ccd92 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Databricks/test_conversion_metric_with_window_and_time_constraint__query_output.txt @@ -0,0 +1,7 @@ +metric_time__day visit__referrer_id visit_buy_conversion_rate_7days +------------------- -------------------- --------------------------------- +2020-01-01T00:00:00 fb_ad_1 2.00 +2020-01-01T00:00:00 homepage_1 None +2020-01-02T00:00:00 fb_ad_1 1.00 +2020-01-02T00:00:00 fb_ad_3 None +2020-01-02T00:00:00 homepage_1 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric__query_output.txt new file mode 100644 index 0000000000..d59c3ac1da --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric__query_output.txt @@ -0,0 +1,10 @@ +metric_time__day visit_buy_conversion_rate +------------------- --------------------------- +2020-01-01T00:00:00 0.50 +2020-01-02T00:00:00 0.50 +2020-01-03T00:00:00 0.67 +2020-01-04T00:00:00 None +2020-01-06T00:00:00 None +2020-01-07T00:00:00 1.00 +2020-01-10T00:00:00 1.00 +2020-01-12T00:00:00 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_categorical_filter__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_categorical_filter__query_output.txt new file mode 100644 index 0000000000..f01a3b3588 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_categorical_filter__query_output.txt @@ -0,0 +1,10 @@ +metric_time__day visit__referrer_id visit_buy_conversion_rate +------------------- -------------------- --------------------------- +2020-01-01T00:00:00 fb_ad_1 1.00 +2020-01-01T00:00:00 homepage_1 None +2020-01-02T00:00:00 fb_ad_1 1.00 +2020-01-02T00:00:00 homepage_1 None +2020-01-03T00:00:00 fb_ad_1 1.00 +2020-01-03T00:00:00 google_ad_1 None +2020-01-07T00:00:00 fb_ad_2 None +2020-01-10T00:00:00 google_ad_1 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_filter_not_in_group_by__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_filter_not_in_group_by__query_output.txt new file mode 100644 index 0000000000..e3046748a3 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_filter_not_in_group_by__query_output.txt @@ -0,0 +1,3 @@ + visit_buy_conversions +----------------------- + 3 diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_time_constraint__query_output.txt new file mode 100644 index 0000000000..0cba1a13ab --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_time_constraint__query_output.txt @@ -0,0 +1,6 @@ +visit__referrer_id visit_buy_conversion_rate +-------------------- --------------------------- +fb_ad_1 1.00 +fb_ad_3 None +homepage_1 None +user_2 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_window__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_window__query_output.txt new file mode 100644 index 0000000000..294fbf9259 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_window__query_output.txt @@ -0,0 +1,10 @@ +metric_time__day visit_buy_conversion_rate_7days +------------------- --------------------------------- +2020-01-01T00:00:00 0.50 +2020-01-02T00:00:00 0.50 +2020-01-03T00:00:00 0.67 +2020-01-04T00:00:00 None +2020-01-06T00:00:00 None +2020-01-07T00:00:00 1.00 +2020-01-10T00:00:00 1.00 +2020-01-12T00:00:00 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_window_and_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_window_and_time_constraint__query_output.txt new file mode 100644 index 0000000000..ee14ea3a19 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/DuckDB/test_conversion_metric_with_window_and_time_constraint__query_output.txt @@ -0,0 +1,8 @@ +metric_time__day visit__referrer_id visit_buy_conversion_rate_7days +------------------- -------------------- --------------------------------- +2020-01-01T00:00:00 fb_ad_1 2.00 +2020-01-01T00:00:00 homepage_1 None +2020-01-02T00:00:00 fb_ad_1 None +2020-01-02T00:00:00 fb_ad_3 None +2020-01-02T00:00:00 homepage_1 None +2020-01-02T00:00:00 user_2 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric__query_output.txt new file mode 100644 index 0000000000..d59c3ac1da --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric__query_output.txt @@ -0,0 +1,10 @@ +metric_time__day visit_buy_conversion_rate +------------------- --------------------------- +2020-01-01T00:00:00 0.50 +2020-01-02T00:00:00 0.50 +2020-01-03T00:00:00 0.67 +2020-01-04T00:00:00 None +2020-01-06T00:00:00 None +2020-01-07T00:00:00 1.00 +2020-01-10T00:00:00 1.00 +2020-01-12T00:00:00 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_categorical_filter__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_categorical_filter__query_output.txt new file mode 100644 index 0000000000..f01a3b3588 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_categorical_filter__query_output.txt @@ -0,0 +1,10 @@ +metric_time__day visit__referrer_id visit_buy_conversion_rate +------------------- -------------------- --------------------------- +2020-01-01T00:00:00 fb_ad_1 1.00 +2020-01-01T00:00:00 homepage_1 None +2020-01-02T00:00:00 fb_ad_1 1.00 +2020-01-02T00:00:00 homepage_1 None +2020-01-03T00:00:00 fb_ad_1 1.00 +2020-01-03T00:00:00 google_ad_1 None +2020-01-07T00:00:00 fb_ad_2 None +2020-01-10T00:00:00 google_ad_1 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_filter_not_in_group_by__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_filter_not_in_group_by__query_output.txt new file mode 100644 index 0000000000..e3046748a3 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_filter_not_in_group_by__query_output.txt @@ -0,0 +1,3 @@ + visit_buy_conversions +----------------------- + 3 diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_time_constraint__query_output.txt new file mode 100644 index 0000000000..0cba1a13ab --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_time_constraint__query_output.txt @@ -0,0 +1,6 @@ +visit__referrer_id visit_buy_conversion_rate +-------------------- --------------------------- +fb_ad_1 1.00 +fb_ad_3 None +homepage_1 None +user_2 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_window__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_window__query_output.txt new file mode 100644 index 0000000000..294fbf9259 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_window__query_output.txt @@ -0,0 +1,10 @@ +metric_time__day visit_buy_conversion_rate_7days +------------------- --------------------------------- +2020-01-01T00:00:00 0.50 +2020-01-02T00:00:00 0.50 +2020-01-03T00:00:00 0.67 +2020-01-04T00:00:00 None +2020-01-06T00:00:00 None +2020-01-07T00:00:00 1.00 +2020-01-10T00:00:00 1.00 +2020-01-12T00:00:00 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_window_and_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_window_and_time_constraint__query_output.txt new file mode 100644 index 0000000000..ee14ea3a19 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Postgres/test_conversion_metric_with_window_and_time_constraint__query_output.txt @@ -0,0 +1,8 @@ +metric_time__day visit__referrer_id visit_buy_conversion_rate_7days +------------------- -------------------- --------------------------------- +2020-01-01T00:00:00 fb_ad_1 2.00 +2020-01-01T00:00:00 homepage_1 None +2020-01-02T00:00:00 fb_ad_1 None +2020-01-02T00:00:00 fb_ad_3 None +2020-01-02T00:00:00 homepage_1 None +2020-01-02T00:00:00 user_2 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric__query_output.txt new file mode 100644 index 0000000000..d59c3ac1da --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric__query_output.txt @@ -0,0 +1,10 @@ +metric_time__day visit_buy_conversion_rate +------------------- --------------------------- +2020-01-01T00:00:00 0.50 +2020-01-02T00:00:00 0.50 +2020-01-03T00:00:00 0.67 +2020-01-04T00:00:00 None +2020-01-06T00:00:00 None +2020-01-07T00:00:00 1.00 +2020-01-10T00:00:00 1.00 +2020-01-12T00:00:00 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_categorical_filter__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_categorical_filter__query_output.txt new file mode 100644 index 0000000000..f01a3b3588 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_categorical_filter__query_output.txt @@ -0,0 +1,10 @@ +metric_time__day visit__referrer_id visit_buy_conversion_rate +------------------- -------------------- --------------------------- +2020-01-01T00:00:00 fb_ad_1 1.00 +2020-01-01T00:00:00 homepage_1 None +2020-01-02T00:00:00 fb_ad_1 1.00 +2020-01-02T00:00:00 homepage_1 None +2020-01-03T00:00:00 fb_ad_1 1.00 +2020-01-03T00:00:00 google_ad_1 None +2020-01-07T00:00:00 fb_ad_2 None +2020-01-10T00:00:00 google_ad_1 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_filter_not_in_group_by__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_filter_not_in_group_by__query_output.txt new file mode 100644 index 0000000000..e3046748a3 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_filter_not_in_group_by__query_output.txt @@ -0,0 +1,3 @@ + visit_buy_conversions +----------------------- + 3 diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_time_constraint__query_output.txt new file mode 100644 index 0000000000..560911418a --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_time_constraint__query_output.txt @@ -0,0 +1,5 @@ +visit__referrer_id visit_buy_conversion_rate +-------------------- --------------------------- +fb_ad_1 1.50 +fb_ad_3 None +homepage_1 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_window__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_window__query_output.txt new file mode 100644 index 0000000000..294fbf9259 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_window__query_output.txt @@ -0,0 +1,10 @@ +metric_time__day visit_buy_conversion_rate_7days +------------------- --------------------------------- +2020-01-01T00:00:00 0.50 +2020-01-02T00:00:00 0.50 +2020-01-03T00:00:00 0.67 +2020-01-04T00:00:00 None +2020-01-06T00:00:00 None +2020-01-07T00:00:00 1.00 +2020-01-10T00:00:00 1.00 +2020-01-12T00:00:00 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_window_and_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_window_and_time_constraint__query_output.txt new file mode 100644 index 0000000000..ca279ccd92 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Redshift/test_conversion_metric_with_window_and_time_constraint__query_output.txt @@ -0,0 +1,7 @@ +metric_time__day visit__referrer_id visit_buy_conversion_rate_7days +------------------- -------------------- --------------------------------- +2020-01-01T00:00:00 fb_ad_1 2.00 +2020-01-01T00:00:00 homepage_1 None +2020-01-02T00:00:00 fb_ad_1 1.00 +2020-01-02T00:00:00 fb_ad_3 None +2020-01-02T00:00:00 homepage_1 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric__query_output.txt new file mode 100644 index 0000000000..57e6611f5c --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric__query_output.txt @@ -0,0 +1,10 @@ +METRIC_TIME__DAY VISIT_BUY_CONVERSION_RATE +------------------- --------------------------- +2020-01-01T00:00:00 0.50 +2020-01-02T00:00:00 0.50 +2020-01-03T00:00:00 0.67 +2020-01-04T00:00:00 None +2020-01-06T00:00:00 None +2020-01-07T00:00:00 1.00 +2020-01-10T00:00:00 1.00 +2020-01-12T00:00:00 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_categorical_filter__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_categorical_filter__query_output.txt new file mode 100644 index 0000000000..9a63af0a25 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_categorical_filter__query_output.txt @@ -0,0 +1,10 @@ +METRIC_TIME__DAY VISIT__REFERRER_ID VISIT_BUY_CONVERSION_RATE +------------------- -------------------- --------------------------- +2020-01-01T00:00:00 fb_ad_1 1.00 +2020-01-01T00:00:00 homepage_1 None +2020-01-02T00:00:00 fb_ad_1 1.00 +2020-01-02T00:00:00 homepage_1 None +2020-01-03T00:00:00 fb_ad_1 1.00 +2020-01-03T00:00:00 google_ad_1 None +2020-01-07T00:00:00 fb_ad_2 None +2020-01-10T00:00:00 google_ad_1 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_filter_not_in_group_by__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_filter_not_in_group_by__query_output.txt new file mode 100644 index 0000000000..9cbe5f4439 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_filter_not_in_group_by__query_output.txt @@ -0,0 +1,3 @@ + VISIT_BUY_CONVERSIONS +----------------------- + 3 diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_time_constraint__query_output.txt new file mode 100644 index 0000000000..a8c7a45a32 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_time_constraint__query_output.txt @@ -0,0 +1,5 @@ +VISIT__REFERRER_ID VISIT_BUY_CONVERSION_RATE +-------------------- --------------------------- +fb_ad_1 1.50 +fb_ad_3 None +homepage_1 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_window__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_window__query_output.txt new file mode 100644 index 0000000000..1d3f1dd15a --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_window__query_output.txt @@ -0,0 +1,10 @@ +METRIC_TIME__DAY VISIT_BUY_CONVERSION_RATE_7DAYS +------------------- --------------------------------- +2020-01-01T00:00:00 0.50 +2020-01-02T00:00:00 0.50 +2020-01-03T00:00:00 0.67 +2020-01-04T00:00:00 None +2020-01-06T00:00:00 None +2020-01-07T00:00:00 1.00 +2020-01-10T00:00:00 1.00 +2020-01-12T00:00:00 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_window_and_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_window_and_time_constraint__query_output.txt new file mode 100644 index 0000000000..ebb836f0a2 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Snowflake/test_conversion_metric_with_window_and_time_constraint__query_output.txt @@ -0,0 +1,7 @@ +METRIC_TIME__DAY VISIT__REFERRER_ID VISIT_BUY_CONVERSION_RATE_7DAYS +------------------- -------------------- --------------------------------- +2020-01-01T00:00:00 fb_ad_1 2.00 +2020-01-01T00:00:00 homepage_1 None +2020-01-02T00:00:00 fb_ad_1 1.00 +2020-01-02T00:00:00 fb_ad_3 None +2020-01-02T00:00:00 homepage_1 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric__query_output.txt new file mode 100644 index 0000000000..d59c3ac1da --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric__query_output.txt @@ -0,0 +1,10 @@ +metric_time__day visit_buy_conversion_rate +------------------- --------------------------- +2020-01-01T00:00:00 0.50 +2020-01-02T00:00:00 0.50 +2020-01-03T00:00:00 0.67 +2020-01-04T00:00:00 None +2020-01-06T00:00:00 None +2020-01-07T00:00:00 1.00 +2020-01-10T00:00:00 1.00 +2020-01-12T00:00:00 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_categorical_filter__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_categorical_filter__query_output.txt new file mode 100644 index 0000000000..f01a3b3588 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_categorical_filter__query_output.txt @@ -0,0 +1,10 @@ +metric_time__day visit__referrer_id visit_buy_conversion_rate +------------------- -------------------- --------------------------- +2020-01-01T00:00:00 fb_ad_1 1.00 +2020-01-01T00:00:00 homepage_1 None +2020-01-02T00:00:00 fb_ad_1 1.00 +2020-01-02T00:00:00 homepage_1 None +2020-01-03T00:00:00 fb_ad_1 1.00 +2020-01-03T00:00:00 google_ad_1 None +2020-01-07T00:00:00 fb_ad_2 None +2020-01-10T00:00:00 google_ad_1 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_filter_not_in_group_by__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_filter_not_in_group_by__query_output.txt new file mode 100644 index 0000000000..e3046748a3 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_filter_not_in_group_by__query_output.txt @@ -0,0 +1,3 @@ + visit_buy_conversions +----------------------- + 3 diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_time_constraint__query_output.txt new file mode 100644 index 0000000000..560911418a --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_time_constraint__query_output.txt @@ -0,0 +1,5 @@ +visit__referrer_id visit_buy_conversion_rate +-------------------- --------------------------- +fb_ad_1 1.50 +fb_ad_3 None +homepage_1 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_window__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_window__query_output.txt new file mode 100644 index 0000000000..294fbf9259 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_window__query_output.txt @@ -0,0 +1,10 @@ +metric_time__day visit_buy_conversion_rate_7days +------------------- --------------------------------- +2020-01-01T00:00:00 0.50 +2020-01-02T00:00:00 0.50 +2020-01-03T00:00:00 0.67 +2020-01-04T00:00:00 None +2020-01-06T00:00:00 None +2020-01-07T00:00:00 1.00 +2020-01-10T00:00:00 1.00 +2020-01-12T00:00:00 None diff --git a/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_window_and_time_constraint__query_output.txt b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_window_and_time_constraint__query_output.txt new file mode 100644 index 0000000000..ca279ccd92 --- /dev/null +++ b/tests_metricflow/snapshots/test_conversion_metrics.py/str/Trino/test_conversion_metric_with_window_and_time_constraint__query_output.txt @@ -0,0 +1,7 @@ +metric_time__day visit__referrer_id visit_buy_conversion_rate_7days +------------------- -------------------- --------------------------------- +2020-01-01T00:00:00 fb_ad_1 2.00 +2020-01-01T00:00:00 homepage_1 None +2020-01-02T00:00:00 fb_ad_1 1.00 +2020-01-02T00:00:00 fb_ad_3 None +2020-01-02T00:00:00 homepage_1 None