diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/BigQuery/test_dimension_with_joined_where_constraint__plan0.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/BigQuery/test_dimension_with_joined_where_constraint__plan0.sql index 4da4d7d82c..e191074286 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/BigQuery/test_dimension_with_joined_where_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/BigQuery/test_dimension_with_joined_where_constraint__plan0.sql @@ -1,192 +1,253 @@ -- Pass Only Elements: ['user__home_state_latest',] SELECT - subq_4.user__home_state_latest + subq_7.user__home_state_latest FROM ( -- Constrain Output with WHERE SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.user__home_state_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing + 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.created_at__day + , subq_6.created_at__week + , subq_6.created_at__month + , subq_6.created_at__quarter + , subq_6.created_at__year + , subq_6.created_at__extract_year + , subq_6.created_at__extract_quarter + , subq_6.created_at__extract_month + , subq_6.created_at__extract_day + , subq_6.created_at__extract_dow + , subq_6.created_at__extract_doy + , subq_6.listing__ds__day + , subq_6.listing__ds__week + , subq_6.listing__ds__month + , subq_6.listing__ds__quarter + , subq_6.listing__ds__year + , subq_6.listing__ds__extract_year + , subq_6.listing__ds__extract_quarter + , subq_6.listing__ds__extract_month + , subq_6.listing__ds__extract_day + , subq_6.listing__ds__extract_dow + , subq_6.listing__ds__extract_doy + , subq_6.listing__created_at__day + , subq_6.listing__created_at__week + , subq_6.listing__created_at__month + , subq_6.listing__created_at__quarter + , subq_6.listing__created_at__year + , subq_6.listing__created_at__extract_year + , subq_6.listing__created_at__extract_quarter + , subq_6.listing__created_at__extract_month + , subq_6.listing__created_at__extract_day + , subq_6.listing__created_at__extract_dow + , subq_6.listing__created_at__extract_doy + , subq_6.listing + , subq_6.user + , subq_6.listing__user + , subq_6.country_latest + , subq_6.is_lux_latest + , subq_6.capacity_latest + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.user__home_state_latest + , subq_6.listings + , subq_6.largest_listing + , subq_6.smallest_listing FROM ( -- Join Standard Outputs SELECT - subq_0.ds__day AS ds__day - , subq_0.ds__week AS ds__week - , subq_0.ds__month AS ds__month - , subq_0.ds__quarter AS ds__quarter - , subq_0.ds__year AS ds__year - , subq_0.ds__extract_year AS ds__extract_year - , subq_0.ds__extract_quarter AS ds__extract_quarter - , subq_0.ds__extract_month AS ds__extract_month - , subq_0.ds__extract_day AS ds__extract_day - , subq_0.ds__extract_dow AS ds__extract_dow - , subq_0.ds__extract_doy AS ds__extract_doy - , subq_0.created_at__day AS created_at__day - , subq_0.created_at__week AS created_at__week - , subq_0.created_at__month AS created_at__month - , subq_0.created_at__quarter AS created_at__quarter - , subq_0.created_at__year AS created_at__year - , subq_0.created_at__extract_year AS created_at__extract_year - , subq_0.created_at__extract_quarter AS created_at__extract_quarter - , subq_0.created_at__extract_month AS created_at__extract_month - , subq_0.created_at__extract_day AS created_at__extract_day - , subq_0.created_at__extract_dow AS created_at__extract_dow - , subq_0.created_at__extract_doy AS created_at__extract_doy - , subq_0.listing__ds__day AS listing__ds__day - , subq_0.listing__ds__week AS listing__ds__week - , subq_0.listing__ds__month AS listing__ds__month - , subq_0.listing__ds__quarter AS listing__ds__quarter - , subq_0.listing__ds__year AS listing__ds__year - , subq_0.listing__ds__extract_year AS listing__ds__extract_year - , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter - , subq_0.listing__ds__extract_month AS listing__ds__extract_month - , subq_0.listing__ds__extract_day AS listing__ds__extract_day - , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow - , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy - , subq_0.listing__created_at__day AS listing__created_at__day - , subq_0.listing__created_at__week AS listing__created_at__week - , subq_0.listing__created_at__month AS listing__created_at__month - , subq_0.listing__created_at__quarter AS listing__created_at__quarter - , subq_0.listing__created_at__year AS listing__created_at__year - , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month - , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow - , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy - , subq_0.listing AS listing - , subq_0.user AS user - , subq_0.listing__user AS listing__user - , subq_0.country_latest AS country_latest - , subq_0.is_lux_latest AS is_lux_latest - , subq_0.capacity_latest AS capacity_latest - , subq_0.listing__country_latest AS listing__country_latest - , subq_0.listing__is_lux_latest AS listing__is_lux_latest - , subq_0.listing__capacity_latest AS listing__capacity_latest - , subq_2.home_state_latest AS user__home_state_latest - , subq_0.listings AS listings - , subq_0.largest_listing AS largest_listing - , subq_0.smallest_listing AS smallest_listing + subq_3.ds__day AS ds__day + , subq_3.ds__week AS ds__week + , subq_3.ds__month AS ds__month + , subq_3.ds__quarter AS ds__quarter + , subq_3.ds__year AS ds__year + , subq_3.ds__extract_year AS ds__extract_year + , subq_3.ds__extract_quarter AS ds__extract_quarter + , subq_3.ds__extract_month AS ds__extract_month + , subq_3.ds__extract_day AS ds__extract_day + , subq_3.ds__extract_dow AS ds__extract_dow + , subq_3.ds__extract_doy AS ds__extract_doy + , subq_3.created_at__day AS created_at__day + , subq_3.created_at__week AS created_at__week + , subq_3.created_at__month AS created_at__month + , subq_3.created_at__quarter AS created_at__quarter + , subq_3.created_at__year AS created_at__year + , subq_3.created_at__extract_year AS created_at__extract_year + , subq_3.created_at__extract_quarter AS created_at__extract_quarter + , subq_3.created_at__extract_month AS created_at__extract_month + , subq_3.created_at__extract_day AS created_at__extract_day + , subq_3.created_at__extract_dow AS created_at__extract_dow + , subq_3.created_at__extract_doy AS created_at__extract_doy + , subq_3.listing__ds__day AS listing__ds__day + , subq_3.listing__ds__week AS listing__ds__week + , subq_3.listing__ds__month AS listing__ds__month + , subq_3.listing__ds__quarter AS listing__ds__quarter + , subq_3.listing__ds__year AS listing__ds__year + , subq_3.listing__ds__extract_year AS listing__ds__extract_year + , subq_3.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_3.listing__ds__extract_month AS listing__ds__extract_month + , subq_3.listing__ds__extract_day AS listing__ds__extract_day + , subq_3.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_3.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_3.listing__created_at__day AS listing__created_at__day + , subq_3.listing__created_at__week AS listing__created_at__week + , subq_3.listing__created_at__month AS listing__created_at__month + , subq_3.listing__created_at__quarter AS listing__created_at__quarter + , subq_3.listing__created_at__year AS listing__created_at__year + , subq_3.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_3.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_3.listing AS listing + , subq_3.user AS user + , subq_3.listing__user AS listing__user + , subq_3.country_latest AS country_latest + , subq_3.is_lux_latest AS is_lux_latest + , subq_3.capacity_latest AS capacity_latest + , subq_3.listing__country_latest AS listing__country_latest + , subq_3.listing__is_lux_latest AS listing__is_lux_latest + , subq_3.listing__capacity_latest AS listing__capacity_latest + , subq_5.home_state_latest AS user__home_state_latest + , subq_3.listings AS listings + , subq_3.largest_listing AS largest_listing + , subq_3.smallest_listing AS smallest_listing FROM ( - -- Read Elements From Semantic Model 'listings_latest' + -- Constrain Output with WHERE SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS ds__day - , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS ds__week - , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS ds__month - , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS ds__quarter - , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS ds__extract_dow - , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS created_at__day - , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS created_at__week - , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS created_at__month - , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS created_at__quarter - , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS created_at__extract_dow - , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS listing__ds__day - , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS listing__ds__week - , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS listing__ds__month - , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS listing__ds__quarter - , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS listing__ds__extract_dow - , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS listing__created_at__day - , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS listing__created_at__week - , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS listing__created_at__month - , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS listing__created_at__quarter - , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS listing__created_at__extract_dow - , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , listings_latest_src_28000.user_id AS user - , listings_latest_src_28000.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_0 + subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.created_at__day + , subq_2.created_at__week + , subq_2.created_at__month + , subq_2.created_at__quarter + , subq_2.created_at__year + , subq_2.created_at__extract_year + , subq_2.created_at__extract_quarter + , subq_2.created_at__extract_month + , subq_2.created_at__extract_day + , subq_2.created_at__extract_dow + , subq_2.created_at__extract_doy + , subq_2.listing__ds__day + , subq_2.listing__ds__week + , subq_2.listing__ds__month + , subq_2.listing__ds__quarter + , subq_2.listing__ds__year + , subq_2.listing__ds__extract_year + , subq_2.listing__ds__extract_quarter + , subq_2.listing__ds__extract_month + , subq_2.listing__ds__extract_day + , subq_2.listing__ds__extract_dow + , subq_2.listing__ds__extract_doy + , subq_2.listing__created_at__day + , subq_2.listing__created_at__week + , subq_2.listing__created_at__month + , subq_2.listing__created_at__quarter + , subq_2.listing__created_at__year + , subq_2.listing__created_at__extract_year + , subq_2.listing__created_at__extract_quarter + , subq_2.listing__created_at__extract_month + , subq_2.listing__created_at__extract_day + , subq_2.listing__created_at__extract_dow + , subq_2.listing__created_at__extract_doy + , subq_2.listing + , subq_2.user + , subq_2.listing__user + , subq_2.country_latest + , subq_2.is_lux_latest + , subq_2.capacity_latest + , subq_2.listing__country_latest + , subq_2.listing__is_lux_latest + , subq_2.listing__capacity_latest + , subq_2.listings + , subq_2.largest_listing + , subq_2.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS ds__day + , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS ds__week + , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS ds__month + , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS ds__quarter + , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS created_at__day + , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS created_at__week + , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS created_at__month + , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS created_at__quarter + , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS created_at__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS listing__ds__day + , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS listing__ds__week + , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS listing__ds__month + , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS listing__ds__quarter + , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS listing__ds__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS listing__created_at__day + , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS listing__created_at__week + , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS listing__created_at__month + , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS listing__created_at__quarter + , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS listing__created_at__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_2 + WHERE listing__country_latest = 'us' + ) subq_3 FULL OUTER JOIN ( -- Pass Only Elements: ['home_state_latest', 'user'] SELECT - subq_1.user - , subq_1.home_state_latest + subq_4.user + , subq_4.home_state_latest FROM ( -- Read Elements From Semantic Model 'users_latest' SELECT @@ -216,12 +277,12 @@ FROM ( , users_latest_src_28000.home_state_latest AS user__home_state_latest , users_latest_src_28000.user_id AS user FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_1 - ) subq_2 + ) subq_4 + ) subq_5 ON - subq_0.user = subq_2.user - ) subq_3 + subq_3.user = subq_5.user + ) subq_6 WHERE listing__country_latest = 'us' -) subq_4 +) subq_7 GROUP BY user__home_state_latest diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/BigQuery/test_dimension_with_joined_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/BigQuery/test_dimension_with_joined_where_constraint__plan0_optimized.sql index c4e57d3c86..f2ac976dac 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/BigQuery/test_dimension_with_joined_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/BigQuery/test_dimension_with_joined_where_constraint__plan0_optimized.sql @@ -5,14 +5,27 @@ SELECT FROM ( -- Join Standard Outputs SELECT - listings_latest_src_28000.country AS listing__country_latest + subq_9.listing__country_latest AS listing__country_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest - FROM ***************************.dim_listings_latest listings_latest_src_28000 + FROM ( + -- Constrain Output with WHERE + SELECT + subq_8.user + , listing__country_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + country AS listing__country_latest + , user_id AS user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_8 + WHERE listing__country_latest = 'us' + ) subq_9 FULL OUTER JOIN ***************************.dim_users_latest users_latest_src_28000 ON - listings_latest_src_28000.user_id = users_latest_src_28000.user_id -) subq_8 + subq_9.user = users_latest_src_28000.user_id +) subq_12 WHERE listing__country_latest = 'us' GROUP BY user__home_state_latest diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Databricks/test_dimension_with_joined_where_constraint__plan0.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Databricks/test_dimension_with_joined_where_constraint__plan0.sql index 1d8a2bddf2..78c446668c 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Databricks/test_dimension_with_joined_where_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Databricks/test_dimension_with_joined_where_constraint__plan0.sql @@ -1,192 +1,253 @@ -- Pass Only Elements: ['user__home_state_latest',] SELECT - subq_4.user__home_state_latest + subq_7.user__home_state_latest FROM ( -- Constrain Output with WHERE SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.user__home_state_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing + 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.created_at__day + , subq_6.created_at__week + , subq_6.created_at__month + , subq_6.created_at__quarter + , subq_6.created_at__year + , subq_6.created_at__extract_year + , subq_6.created_at__extract_quarter + , subq_6.created_at__extract_month + , subq_6.created_at__extract_day + , subq_6.created_at__extract_dow + , subq_6.created_at__extract_doy + , subq_6.listing__ds__day + , subq_6.listing__ds__week + , subq_6.listing__ds__month + , subq_6.listing__ds__quarter + , subq_6.listing__ds__year + , subq_6.listing__ds__extract_year + , subq_6.listing__ds__extract_quarter + , subq_6.listing__ds__extract_month + , subq_6.listing__ds__extract_day + , subq_6.listing__ds__extract_dow + , subq_6.listing__ds__extract_doy + , subq_6.listing__created_at__day + , subq_6.listing__created_at__week + , subq_6.listing__created_at__month + , subq_6.listing__created_at__quarter + , subq_6.listing__created_at__year + , subq_6.listing__created_at__extract_year + , subq_6.listing__created_at__extract_quarter + , subq_6.listing__created_at__extract_month + , subq_6.listing__created_at__extract_day + , subq_6.listing__created_at__extract_dow + , subq_6.listing__created_at__extract_doy + , subq_6.listing + , subq_6.user + , subq_6.listing__user + , subq_6.country_latest + , subq_6.is_lux_latest + , subq_6.capacity_latest + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.user__home_state_latest + , subq_6.listings + , subq_6.largest_listing + , subq_6.smallest_listing FROM ( -- Join Standard Outputs SELECT - subq_0.ds__day AS ds__day - , subq_0.ds__week AS ds__week - , subq_0.ds__month AS ds__month - , subq_0.ds__quarter AS ds__quarter - , subq_0.ds__year AS ds__year - , subq_0.ds__extract_year AS ds__extract_year - , subq_0.ds__extract_quarter AS ds__extract_quarter - , subq_0.ds__extract_month AS ds__extract_month - , subq_0.ds__extract_day AS ds__extract_day - , subq_0.ds__extract_dow AS ds__extract_dow - , subq_0.ds__extract_doy AS ds__extract_doy - , subq_0.created_at__day AS created_at__day - , subq_0.created_at__week AS created_at__week - , subq_0.created_at__month AS created_at__month - , subq_0.created_at__quarter AS created_at__quarter - , subq_0.created_at__year AS created_at__year - , subq_0.created_at__extract_year AS created_at__extract_year - , subq_0.created_at__extract_quarter AS created_at__extract_quarter - , subq_0.created_at__extract_month AS created_at__extract_month - , subq_0.created_at__extract_day AS created_at__extract_day - , subq_0.created_at__extract_dow AS created_at__extract_dow - , subq_0.created_at__extract_doy AS created_at__extract_doy - , subq_0.listing__ds__day AS listing__ds__day - , subq_0.listing__ds__week AS listing__ds__week - , subq_0.listing__ds__month AS listing__ds__month - , subq_0.listing__ds__quarter AS listing__ds__quarter - , subq_0.listing__ds__year AS listing__ds__year - , subq_0.listing__ds__extract_year AS listing__ds__extract_year - , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter - , subq_0.listing__ds__extract_month AS listing__ds__extract_month - , subq_0.listing__ds__extract_day AS listing__ds__extract_day - , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow - , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy - , subq_0.listing__created_at__day AS listing__created_at__day - , subq_0.listing__created_at__week AS listing__created_at__week - , subq_0.listing__created_at__month AS listing__created_at__month - , subq_0.listing__created_at__quarter AS listing__created_at__quarter - , subq_0.listing__created_at__year AS listing__created_at__year - , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month - , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow - , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy - , subq_0.listing AS listing - , subq_0.user AS user - , subq_0.listing__user AS listing__user - , subq_0.country_latest AS country_latest - , subq_0.is_lux_latest AS is_lux_latest - , subq_0.capacity_latest AS capacity_latest - , subq_0.listing__country_latest AS listing__country_latest - , subq_0.listing__is_lux_latest AS listing__is_lux_latest - , subq_0.listing__capacity_latest AS listing__capacity_latest - , subq_2.home_state_latest AS user__home_state_latest - , subq_0.listings AS listings - , subq_0.largest_listing AS largest_listing - , subq_0.smallest_listing AS smallest_listing + subq_3.ds__day AS ds__day + , subq_3.ds__week AS ds__week + , subq_3.ds__month AS ds__month + , subq_3.ds__quarter AS ds__quarter + , subq_3.ds__year AS ds__year + , subq_3.ds__extract_year AS ds__extract_year + , subq_3.ds__extract_quarter AS ds__extract_quarter + , subq_3.ds__extract_month AS ds__extract_month + , subq_3.ds__extract_day AS ds__extract_day + , subq_3.ds__extract_dow AS ds__extract_dow + , subq_3.ds__extract_doy AS ds__extract_doy + , subq_3.created_at__day AS created_at__day + , subq_3.created_at__week AS created_at__week + , subq_3.created_at__month AS created_at__month + , subq_3.created_at__quarter AS created_at__quarter + , subq_3.created_at__year AS created_at__year + , subq_3.created_at__extract_year AS created_at__extract_year + , subq_3.created_at__extract_quarter AS created_at__extract_quarter + , subq_3.created_at__extract_month AS created_at__extract_month + , subq_3.created_at__extract_day AS created_at__extract_day + , subq_3.created_at__extract_dow AS created_at__extract_dow + , subq_3.created_at__extract_doy AS created_at__extract_doy + , subq_3.listing__ds__day AS listing__ds__day + , subq_3.listing__ds__week AS listing__ds__week + , subq_3.listing__ds__month AS listing__ds__month + , subq_3.listing__ds__quarter AS listing__ds__quarter + , subq_3.listing__ds__year AS listing__ds__year + , subq_3.listing__ds__extract_year AS listing__ds__extract_year + , subq_3.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_3.listing__ds__extract_month AS listing__ds__extract_month + , subq_3.listing__ds__extract_day AS listing__ds__extract_day + , subq_3.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_3.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_3.listing__created_at__day AS listing__created_at__day + , subq_3.listing__created_at__week AS listing__created_at__week + , subq_3.listing__created_at__month AS listing__created_at__month + , subq_3.listing__created_at__quarter AS listing__created_at__quarter + , subq_3.listing__created_at__year AS listing__created_at__year + , subq_3.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_3.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_3.listing AS listing + , subq_3.user AS user + , subq_3.listing__user AS listing__user + , subq_3.country_latest AS country_latest + , subq_3.is_lux_latest AS is_lux_latest + , subq_3.capacity_latest AS capacity_latest + , subq_3.listing__country_latest AS listing__country_latest + , subq_3.listing__is_lux_latest AS listing__is_lux_latest + , subq_3.listing__capacity_latest AS listing__capacity_latest + , subq_5.home_state_latest AS user__home_state_latest + , subq_3.listings AS listings + , subq_3.largest_listing AS largest_listing + , subq_3.smallest_listing AS smallest_listing FROM ( - -- Read Elements From Semantic Model 'listings_latest' + -- Constrain Output with WHERE SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , listings_latest_src_28000.user_id AS user - , listings_latest_src_28000.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_0 + subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.created_at__day + , subq_2.created_at__week + , subq_2.created_at__month + , subq_2.created_at__quarter + , subq_2.created_at__year + , subq_2.created_at__extract_year + , subq_2.created_at__extract_quarter + , subq_2.created_at__extract_month + , subq_2.created_at__extract_day + , subq_2.created_at__extract_dow + , subq_2.created_at__extract_doy + , subq_2.listing__ds__day + , subq_2.listing__ds__week + , subq_2.listing__ds__month + , subq_2.listing__ds__quarter + , subq_2.listing__ds__year + , subq_2.listing__ds__extract_year + , subq_2.listing__ds__extract_quarter + , subq_2.listing__ds__extract_month + , subq_2.listing__ds__extract_day + , subq_2.listing__ds__extract_dow + , subq_2.listing__ds__extract_doy + , subq_2.listing__created_at__day + , subq_2.listing__created_at__week + , subq_2.listing__created_at__month + , subq_2.listing__created_at__quarter + , subq_2.listing__created_at__year + , subq_2.listing__created_at__extract_year + , subq_2.listing__created_at__extract_quarter + , subq_2.listing__created_at__extract_month + , subq_2.listing__created_at__extract_day + , subq_2.listing__created_at__extract_dow + , subq_2.listing__created_at__extract_doy + , subq_2.listing + , subq_2.user + , subq_2.listing__user + , subq_2.country_latest + , subq_2.is_lux_latest + , subq_2.capacity_latest + , subq_2.listing__country_latest + , subq_2.listing__is_lux_latest + , subq_2.listing__capacity_latest + , subq_2.listings + , subq_2.largest_listing + , subq_2.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_2 + WHERE listing__country_latest = 'us' + ) subq_3 FULL OUTER JOIN ( -- Pass Only Elements: ['home_state_latest', 'user'] SELECT - subq_1.user - , subq_1.home_state_latest + subq_4.user + , subq_4.home_state_latest FROM ( -- Read Elements From Semantic Model 'users_latest' SELECT @@ -216,12 +277,12 @@ FROM ( , users_latest_src_28000.home_state_latest AS user__home_state_latest , users_latest_src_28000.user_id AS user FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_1 - ) subq_2 + ) subq_4 + ) subq_5 ON - subq_0.user = subq_2.user - ) subq_3 + subq_3.user = subq_5.user + ) subq_6 WHERE listing__country_latest = 'us' -) subq_4 +) subq_7 GROUP BY - subq_4.user__home_state_latest + subq_7.user__home_state_latest diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Databricks/test_dimension_with_joined_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Databricks/test_dimension_with_joined_where_constraint__plan0_optimized.sql index c4e57d3c86..f2ac976dac 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Databricks/test_dimension_with_joined_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Databricks/test_dimension_with_joined_where_constraint__plan0_optimized.sql @@ -5,14 +5,27 @@ SELECT FROM ( -- Join Standard Outputs SELECT - listings_latest_src_28000.country AS listing__country_latest + subq_9.listing__country_latest AS listing__country_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest - FROM ***************************.dim_listings_latest listings_latest_src_28000 + FROM ( + -- Constrain Output with WHERE + SELECT + subq_8.user + , listing__country_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + country AS listing__country_latest + , user_id AS user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_8 + WHERE listing__country_latest = 'us' + ) subq_9 FULL OUTER JOIN ***************************.dim_users_latest users_latest_src_28000 ON - listings_latest_src_28000.user_id = users_latest_src_28000.user_id -) subq_8 + subq_9.user = users_latest_src_28000.user_id +) subq_12 WHERE listing__country_latest = 'us' GROUP BY user__home_state_latest diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Postgres/test_dimension_with_joined_where_constraint__plan0.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Postgres/test_dimension_with_joined_where_constraint__plan0.sql index ed1028fb88..9b9dc5ff09 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Postgres/test_dimension_with_joined_where_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Postgres/test_dimension_with_joined_where_constraint__plan0.sql @@ -1,192 +1,253 @@ -- Pass Only Elements: ['user__home_state_latest',] SELECT - subq_4.user__home_state_latest + subq_7.user__home_state_latest FROM ( -- Constrain Output with WHERE SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.user__home_state_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing + 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.created_at__day + , subq_6.created_at__week + , subq_6.created_at__month + , subq_6.created_at__quarter + , subq_6.created_at__year + , subq_6.created_at__extract_year + , subq_6.created_at__extract_quarter + , subq_6.created_at__extract_month + , subq_6.created_at__extract_day + , subq_6.created_at__extract_dow + , subq_6.created_at__extract_doy + , subq_6.listing__ds__day + , subq_6.listing__ds__week + , subq_6.listing__ds__month + , subq_6.listing__ds__quarter + , subq_6.listing__ds__year + , subq_6.listing__ds__extract_year + , subq_6.listing__ds__extract_quarter + , subq_6.listing__ds__extract_month + , subq_6.listing__ds__extract_day + , subq_6.listing__ds__extract_dow + , subq_6.listing__ds__extract_doy + , subq_6.listing__created_at__day + , subq_6.listing__created_at__week + , subq_6.listing__created_at__month + , subq_6.listing__created_at__quarter + , subq_6.listing__created_at__year + , subq_6.listing__created_at__extract_year + , subq_6.listing__created_at__extract_quarter + , subq_6.listing__created_at__extract_month + , subq_6.listing__created_at__extract_day + , subq_6.listing__created_at__extract_dow + , subq_6.listing__created_at__extract_doy + , subq_6.listing + , subq_6.user + , subq_6.listing__user + , subq_6.country_latest + , subq_6.is_lux_latest + , subq_6.capacity_latest + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.user__home_state_latest + , subq_6.listings + , subq_6.largest_listing + , subq_6.smallest_listing FROM ( -- Join Standard Outputs SELECT - subq_0.ds__day AS ds__day - , subq_0.ds__week AS ds__week - , subq_0.ds__month AS ds__month - , subq_0.ds__quarter AS ds__quarter - , subq_0.ds__year AS ds__year - , subq_0.ds__extract_year AS ds__extract_year - , subq_0.ds__extract_quarter AS ds__extract_quarter - , subq_0.ds__extract_month AS ds__extract_month - , subq_0.ds__extract_day AS ds__extract_day - , subq_0.ds__extract_dow AS ds__extract_dow - , subq_0.ds__extract_doy AS ds__extract_doy - , subq_0.created_at__day AS created_at__day - , subq_0.created_at__week AS created_at__week - , subq_0.created_at__month AS created_at__month - , subq_0.created_at__quarter AS created_at__quarter - , subq_0.created_at__year AS created_at__year - , subq_0.created_at__extract_year AS created_at__extract_year - , subq_0.created_at__extract_quarter AS created_at__extract_quarter - , subq_0.created_at__extract_month AS created_at__extract_month - , subq_0.created_at__extract_day AS created_at__extract_day - , subq_0.created_at__extract_dow AS created_at__extract_dow - , subq_0.created_at__extract_doy AS created_at__extract_doy - , subq_0.listing__ds__day AS listing__ds__day - , subq_0.listing__ds__week AS listing__ds__week - , subq_0.listing__ds__month AS listing__ds__month - , subq_0.listing__ds__quarter AS listing__ds__quarter - , subq_0.listing__ds__year AS listing__ds__year - , subq_0.listing__ds__extract_year AS listing__ds__extract_year - , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter - , subq_0.listing__ds__extract_month AS listing__ds__extract_month - , subq_0.listing__ds__extract_day AS listing__ds__extract_day - , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow - , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy - , subq_0.listing__created_at__day AS listing__created_at__day - , subq_0.listing__created_at__week AS listing__created_at__week - , subq_0.listing__created_at__month AS listing__created_at__month - , subq_0.listing__created_at__quarter AS listing__created_at__quarter - , subq_0.listing__created_at__year AS listing__created_at__year - , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month - , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow - , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy - , subq_0.listing AS listing - , subq_0.user AS user - , subq_0.listing__user AS listing__user - , subq_0.country_latest AS country_latest - , subq_0.is_lux_latest AS is_lux_latest - , subq_0.capacity_latest AS capacity_latest - , subq_0.listing__country_latest AS listing__country_latest - , subq_0.listing__is_lux_latest AS listing__is_lux_latest - , subq_0.listing__capacity_latest AS listing__capacity_latest - , subq_2.home_state_latest AS user__home_state_latest - , subq_0.listings AS listings - , subq_0.largest_listing AS largest_listing - , subq_0.smallest_listing AS smallest_listing + subq_3.ds__day AS ds__day + , subq_3.ds__week AS ds__week + , subq_3.ds__month AS ds__month + , subq_3.ds__quarter AS ds__quarter + , subq_3.ds__year AS ds__year + , subq_3.ds__extract_year AS ds__extract_year + , subq_3.ds__extract_quarter AS ds__extract_quarter + , subq_3.ds__extract_month AS ds__extract_month + , subq_3.ds__extract_day AS ds__extract_day + , subq_3.ds__extract_dow AS ds__extract_dow + , subq_3.ds__extract_doy AS ds__extract_doy + , subq_3.created_at__day AS created_at__day + , subq_3.created_at__week AS created_at__week + , subq_3.created_at__month AS created_at__month + , subq_3.created_at__quarter AS created_at__quarter + , subq_3.created_at__year AS created_at__year + , subq_3.created_at__extract_year AS created_at__extract_year + , subq_3.created_at__extract_quarter AS created_at__extract_quarter + , subq_3.created_at__extract_month AS created_at__extract_month + , subq_3.created_at__extract_day AS created_at__extract_day + , subq_3.created_at__extract_dow AS created_at__extract_dow + , subq_3.created_at__extract_doy AS created_at__extract_doy + , subq_3.listing__ds__day AS listing__ds__day + , subq_3.listing__ds__week AS listing__ds__week + , subq_3.listing__ds__month AS listing__ds__month + , subq_3.listing__ds__quarter AS listing__ds__quarter + , subq_3.listing__ds__year AS listing__ds__year + , subq_3.listing__ds__extract_year AS listing__ds__extract_year + , subq_3.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_3.listing__ds__extract_month AS listing__ds__extract_month + , subq_3.listing__ds__extract_day AS listing__ds__extract_day + , subq_3.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_3.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_3.listing__created_at__day AS listing__created_at__day + , subq_3.listing__created_at__week AS listing__created_at__week + , subq_3.listing__created_at__month AS listing__created_at__month + , subq_3.listing__created_at__quarter AS listing__created_at__quarter + , subq_3.listing__created_at__year AS listing__created_at__year + , subq_3.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_3.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_3.listing AS listing + , subq_3.user AS user + , subq_3.listing__user AS listing__user + , subq_3.country_latest AS country_latest + , subq_3.is_lux_latest AS is_lux_latest + , subq_3.capacity_latest AS capacity_latest + , subq_3.listing__country_latest AS listing__country_latest + , subq_3.listing__is_lux_latest AS listing__is_lux_latest + , subq_3.listing__capacity_latest AS listing__capacity_latest + , subq_5.home_state_latest AS user__home_state_latest + , subq_3.listings AS listings + , subq_3.largest_listing AS largest_listing + , subq_3.smallest_listing AS smallest_listing FROM ( - -- Read Elements From Semantic Model 'listings_latest' + -- Constrain Output with WHERE SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , listings_latest_src_28000.user_id AS user - , listings_latest_src_28000.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_0 + subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.created_at__day + , subq_2.created_at__week + , subq_2.created_at__month + , subq_2.created_at__quarter + , subq_2.created_at__year + , subq_2.created_at__extract_year + , subq_2.created_at__extract_quarter + , subq_2.created_at__extract_month + , subq_2.created_at__extract_day + , subq_2.created_at__extract_dow + , subq_2.created_at__extract_doy + , subq_2.listing__ds__day + , subq_2.listing__ds__week + , subq_2.listing__ds__month + , subq_2.listing__ds__quarter + , subq_2.listing__ds__year + , subq_2.listing__ds__extract_year + , subq_2.listing__ds__extract_quarter + , subq_2.listing__ds__extract_month + , subq_2.listing__ds__extract_day + , subq_2.listing__ds__extract_dow + , subq_2.listing__ds__extract_doy + , subq_2.listing__created_at__day + , subq_2.listing__created_at__week + , subq_2.listing__created_at__month + , subq_2.listing__created_at__quarter + , subq_2.listing__created_at__year + , subq_2.listing__created_at__extract_year + , subq_2.listing__created_at__extract_quarter + , subq_2.listing__created_at__extract_month + , subq_2.listing__created_at__extract_day + , subq_2.listing__created_at__extract_dow + , subq_2.listing__created_at__extract_doy + , subq_2.listing + , subq_2.user + , subq_2.listing__user + , subq_2.country_latest + , subq_2.is_lux_latest + , subq_2.capacity_latest + , subq_2.listing__country_latest + , subq_2.listing__is_lux_latest + , subq_2.listing__capacity_latest + , subq_2.listings + , subq_2.largest_listing + , subq_2.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_2 + WHERE listing__country_latest = 'us' + ) subq_3 FULL OUTER JOIN ( -- Pass Only Elements: ['home_state_latest', 'user'] SELECT - subq_1.user - , subq_1.home_state_latest + subq_4.user + , subq_4.home_state_latest FROM ( -- Read Elements From Semantic Model 'users_latest' SELECT @@ -216,12 +277,12 @@ FROM ( , users_latest_src_28000.home_state_latest AS user__home_state_latest , users_latest_src_28000.user_id AS user FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_1 - ) subq_2 + ) subq_4 + ) subq_5 ON - subq_0.user = subq_2.user - ) subq_3 + subq_3.user = subq_5.user + ) subq_6 WHERE listing__country_latest = 'us' -) subq_4 +) subq_7 GROUP BY - subq_4.user__home_state_latest + subq_7.user__home_state_latest diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Postgres/test_dimension_with_joined_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Postgres/test_dimension_with_joined_where_constraint__plan0_optimized.sql index c4e57d3c86..f2ac976dac 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Postgres/test_dimension_with_joined_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Postgres/test_dimension_with_joined_where_constraint__plan0_optimized.sql @@ -5,14 +5,27 @@ SELECT FROM ( -- Join Standard Outputs SELECT - listings_latest_src_28000.country AS listing__country_latest + subq_9.listing__country_latest AS listing__country_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest - FROM ***************************.dim_listings_latest listings_latest_src_28000 + FROM ( + -- Constrain Output with WHERE + SELECT + subq_8.user + , listing__country_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + country AS listing__country_latest + , user_id AS user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_8 + WHERE listing__country_latest = 'us' + ) subq_9 FULL OUTER JOIN ***************************.dim_users_latest users_latest_src_28000 ON - listings_latest_src_28000.user_id = users_latest_src_28000.user_id -) subq_8 + subq_9.user = users_latest_src_28000.user_id +) subq_12 WHERE listing__country_latest = 'us' GROUP BY user__home_state_latest diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Redshift/test_dimension_with_joined_where_constraint__plan0.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Redshift/test_dimension_with_joined_where_constraint__plan0.sql index c59a5e39af..46e4dd2a52 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Redshift/test_dimension_with_joined_where_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Redshift/test_dimension_with_joined_where_constraint__plan0.sql @@ -1,192 +1,253 @@ -- Pass Only Elements: ['user__home_state_latest',] SELECT - subq_4.user__home_state_latest + subq_7.user__home_state_latest FROM ( -- Constrain Output with WHERE SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.user__home_state_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing + 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.created_at__day + , subq_6.created_at__week + , subq_6.created_at__month + , subq_6.created_at__quarter + , subq_6.created_at__year + , subq_6.created_at__extract_year + , subq_6.created_at__extract_quarter + , subq_6.created_at__extract_month + , subq_6.created_at__extract_day + , subq_6.created_at__extract_dow + , subq_6.created_at__extract_doy + , subq_6.listing__ds__day + , subq_6.listing__ds__week + , subq_6.listing__ds__month + , subq_6.listing__ds__quarter + , subq_6.listing__ds__year + , subq_6.listing__ds__extract_year + , subq_6.listing__ds__extract_quarter + , subq_6.listing__ds__extract_month + , subq_6.listing__ds__extract_day + , subq_6.listing__ds__extract_dow + , subq_6.listing__ds__extract_doy + , subq_6.listing__created_at__day + , subq_6.listing__created_at__week + , subq_6.listing__created_at__month + , subq_6.listing__created_at__quarter + , subq_6.listing__created_at__year + , subq_6.listing__created_at__extract_year + , subq_6.listing__created_at__extract_quarter + , subq_6.listing__created_at__extract_month + , subq_6.listing__created_at__extract_day + , subq_6.listing__created_at__extract_dow + , subq_6.listing__created_at__extract_doy + , subq_6.listing + , subq_6.user + , subq_6.listing__user + , subq_6.country_latest + , subq_6.is_lux_latest + , subq_6.capacity_latest + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.user__home_state_latest + , subq_6.listings + , subq_6.largest_listing + , subq_6.smallest_listing FROM ( -- Join Standard Outputs SELECT - subq_0.ds__day AS ds__day - , subq_0.ds__week AS ds__week - , subq_0.ds__month AS ds__month - , subq_0.ds__quarter AS ds__quarter - , subq_0.ds__year AS ds__year - , subq_0.ds__extract_year AS ds__extract_year - , subq_0.ds__extract_quarter AS ds__extract_quarter - , subq_0.ds__extract_month AS ds__extract_month - , subq_0.ds__extract_day AS ds__extract_day - , subq_0.ds__extract_dow AS ds__extract_dow - , subq_0.ds__extract_doy AS ds__extract_doy - , subq_0.created_at__day AS created_at__day - , subq_0.created_at__week AS created_at__week - , subq_0.created_at__month AS created_at__month - , subq_0.created_at__quarter AS created_at__quarter - , subq_0.created_at__year AS created_at__year - , subq_0.created_at__extract_year AS created_at__extract_year - , subq_0.created_at__extract_quarter AS created_at__extract_quarter - , subq_0.created_at__extract_month AS created_at__extract_month - , subq_0.created_at__extract_day AS created_at__extract_day - , subq_0.created_at__extract_dow AS created_at__extract_dow - , subq_0.created_at__extract_doy AS created_at__extract_doy - , subq_0.listing__ds__day AS listing__ds__day - , subq_0.listing__ds__week AS listing__ds__week - , subq_0.listing__ds__month AS listing__ds__month - , subq_0.listing__ds__quarter AS listing__ds__quarter - , subq_0.listing__ds__year AS listing__ds__year - , subq_0.listing__ds__extract_year AS listing__ds__extract_year - , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter - , subq_0.listing__ds__extract_month AS listing__ds__extract_month - , subq_0.listing__ds__extract_day AS listing__ds__extract_day - , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow - , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy - , subq_0.listing__created_at__day AS listing__created_at__day - , subq_0.listing__created_at__week AS listing__created_at__week - , subq_0.listing__created_at__month AS listing__created_at__month - , subq_0.listing__created_at__quarter AS listing__created_at__quarter - , subq_0.listing__created_at__year AS listing__created_at__year - , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month - , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow - , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy - , subq_0.listing AS listing - , subq_0.user AS user - , subq_0.listing__user AS listing__user - , subq_0.country_latest AS country_latest - , subq_0.is_lux_latest AS is_lux_latest - , subq_0.capacity_latest AS capacity_latest - , subq_0.listing__country_latest AS listing__country_latest - , subq_0.listing__is_lux_latest AS listing__is_lux_latest - , subq_0.listing__capacity_latest AS listing__capacity_latest - , subq_2.home_state_latest AS user__home_state_latest - , subq_0.listings AS listings - , subq_0.largest_listing AS largest_listing - , subq_0.smallest_listing AS smallest_listing + subq_3.ds__day AS ds__day + , subq_3.ds__week AS ds__week + , subq_3.ds__month AS ds__month + , subq_3.ds__quarter AS ds__quarter + , subq_3.ds__year AS ds__year + , subq_3.ds__extract_year AS ds__extract_year + , subq_3.ds__extract_quarter AS ds__extract_quarter + , subq_3.ds__extract_month AS ds__extract_month + , subq_3.ds__extract_day AS ds__extract_day + , subq_3.ds__extract_dow AS ds__extract_dow + , subq_3.ds__extract_doy AS ds__extract_doy + , subq_3.created_at__day AS created_at__day + , subq_3.created_at__week AS created_at__week + , subq_3.created_at__month AS created_at__month + , subq_3.created_at__quarter AS created_at__quarter + , subq_3.created_at__year AS created_at__year + , subq_3.created_at__extract_year AS created_at__extract_year + , subq_3.created_at__extract_quarter AS created_at__extract_quarter + , subq_3.created_at__extract_month AS created_at__extract_month + , subq_3.created_at__extract_day AS created_at__extract_day + , subq_3.created_at__extract_dow AS created_at__extract_dow + , subq_3.created_at__extract_doy AS created_at__extract_doy + , subq_3.listing__ds__day AS listing__ds__day + , subq_3.listing__ds__week AS listing__ds__week + , subq_3.listing__ds__month AS listing__ds__month + , subq_3.listing__ds__quarter AS listing__ds__quarter + , subq_3.listing__ds__year AS listing__ds__year + , subq_3.listing__ds__extract_year AS listing__ds__extract_year + , subq_3.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_3.listing__ds__extract_month AS listing__ds__extract_month + , subq_3.listing__ds__extract_day AS listing__ds__extract_day + , subq_3.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_3.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_3.listing__created_at__day AS listing__created_at__day + , subq_3.listing__created_at__week AS listing__created_at__week + , subq_3.listing__created_at__month AS listing__created_at__month + , subq_3.listing__created_at__quarter AS listing__created_at__quarter + , subq_3.listing__created_at__year AS listing__created_at__year + , subq_3.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_3.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_3.listing AS listing + , subq_3.user AS user + , subq_3.listing__user AS listing__user + , subq_3.country_latest AS country_latest + , subq_3.is_lux_latest AS is_lux_latest + , subq_3.capacity_latest AS capacity_latest + , subq_3.listing__country_latest AS listing__country_latest + , subq_3.listing__is_lux_latest AS listing__is_lux_latest + , subq_3.listing__capacity_latest AS listing__capacity_latest + , subq_5.home_state_latest AS user__home_state_latest + , subq_3.listings AS listings + , subq_3.largest_listing AS largest_listing + , subq_3.smallest_listing AS smallest_listing FROM ( - -- Read Elements From Semantic Model 'listings_latest' + -- Constrain Output with WHERE SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , listings_latest_src_28000.user_id AS user - , listings_latest_src_28000.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_0 + subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.created_at__day + , subq_2.created_at__week + , subq_2.created_at__month + , subq_2.created_at__quarter + , subq_2.created_at__year + , subq_2.created_at__extract_year + , subq_2.created_at__extract_quarter + , subq_2.created_at__extract_month + , subq_2.created_at__extract_day + , subq_2.created_at__extract_dow + , subq_2.created_at__extract_doy + , subq_2.listing__ds__day + , subq_2.listing__ds__week + , subq_2.listing__ds__month + , subq_2.listing__ds__quarter + , subq_2.listing__ds__year + , subq_2.listing__ds__extract_year + , subq_2.listing__ds__extract_quarter + , subq_2.listing__ds__extract_month + , subq_2.listing__ds__extract_day + , subq_2.listing__ds__extract_dow + , subq_2.listing__ds__extract_doy + , subq_2.listing__created_at__day + , subq_2.listing__created_at__week + , subq_2.listing__created_at__month + , subq_2.listing__created_at__quarter + , subq_2.listing__created_at__year + , subq_2.listing__created_at__extract_year + , subq_2.listing__created_at__extract_quarter + , subq_2.listing__created_at__extract_month + , subq_2.listing__created_at__extract_day + , subq_2.listing__created_at__extract_dow + , subq_2.listing__created_at__extract_doy + , subq_2.listing + , subq_2.user + , subq_2.listing__user + , subq_2.country_latest + , subq_2.is_lux_latest + , subq_2.capacity_latest + , subq_2.listing__country_latest + , subq_2.listing__is_lux_latest + , subq_2.listing__capacity_latest + , subq_2.listings + , subq_2.largest_listing + , subq_2.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_2 + WHERE listing__country_latest = 'us' + ) subq_3 FULL OUTER JOIN ( -- Pass Only Elements: ['home_state_latest', 'user'] SELECT - subq_1.user - , subq_1.home_state_latest + subq_4.user + , subq_4.home_state_latest FROM ( -- Read Elements From Semantic Model 'users_latest' SELECT @@ -216,12 +277,12 @@ FROM ( , users_latest_src_28000.home_state_latest AS user__home_state_latest , users_latest_src_28000.user_id AS user FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_1 - ) subq_2 + ) subq_4 + ) subq_5 ON - subq_0.user = subq_2.user - ) subq_3 + subq_3.user = subq_5.user + ) subq_6 WHERE listing__country_latest = 'us' -) subq_4 +) subq_7 GROUP BY - subq_4.user__home_state_latest + subq_7.user__home_state_latest diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Redshift/test_dimension_with_joined_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Redshift/test_dimension_with_joined_where_constraint__plan0_optimized.sql index c4e57d3c86..f2ac976dac 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Redshift/test_dimension_with_joined_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Redshift/test_dimension_with_joined_where_constraint__plan0_optimized.sql @@ -5,14 +5,27 @@ SELECT FROM ( -- Join Standard Outputs SELECT - listings_latest_src_28000.country AS listing__country_latest + subq_9.listing__country_latest AS listing__country_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest - FROM ***************************.dim_listings_latest listings_latest_src_28000 + FROM ( + -- Constrain Output with WHERE + SELECT + subq_8.user + , listing__country_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + country AS listing__country_latest + , user_id AS user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_8 + WHERE listing__country_latest = 'us' + ) subq_9 FULL OUTER JOIN ***************************.dim_users_latest users_latest_src_28000 ON - listings_latest_src_28000.user_id = users_latest_src_28000.user_id -) subq_8 + subq_9.user = users_latest_src_28000.user_id +) subq_12 WHERE listing__country_latest = 'us' GROUP BY user__home_state_latest diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Snowflake/test_dimension_with_joined_where_constraint__plan0.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Snowflake/test_dimension_with_joined_where_constraint__plan0.sql index d1dedc82a3..e7670aac55 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Snowflake/test_dimension_with_joined_where_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Snowflake/test_dimension_with_joined_where_constraint__plan0.sql @@ -1,192 +1,253 @@ -- Pass Only Elements: ['user__home_state_latest',] SELECT - subq_4.user__home_state_latest + subq_7.user__home_state_latest FROM ( -- Constrain Output with WHERE SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.user__home_state_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing + 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.created_at__day + , subq_6.created_at__week + , subq_6.created_at__month + , subq_6.created_at__quarter + , subq_6.created_at__year + , subq_6.created_at__extract_year + , subq_6.created_at__extract_quarter + , subq_6.created_at__extract_month + , subq_6.created_at__extract_day + , subq_6.created_at__extract_dow + , subq_6.created_at__extract_doy + , subq_6.listing__ds__day + , subq_6.listing__ds__week + , subq_6.listing__ds__month + , subq_6.listing__ds__quarter + , subq_6.listing__ds__year + , subq_6.listing__ds__extract_year + , subq_6.listing__ds__extract_quarter + , subq_6.listing__ds__extract_month + , subq_6.listing__ds__extract_day + , subq_6.listing__ds__extract_dow + , subq_6.listing__ds__extract_doy + , subq_6.listing__created_at__day + , subq_6.listing__created_at__week + , subq_6.listing__created_at__month + , subq_6.listing__created_at__quarter + , subq_6.listing__created_at__year + , subq_6.listing__created_at__extract_year + , subq_6.listing__created_at__extract_quarter + , subq_6.listing__created_at__extract_month + , subq_6.listing__created_at__extract_day + , subq_6.listing__created_at__extract_dow + , subq_6.listing__created_at__extract_doy + , subq_6.listing + , subq_6.user + , subq_6.listing__user + , subq_6.country_latest + , subq_6.is_lux_latest + , subq_6.capacity_latest + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.user__home_state_latest + , subq_6.listings + , subq_6.largest_listing + , subq_6.smallest_listing FROM ( -- Join Standard Outputs SELECT - subq_0.ds__day AS ds__day - , subq_0.ds__week AS ds__week - , subq_0.ds__month AS ds__month - , subq_0.ds__quarter AS ds__quarter - , subq_0.ds__year AS ds__year - , subq_0.ds__extract_year AS ds__extract_year - , subq_0.ds__extract_quarter AS ds__extract_quarter - , subq_0.ds__extract_month AS ds__extract_month - , subq_0.ds__extract_day AS ds__extract_day - , subq_0.ds__extract_dow AS ds__extract_dow - , subq_0.ds__extract_doy AS ds__extract_doy - , subq_0.created_at__day AS created_at__day - , subq_0.created_at__week AS created_at__week - , subq_0.created_at__month AS created_at__month - , subq_0.created_at__quarter AS created_at__quarter - , subq_0.created_at__year AS created_at__year - , subq_0.created_at__extract_year AS created_at__extract_year - , subq_0.created_at__extract_quarter AS created_at__extract_quarter - , subq_0.created_at__extract_month AS created_at__extract_month - , subq_0.created_at__extract_day AS created_at__extract_day - , subq_0.created_at__extract_dow AS created_at__extract_dow - , subq_0.created_at__extract_doy AS created_at__extract_doy - , subq_0.listing__ds__day AS listing__ds__day - , subq_0.listing__ds__week AS listing__ds__week - , subq_0.listing__ds__month AS listing__ds__month - , subq_0.listing__ds__quarter AS listing__ds__quarter - , subq_0.listing__ds__year AS listing__ds__year - , subq_0.listing__ds__extract_year AS listing__ds__extract_year - , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter - , subq_0.listing__ds__extract_month AS listing__ds__extract_month - , subq_0.listing__ds__extract_day AS listing__ds__extract_day - , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow - , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy - , subq_0.listing__created_at__day AS listing__created_at__day - , subq_0.listing__created_at__week AS listing__created_at__week - , subq_0.listing__created_at__month AS listing__created_at__month - , subq_0.listing__created_at__quarter AS listing__created_at__quarter - , subq_0.listing__created_at__year AS listing__created_at__year - , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month - , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow - , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy - , subq_0.listing AS listing - , subq_0.user AS user - , subq_0.listing__user AS listing__user - , subq_0.country_latest AS country_latest - , subq_0.is_lux_latest AS is_lux_latest - , subq_0.capacity_latest AS capacity_latest - , subq_0.listing__country_latest AS listing__country_latest - , subq_0.listing__is_lux_latest AS listing__is_lux_latest - , subq_0.listing__capacity_latest AS listing__capacity_latest - , subq_2.home_state_latest AS user__home_state_latest - , subq_0.listings AS listings - , subq_0.largest_listing AS largest_listing - , subq_0.smallest_listing AS smallest_listing + subq_3.ds__day AS ds__day + , subq_3.ds__week AS ds__week + , subq_3.ds__month AS ds__month + , subq_3.ds__quarter AS ds__quarter + , subq_3.ds__year AS ds__year + , subq_3.ds__extract_year AS ds__extract_year + , subq_3.ds__extract_quarter AS ds__extract_quarter + , subq_3.ds__extract_month AS ds__extract_month + , subq_3.ds__extract_day AS ds__extract_day + , subq_3.ds__extract_dow AS ds__extract_dow + , subq_3.ds__extract_doy AS ds__extract_doy + , subq_3.created_at__day AS created_at__day + , subq_3.created_at__week AS created_at__week + , subq_3.created_at__month AS created_at__month + , subq_3.created_at__quarter AS created_at__quarter + , subq_3.created_at__year AS created_at__year + , subq_3.created_at__extract_year AS created_at__extract_year + , subq_3.created_at__extract_quarter AS created_at__extract_quarter + , subq_3.created_at__extract_month AS created_at__extract_month + , subq_3.created_at__extract_day AS created_at__extract_day + , subq_3.created_at__extract_dow AS created_at__extract_dow + , subq_3.created_at__extract_doy AS created_at__extract_doy + , subq_3.listing__ds__day AS listing__ds__day + , subq_3.listing__ds__week AS listing__ds__week + , subq_3.listing__ds__month AS listing__ds__month + , subq_3.listing__ds__quarter AS listing__ds__quarter + , subq_3.listing__ds__year AS listing__ds__year + , subq_3.listing__ds__extract_year AS listing__ds__extract_year + , subq_3.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_3.listing__ds__extract_month AS listing__ds__extract_month + , subq_3.listing__ds__extract_day AS listing__ds__extract_day + , subq_3.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_3.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_3.listing__created_at__day AS listing__created_at__day + , subq_3.listing__created_at__week AS listing__created_at__week + , subq_3.listing__created_at__month AS listing__created_at__month + , subq_3.listing__created_at__quarter AS listing__created_at__quarter + , subq_3.listing__created_at__year AS listing__created_at__year + , subq_3.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_3.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_3.listing AS listing + , subq_3.user AS user + , subq_3.listing__user AS listing__user + , subq_3.country_latest AS country_latest + , subq_3.is_lux_latest AS is_lux_latest + , subq_3.capacity_latest AS capacity_latest + , subq_3.listing__country_latest AS listing__country_latest + , subq_3.listing__is_lux_latest AS listing__is_lux_latest + , subq_3.listing__capacity_latest AS listing__capacity_latest + , subq_5.home_state_latest AS user__home_state_latest + , subq_3.listings AS listings + , subq_3.largest_listing AS largest_listing + , subq_3.smallest_listing AS smallest_listing FROM ( - -- Read Elements From Semantic Model 'listings_latest' + -- Constrain Output with WHERE SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , listings_latest_src_28000.user_id AS user - , listings_latest_src_28000.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_0 + subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.created_at__day + , subq_2.created_at__week + , subq_2.created_at__month + , subq_2.created_at__quarter + , subq_2.created_at__year + , subq_2.created_at__extract_year + , subq_2.created_at__extract_quarter + , subq_2.created_at__extract_month + , subq_2.created_at__extract_day + , subq_2.created_at__extract_dow + , subq_2.created_at__extract_doy + , subq_2.listing__ds__day + , subq_2.listing__ds__week + , subq_2.listing__ds__month + , subq_2.listing__ds__quarter + , subq_2.listing__ds__year + , subq_2.listing__ds__extract_year + , subq_2.listing__ds__extract_quarter + , subq_2.listing__ds__extract_month + , subq_2.listing__ds__extract_day + , subq_2.listing__ds__extract_dow + , subq_2.listing__ds__extract_doy + , subq_2.listing__created_at__day + , subq_2.listing__created_at__week + , subq_2.listing__created_at__month + , subq_2.listing__created_at__quarter + , subq_2.listing__created_at__year + , subq_2.listing__created_at__extract_year + , subq_2.listing__created_at__extract_quarter + , subq_2.listing__created_at__extract_month + , subq_2.listing__created_at__extract_day + , subq_2.listing__created_at__extract_dow + , subq_2.listing__created_at__extract_doy + , subq_2.listing + , subq_2.user + , subq_2.listing__user + , subq_2.country_latest + , subq_2.is_lux_latest + , subq_2.capacity_latest + , subq_2.listing__country_latest + , subq_2.listing__is_lux_latest + , subq_2.listing__capacity_latest + , subq_2.listings + , subq_2.largest_listing + , subq_2.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_2 + WHERE listing__country_latest = 'us' + ) subq_3 FULL OUTER JOIN ( -- Pass Only Elements: ['home_state_latest', 'user'] SELECT - subq_1.user - , subq_1.home_state_latest + subq_4.user + , subq_4.home_state_latest FROM ( -- Read Elements From Semantic Model 'users_latest' SELECT @@ -216,12 +277,12 @@ FROM ( , users_latest_src_28000.home_state_latest AS user__home_state_latest , users_latest_src_28000.user_id AS user FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_1 - ) subq_2 + ) subq_4 + ) subq_5 ON - subq_0.user = subq_2.user - ) subq_3 + subq_3.user = subq_5.user + ) subq_6 WHERE listing__country_latest = 'us' -) subq_4 +) subq_7 GROUP BY - subq_4.user__home_state_latest + subq_7.user__home_state_latest diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Snowflake/test_dimension_with_joined_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Snowflake/test_dimension_with_joined_where_constraint__plan0_optimized.sql index c4e57d3c86..f2ac976dac 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Snowflake/test_dimension_with_joined_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Snowflake/test_dimension_with_joined_where_constraint__plan0_optimized.sql @@ -5,14 +5,27 @@ SELECT FROM ( -- Join Standard Outputs SELECT - listings_latest_src_28000.country AS listing__country_latest + subq_9.listing__country_latest AS listing__country_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest - FROM ***************************.dim_listings_latest listings_latest_src_28000 + FROM ( + -- Constrain Output with WHERE + SELECT + subq_8.user + , listing__country_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + country AS listing__country_latest + , user_id AS user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_8 + WHERE listing__country_latest = 'us' + ) subq_9 FULL OUTER JOIN ***************************.dim_users_latest users_latest_src_28000 ON - listings_latest_src_28000.user_id = users_latest_src_28000.user_id -) subq_8 + subq_9.user = users_latest_src_28000.user_id +) subq_12 WHERE listing__country_latest = 'us' GROUP BY user__home_state_latest diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimension_with_joined_where_constraint__plan0.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimension_with_joined_where_constraint__plan0.sql index c30f2c64e7..0f8d5830a6 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimension_with_joined_where_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimension_with_joined_where_constraint__plan0.sql @@ -1,192 +1,253 @@ -- Pass Only Elements: ['user__home_state_latest',] SELECT - subq_4.user__home_state_latest + subq_7.user__home_state_latest FROM ( -- Constrain Output with WHERE SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.user__home_state_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing + 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.created_at__day + , subq_6.created_at__week + , subq_6.created_at__month + , subq_6.created_at__quarter + , subq_6.created_at__year + , subq_6.created_at__extract_year + , subq_6.created_at__extract_quarter + , subq_6.created_at__extract_month + , subq_6.created_at__extract_day + , subq_6.created_at__extract_dow + , subq_6.created_at__extract_doy + , subq_6.listing__ds__day + , subq_6.listing__ds__week + , subq_6.listing__ds__month + , subq_6.listing__ds__quarter + , subq_6.listing__ds__year + , subq_6.listing__ds__extract_year + , subq_6.listing__ds__extract_quarter + , subq_6.listing__ds__extract_month + , subq_6.listing__ds__extract_day + , subq_6.listing__ds__extract_dow + , subq_6.listing__ds__extract_doy + , subq_6.listing__created_at__day + , subq_6.listing__created_at__week + , subq_6.listing__created_at__month + , subq_6.listing__created_at__quarter + , subq_6.listing__created_at__year + , subq_6.listing__created_at__extract_year + , subq_6.listing__created_at__extract_quarter + , subq_6.listing__created_at__extract_month + , subq_6.listing__created_at__extract_day + , subq_6.listing__created_at__extract_dow + , subq_6.listing__created_at__extract_doy + , subq_6.listing + , subq_6.user + , subq_6.listing__user + , subq_6.country_latest + , subq_6.is_lux_latest + , subq_6.capacity_latest + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.user__home_state_latest + , subq_6.listings + , subq_6.largest_listing + , subq_6.smallest_listing FROM ( -- Join Standard Outputs SELECT - subq_0.ds__day AS ds__day - , subq_0.ds__week AS ds__week - , subq_0.ds__month AS ds__month - , subq_0.ds__quarter AS ds__quarter - , subq_0.ds__year AS ds__year - , subq_0.ds__extract_year AS ds__extract_year - , subq_0.ds__extract_quarter AS ds__extract_quarter - , subq_0.ds__extract_month AS ds__extract_month - , subq_0.ds__extract_day AS ds__extract_day - , subq_0.ds__extract_dow AS ds__extract_dow - , subq_0.ds__extract_doy AS ds__extract_doy - , subq_0.created_at__day AS created_at__day - , subq_0.created_at__week AS created_at__week - , subq_0.created_at__month AS created_at__month - , subq_0.created_at__quarter AS created_at__quarter - , subq_0.created_at__year AS created_at__year - , subq_0.created_at__extract_year AS created_at__extract_year - , subq_0.created_at__extract_quarter AS created_at__extract_quarter - , subq_0.created_at__extract_month AS created_at__extract_month - , subq_0.created_at__extract_day AS created_at__extract_day - , subq_0.created_at__extract_dow AS created_at__extract_dow - , subq_0.created_at__extract_doy AS created_at__extract_doy - , subq_0.listing__ds__day AS listing__ds__day - , subq_0.listing__ds__week AS listing__ds__week - , subq_0.listing__ds__month AS listing__ds__month - , subq_0.listing__ds__quarter AS listing__ds__quarter - , subq_0.listing__ds__year AS listing__ds__year - , subq_0.listing__ds__extract_year AS listing__ds__extract_year - , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter - , subq_0.listing__ds__extract_month AS listing__ds__extract_month - , subq_0.listing__ds__extract_day AS listing__ds__extract_day - , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow - , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy - , subq_0.listing__created_at__day AS listing__created_at__day - , subq_0.listing__created_at__week AS listing__created_at__week - , subq_0.listing__created_at__month AS listing__created_at__month - , subq_0.listing__created_at__quarter AS listing__created_at__quarter - , subq_0.listing__created_at__year AS listing__created_at__year - , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month - , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow - , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy - , subq_0.listing AS listing - , subq_0.user AS user - , subq_0.listing__user AS listing__user - , subq_0.country_latest AS country_latest - , subq_0.is_lux_latest AS is_lux_latest - , subq_0.capacity_latest AS capacity_latest - , subq_0.listing__country_latest AS listing__country_latest - , subq_0.listing__is_lux_latest AS listing__is_lux_latest - , subq_0.listing__capacity_latest AS listing__capacity_latest - , subq_2.home_state_latest AS user__home_state_latest - , subq_0.listings AS listings - , subq_0.largest_listing AS largest_listing - , subq_0.smallest_listing AS smallest_listing + subq_3.ds__day AS ds__day + , subq_3.ds__week AS ds__week + , subq_3.ds__month AS ds__month + , subq_3.ds__quarter AS ds__quarter + , subq_3.ds__year AS ds__year + , subq_3.ds__extract_year AS ds__extract_year + , subq_3.ds__extract_quarter AS ds__extract_quarter + , subq_3.ds__extract_month AS ds__extract_month + , subq_3.ds__extract_day AS ds__extract_day + , subq_3.ds__extract_dow AS ds__extract_dow + , subq_3.ds__extract_doy AS ds__extract_doy + , subq_3.created_at__day AS created_at__day + , subq_3.created_at__week AS created_at__week + , subq_3.created_at__month AS created_at__month + , subq_3.created_at__quarter AS created_at__quarter + , subq_3.created_at__year AS created_at__year + , subq_3.created_at__extract_year AS created_at__extract_year + , subq_3.created_at__extract_quarter AS created_at__extract_quarter + , subq_3.created_at__extract_month AS created_at__extract_month + , subq_3.created_at__extract_day AS created_at__extract_day + , subq_3.created_at__extract_dow AS created_at__extract_dow + , subq_3.created_at__extract_doy AS created_at__extract_doy + , subq_3.listing__ds__day AS listing__ds__day + , subq_3.listing__ds__week AS listing__ds__week + , subq_3.listing__ds__month AS listing__ds__month + , subq_3.listing__ds__quarter AS listing__ds__quarter + , subq_3.listing__ds__year AS listing__ds__year + , subq_3.listing__ds__extract_year AS listing__ds__extract_year + , subq_3.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_3.listing__ds__extract_month AS listing__ds__extract_month + , subq_3.listing__ds__extract_day AS listing__ds__extract_day + , subq_3.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_3.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_3.listing__created_at__day AS listing__created_at__day + , subq_3.listing__created_at__week AS listing__created_at__week + , subq_3.listing__created_at__month AS listing__created_at__month + , subq_3.listing__created_at__quarter AS listing__created_at__quarter + , subq_3.listing__created_at__year AS listing__created_at__year + , subq_3.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_3.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_3.listing AS listing + , subq_3.user AS user + , subq_3.listing__user AS listing__user + , subq_3.country_latest AS country_latest + , subq_3.is_lux_latest AS is_lux_latest + , subq_3.capacity_latest AS capacity_latest + , subq_3.listing__country_latest AS listing__country_latest + , subq_3.listing__is_lux_latest AS listing__is_lux_latest + , subq_3.listing__capacity_latest AS listing__capacity_latest + , subq_5.home_state_latest AS user__home_state_latest + , subq_3.listings AS listings + , subq_3.largest_listing AS largest_listing + , subq_3.smallest_listing AS smallest_listing FROM ( - -- Read Elements From Semantic Model 'listings_latest' + -- Constrain Output with WHERE SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , listings_latest_src_28000.user_id AS user - , listings_latest_src_28000.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_0 + subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.created_at__day + , subq_2.created_at__week + , subq_2.created_at__month + , subq_2.created_at__quarter + , subq_2.created_at__year + , subq_2.created_at__extract_year + , subq_2.created_at__extract_quarter + , subq_2.created_at__extract_month + , subq_2.created_at__extract_day + , subq_2.created_at__extract_dow + , subq_2.created_at__extract_doy + , subq_2.listing__ds__day + , subq_2.listing__ds__week + , subq_2.listing__ds__month + , subq_2.listing__ds__quarter + , subq_2.listing__ds__year + , subq_2.listing__ds__extract_year + , subq_2.listing__ds__extract_quarter + , subq_2.listing__ds__extract_month + , subq_2.listing__ds__extract_day + , subq_2.listing__ds__extract_dow + , subq_2.listing__ds__extract_doy + , subq_2.listing__created_at__day + , subq_2.listing__created_at__week + , subq_2.listing__created_at__month + , subq_2.listing__created_at__quarter + , subq_2.listing__created_at__year + , subq_2.listing__created_at__extract_year + , subq_2.listing__created_at__extract_quarter + , subq_2.listing__created_at__extract_month + , subq_2.listing__created_at__extract_day + , subq_2.listing__created_at__extract_dow + , subq_2.listing__created_at__extract_doy + , subq_2.listing + , subq_2.user + , subq_2.listing__user + , subq_2.country_latest + , subq_2.is_lux_latest + , subq_2.capacity_latest + , subq_2.listing__country_latest + , subq_2.listing__is_lux_latest + , subq_2.listing__capacity_latest + , subq_2.listings + , subq_2.largest_listing + , subq_2.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_2 + WHERE listing__country_latest = 'us' + ) subq_3 FULL OUTER JOIN ( -- Pass Only Elements: ['home_state_latest', 'user'] SELECT - subq_1.user - , subq_1.home_state_latest + subq_4.user + , subq_4.home_state_latest FROM ( -- Read Elements From Semantic Model 'users_latest' SELECT @@ -216,12 +277,12 @@ FROM ( , users_latest_src_28000.home_state_latest AS user__home_state_latest , users_latest_src_28000.user_id AS user FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_1 - ) subq_2 + ) subq_4 + ) subq_5 ON - subq_0.user = subq_2.user - ) subq_3 + subq_3.user = subq_5.user + ) subq_6 WHERE listing__country_latest = 'us' -) subq_4 +) subq_7 GROUP BY - subq_4.user__home_state_latest + subq_7.user__home_state_latest diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimension_with_joined_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimension_with_joined_where_constraint__plan0_optimized.sql index c4e57d3c86..f2ac976dac 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimension_with_joined_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimension_with_joined_where_constraint__plan0_optimized.sql @@ -5,14 +5,27 @@ SELECT FROM ( -- Join Standard Outputs SELECT - listings_latest_src_28000.country AS listing__country_latest + subq_9.listing__country_latest AS listing__country_latest , users_latest_src_28000.home_state_latest AS user__home_state_latest - FROM ***************************.dim_listings_latest listings_latest_src_28000 + FROM ( + -- Constrain Output with WHERE + SELECT + subq_8.user + , listing__country_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + country AS listing__country_latest + , user_id AS user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_8 + WHERE listing__country_latest = 'us' + ) subq_9 FULL OUTER JOIN ***************************.dim_users_latest users_latest_src_28000 ON - listings_latest_src_28000.user_id = users_latest_src_28000.user_id -) subq_8 + subq_9.user = users_latest_src_28000.user_id +) subq_12 WHERE listing__country_latest = 'us' GROUP BY user__home_state_latest diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_filters__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_filters__plan0.sql index 7645de589c..61b7bee195 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_filters__plan0.sql @@ -8,317 +8,420 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_11.average_booking_value) AS average_booking_value - , MAX(subq_23.bookings) AS bookings - , MAX(subq_30.booking_value) AS booking_value + MAX(subq_30.average_booking_value) AS average_booking_value + , MAX(subq_43.bookings) AS bookings + , MAX(subq_51.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_10.average_booking_value + subq_29.average_booking_value FROM ( -- Aggregate Measures SELECT - AVG(subq_9.average_booking_value) AS average_booking_value + AVG(subq_28.average_booking_value) AS average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value',] SELECT - subq_8.average_booking_value + subq_27.average_booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_7.booking__is_instant - , subq_7.listing__is_lux_latest - , subq_7.average_booking_value + subq_26.booking__is_instant + , subq_26.listing__is_lux_latest + , subq_26.average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_6.booking__is_instant - , subq_6.listing__is_lux_latest - , subq_6.average_booking_value + subq_25.booking__is_instant + , subq_25.listing__is_lux_latest + , subq_25.average_booking_value FROM ( -- Join Standard Outputs SELECT - subq_2.listing AS listing - , subq_2.booking__is_instant AS booking__is_instant - , subq_5.is_lux_latest AS listing__is_lux_latest - , subq_2.average_booking_value AS average_booking_value + subq_21.listing AS listing + , subq_21.booking__is_instant AS booking__is_instant + , subq_24.is_lux_latest AS listing__is_lux_latest + , subq_21.average_booking_value AS average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] SELECT - subq_1.listing - , subq_1.booking__is_instant - , subq_1.average_booking_value + subq_20.listing + , subq_20.booking__is_instant + , subq_20.average_booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE 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.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.booking__paid_at__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.listing - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_19.ds__day + , subq_19.ds__week + , subq_19.ds__month + , subq_19.ds__quarter + , subq_19.ds__year + , subq_19.ds__extract_year + , subq_19.ds__extract_quarter + , subq_19.ds__extract_month + , subq_19.ds__extract_day + , subq_19.ds__extract_dow + , subq_19.ds__extract_doy + , subq_19.ds_partitioned__day + , subq_19.ds_partitioned__week + , subq_19.ds_partitioned__month + , subq_19.ds_partitioned__quarter + , subq_19.ds_partitioned__year + , subq_19.ds_partitioned__extract_year + , subq_19.ds_partitioned__extract_quarter + , subq_19.ds_partitioned__extract_month + , subq_19.ds_partitioned__extract_day + , subq_19.ds_partitioned__extract_dow + , subq_19.ds_partitioned__extract_doy + , subq_19.paid_at__day + , subq_19.paid_at__week + , subq_19.paid_at__month + , subq_19.paid_at__quarter + , subq_19.paid_at__year + , subq_19.paid_at__extract_year + , subq_19.paid_at__extract_quarter + , subq_19.paid_at__extract_month + , subq_19.paid_at__extract_day + , subq_19.paid_at__extract_dow + , subq_19.paid_at__extract_doy + , subq_19.booking__ds__day + , subq_19.booking__ds__week + , subq_19.booking__ds__month + , subq_19.booking__ds__quarter + , subq_19.booking__ds__year + , subq_19.booking__ds__extract_year + , subq_19.booking__ds__extract_quarter + , subq_19.booking__ds__extract_month + , subq_19.booking__ds__extract_day + , subq_19.booking__ds__extract_dow + , subq_19.booking__ds__extract_doy + , subq_19.booking__ds_partitioned__day + , subq_19.booking__ds_partitioned__week + , subq_19.booking__ds_partitioned__month + , subq_19.booking__ds_partitioned__quarter + , subq_19.booking__ds_partitioned__year + , subq_19.booking__ds_partitioned__extract_year + , subq_19.booking__ds_partitioned__extract_quarter + , subq_19.booking__ds_partitioned__extract_month + , subq_19.booking__ds_partitioned__extract_day + , subq_19.booking__ds_partitioned__extract_dow + , subq_19.booking__ds_partitioned__extract_doy + , subq_19.booking__paid_at__day + , subq_19.booking__paid_at__week + , subq_19.booking__paid_at__month + , subq_19.booking__paid_at__quarter + , subq_19.booking__paid_at__year + , subq_19.booking__paid_at__extract_year + , subq_19.booking__paid_at__extract_quarter + , subq_19.booking__paid_at__extract_month + , subq_19.booking__paid_at__extract_day + , subq_19.booking__paid_at__extract_dow + , subq_19.booking__paid_at__extract_doy + , subq_19.metric_time__day + , subq_19.metric_time__week + , subq_19.metric_time__month + , subq_19.metric_time__quarter + , subq_19.metric_time__year + , subq_19.metric_time__extract_year + , subq_19.metric_time__extract_quarter + , subq_19.metric_time__extract_month + , subq_19.metric_time__extract_day + , subq_19.metric_time__extract_dow + , subq_19.metric_time__extract_doy + , subq_19.listing + , subq_19.guest + , subq_19.host + , subq_19.booking__listing + , subq_19.booking__guest + , subq_19.booking__host + , subq_19.is_instant + , subq_19.booking__is_instant + , subq_19.bookings + , subq_19.instant_bookings + , subq_19.booking_value + , subq_19.max_booking_value + , subq_19.min_booking_value + , subq_19.bookers + , subq_19.average_booking_value + , subq_19.referred_bookings + , subq_19.median_booking_value + , subq_19.booking_value_p99 + , subq_19.discrete_booking_value_p99 + , subq_19.approximate_continuous_booking_value_p99 + , subq_19.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC(bookings_source_src_28000.ds, day) AS ds__day - , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS ds__week - , DATE_TRUNC(bookings_source_src_28000.ds, month) AS ds__month - , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS ds__quarter - , DATE_TRUNC(bookings_source_src_28000.ds, year) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS ds__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS ds_partitioned__day - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS ds_partitioned__week - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS ds_partitioned__month - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS ds_partitioned__quarter - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS ds_partitioned__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS paid_at__day - , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS paid_at__week - , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS paid_at__month - , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS paid_at__quarter - , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS paid_at__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC(bookings_source_src_28000.ds, day) AS booking__ds__day - , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS booking__ds__week - , DATE_TRUNC(bookings_source_src_28000.ds, month) AS booking__ds__month - , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS booking__ds__quarter - , DATE_TRUNC(bookings_source_src_28000.ds, year) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS booking__ds__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS booking__ds_partitioned__day - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS booking__ds_partitioned__week - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS booking__ds_partitioned__month - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS booking__ds_partitioned__quarter - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS booking__ds_partitioned__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS booking__paid_at__day - , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS booking__paid_at__week - , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS booking__paid_at__month - , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS booking__paid_at__quarter - , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS booking__paid_at__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + subq_18.ds__day + , subq_18.ds__week + , subq_18.ds__month + , subq_18.ds__quarter + , subq_18.ds__year + , subq_18.ds__extract_year + , subq_18.ds__extract_quarter + , subq_18.ds__extract_month + , subq_18.ds__extract_day + , subq_18.ds__extract_dow + , subq_18.ds__extract_doy + , subq_18.ds_partitioned__day + , subq_18.ds_partitioned__week + , subq_18.ds_partitioned__month + , subq_18.ds_partitioned__quarter + , subq_18.ds_partitioned__year + , subq_18.ds_partitioned__extract_year + , subq_18.ds_partitioned__extract_quarter + , subq_18.ds_partitioned__extract_month + , subq_18.ds_partitioned__extract_day + , subq_18.ds_partitioned__extract_dow + , subq_18.ds_partitioned__extract_doy + , subq_18.paid_at__day + , subq_18.paid_at__week + , subq_18.paid_at__month + , subq_18.paid_at__quarter + , subq_18.paid_at__year + , subq_18.paid_at__extract_year + , subq_18.paid_at__extract_quarter + , subq_18.paid_at__extract_month + , subq_18.paid_at__extract_day + , subq_18.paid_at__extract_dow + , subq_18.paid_at__extract_doy + , subq_18.booking__ds__day + , subq_18.booking__ds__week + , subq_18.booking__ds__month + , subq_18.booking__ds__quarter + , subq_18.booking__ds__year + , subq_18.booking__ds__extract_year + , subq_18.booking__ds__extract_quarter + , subq_18.booking__ds__extract_month + , subq_18.booking__ds__extract_day + , subq_18.booking__ds__extract_dow + , subq_18.booking__ds__extract_doy + , subq_18.booking__ds_partitioned__day + , subq_18.booking__ds_partitioned__week + , subq_18.booking__ds_partitioned__month + , subq_18.booking__ds_partitioned__quarter + , subq_18.booking__ds_partitioned__year + , subq_18.booking__ds_partitioned__extract_year + , subq_18.booking__ds_partitioned__extract_quarter + , subq_18.booking__ds_partitioned__extract_month + , subq_18.booking__ds_partitioned__extract_day + , subq_18.booking__ds_partitioned__extract_dow + , subq_18.booking__ds_partitioned__extract_doy + , subq_18.booking__paid_at__day + , subq_18.booking__paid_at__week + , subq_18.booking__paid_at__month + , subq_18.booking__paid_at__quarter + , subq_18.booking__paid_at__year + , subq_18.booking__paid_at__extract_year + , subq_18.booking__paid_at__extract_quarter + , subq_18.booking__paid_at__extract_month + , subq_18.booking__paid_at__extract_day + , subq_18.booking__paid_at__extract_dow + , subq_18.booking__paid_at__extract_doy + , subq_18.ds__day AS metric_time__day + , subq_18.ds__week AS metric_time__week + , subq_18.ds__month AS metric_time__month + , subq_18.ds__quarter AS metric_time__quarter + , subq_18.ds__year AS metric_time__year + , subq_18.ds__extract_year AS metric_time__extract_year + , subq_18.ds__extract_quarter AS metric_time__extract_quarter + , subq_18.ds__extract_month AS metric_time__extract_month + , subq_18.ds__extract_day AS metric_time__extract_day + , subq_18.ds__extract_dow AS metric_time__extract_dow + , subq_18.ds__extract_doy AS metric_time__extract_doy + , subq_18.listing + , subq_18.guest + , subq_18.host + , subq_18.booking__listing + , subq_18.booking__guest + , subq_18.booking__host + , subq_18.is_instant + , subq_18.booking__is_instant + , subq_18.bookings + , subq_18.instant_bookings + , subq_18.booking_value + , subq_18.max_booking_value + , subq_18.min_booking_value + , subq_18.bookers + , subq_18.average_booking_value + , subq_18.referred_bookings + , subq_18.median_booking_value + , subq_18.booking_value_p99 + , subq_18.discrete_booking_value_p99 + , subq_18.approximate_continuous_booking_value_p99 + , subq_18.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC(bookings_source_src_28000.ds, day) AS ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC(bookings_source_src_28000.ds, day) AS booking__ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS booking__ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS booking__ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS booking__ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS booking__ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS booking__ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS booking__ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS booking__ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS booking__ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS booking__ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS booking__paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS booking__paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS booking__paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS booking__paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS booking__paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_18 + ) subq_19 + WHERE booking__is_instant + ) subq_20 + ) subq_21 LEFT OUTER JOIN ( -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_4.listing - , subq_4.is_lux_latest + subq_23.listing + , subq_23.is_lux_latest FROM ( -- Metric Time Dimension 'ds' SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing + subq_22.ds__day + , subq_22.ds__week + , subq_22.ds__month + , subq_22.ds__quarter + , subq_22.ds__year + , subq_22.ds__extract_year + , subq_22.ds__extract_quarter + , subq_22.ds__extract_month + , subq_22.ds__extract_day + , subq_22.ds__extract_dow + , subq_22.ds__extract_doy + , subq_22.created_at__day + , subq_22.created_at__week + , subq_22.created_at__month + , subq_22.created_at__quarter + , subq_22.created_at__year + , subq_22.created_at__extract_year + , subq_22.created_at__extract_quarter + , subq_22.created_at__extract_month + , subq_22.created_at__extract_day + , subq_22.created_at__extract_dow + , subq_22.created_at__extract_doy + , subq_22.listing__ds__day + , subq_22.listing__ds__week + , subq_22.listing__ds__month + , subq_22.listing__ds__quarter + , subq_22.listing__ds__year + , subq_22.listing__ds__extract_year + , subq_22.listing__ds__extract_quarter + , subq_22.listing__ds__extract_month + , subq_22.listing__ds__extract_day + , subq_22.listing__ds__extract_dow + , subq_22.listing__ds__extract_doy + , subq_22.listing__created_at__day + , subq_22.listing__created_at__week + , subq_22.listing__created_at__month + , subq_22.listing__created_at__quarter + , subq_22.listing__created_at__year + , subq_22.listing__created_at__extract_year + , subq_22.listing__created_at__extract_quarter + , subq_22.listing__created_at__extract_month + , subq_22.listing__created_at__extract_day + , subq_22.listing__created_at__extract_dow + , subq_22.listing__created_at__extract_doy + , subq_22.ds__day AS metric_time__day + , subq_22.ds__week AS metric_time__week + , subq_22.ds__month AS metric_time__month + , subq_22.ds__quarter AS metric_time__quarter + , subq_22.ds__year AS metric_time__year + , subq_22.ds__extract_year AS metric_time__extract_year + , subq_22.ds__extract_quarter AS metric_time__extract_quarter + , subq_22.ds__extract_month AS metric_time__extract_month + , subq_22.ds__extract_day AS metric_time__extract_day + , subq_22.ds__extract_dow AS metric_time__extract_dow + , subq_22.ds__extract_doy AS metric_time__extract_doy + , subq_22.listing + , subq_22.user + , subq_22.listing__user + , subq_22.country_latest + , subq_22.is_lux_latest + , subq_22.capacity_latest + , subq_22.listing__country_latest + , subq_22.listing__is_lux_latest + , subq_22.listing__capacity_latest + , subq_22.listings + , subq_22.largest_listing + , subq_22.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -379,326 +482,429 @@ FROM ( , listings_latest_src_28000.user_id AS user , listings_latest_src_28000.user_id AS listing__user FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_3 - ) subq_4 - ) subq_5 + ) subq_22 + ) subq_23 + ) subq_24 ON - subq_2.listing = subq_5.listing - ) subq_6 - ) subq_7 + subq_21.listing = subq_24.listing + ) subq_25 + ) subq_26 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_8 - ) subq_9 - ) subq_10 - ) subq_11 + ) subq_27 + ) subq_28 + ) subq_29 + ) subq_30 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_22.bookings + subq_42.bookings FROM ( -- Aggregate Measures SELECT - SUM(subq_21.bookings) AS bookings + SUM(subq_41.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings',] SELECT - subq_20.bookings + subq_40.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_19.booking__is_instant - , subq_19.listing__is_lux_latest - , subq_19.bookings + subq_39.booking__is_instant + , subq_39.listing__is_lux_latest + , subq_39.bookings FROM ( -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_18.booking__is_instant - , subq_18.listing__is_lux_latest - , subq_18.bookings + subq_38.booking__is_instant + , subq_38.listing__is_lux_latest + , subq_38.bookings FROM ( -- Join Standard Outputs SELECT - subq_14.listing AS listing - , subq_14.booking__is_instant AS booking__is_instant - , subq_17.is_lux_latest AS listing__is_lux_latest - , subq_14.bookings AS bookings + subq_34.listing AS listing + , subq_34.booking__is_instant AS booking__is_instant + , subq_37.is_lux_latest AS listing__is_lux_latest + , subq_34.bookings AS bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - subq_13.listing - , subq_13.booking__is_instant - , subq_13.bookings + subq_33.listing + , subq_33.booking__is_instant + , subq_33.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_12.ds__day - , subq_12.ds__week - , subq_12.ds__month - , subq_12.ds__quarter - , subq_12.ds__year - , subq_12.ds__extract_year - , subq_12.ds__extract_quarter - , subq_12.ds__extract_month - , subq_12.ds__extract_day - , subq_12.ds__extract_dow - , subq_12.ds__extract_doy - , subq_12.ds_partitioned__day - , subq_12.ds_partitioned__week - , subq_12.ds_partitioned__month - , subq_12.ds_partitioned__quarter - , subq_12.ds_partitioned__year - , subq_12.ds_partitioned__extract_year - , subq_12.ds_partitioned__extract_quarter - , subq_12.ds_partitioned__extract_month - , subq_12.ds_partitioned__extract_day - , subq_12.ds_partitioned__extract_dow - , subq_12.ds_partitioned__extract_doy - , subq_12.paid_at__day - , subq_12.paid_at__week - , subq_12.paid_at__month - , subq_12.paid_at__quarter - , subq_12.paid_at__year - , subq_12.paid_at__extract_year - , subq_12.paid_at__extract_quarter - , subq_12.paid_at__extract_month - , subq_12.paid_at__extract_day - , subq_12.paid_at__extract_dow - , subq_12.paid_at__extract_doy - , subq_12.booking__ds__day - , subq_12.booking__ds__week - , subq_12.booking__ds__month - , subq_12.booking__ds__quarter - , subq_12.booking__ds__year - , subq_12.booking__ds__extract_year - , subq_12.booking__ds__extract_quarter - , subq_12.booking__ds__extract_month - , subq_12.booking__ds__extract_day - , subq_12.booking__ds__extract_dow - , subq_12.booking__ds__extract_doy - , subq_12.booking__ds_partitioned__day - , subq_12.booking__ds_partitioned__week - , subq_12.booking__ds_partitioned__month - , subq_12.booking__ds_partitioned__quarter - , subq_12.booking__ds_partitioned__year - , subq_12.booking__ds_partitioned__extract_year - , subq_12.booking__ds_partitioned__extract_quarter - , subq_12.booking__ds_partitioned__extract_month - , subq_12.booking__ds_partitioned__extract_day - , subq_12.booking__ds_partitioned__extract_dow - , subq_12.booking__ds_partitioned__extract_doy - , subq_12.booking__paid_at__day - , subq_12.booking__paid_at__week - , subq_12.booking__paid_at__month - , subq_12.booking__paid_at__quarter - , subq_12.booking__paid_at__year - , subq_12.booking__paid_at__extract_year - , subq_12.booking__paid_at__extract_quarter - , subq_12.booking__paid_at__extract_month - , subq_12.booking__paid_at__extract_day - , subq_12.booking__paid_at__extract_dow - , subq_12.booking__paid_at__extract_doy - , subq_12.ds__day AS metric_time__day - , subq_12.ds__week AS metric_time__week - , subq_12.ds__month AS metric_time__month - , subq_12.ds__quarter AS metric_time__quarter - , subq_12.ds__year AS metric_time__year - , subq_12.ds__extract_year AS metric_time__extract_year - , subq_12.ds__extract_quarter AS metric_time__extract_quarter - , subq_12.ds__extract_month AS metric_time__extract_month - , subq_12.ds__extract_day AS metric_time__extract_day - , subq_12.ds__extract_dow AS metric_time__extract_dow - , subq_12.ds__extract_doy AS metric_time__extract_doy - , subq_12.listing - , subq_12.guest - , subq_12.host - , subq_12.booking__listing - , subq_12.booking__guest - , subq_12.booking__host - , subq_12.is_instant - , subq_12.booking__is_instant - , subq_12.bookings - , subq_12.instant_bookings - , subq_12.booking_value - , subq_12.max_booking_value - , subq_12.min_booking_value - , subq_12.bookers - , subq_12.average_booking_value - , subq_12.referred_bookings - , subq_12.median_booking_value - , subq_12.booking_value_p99 - , subq_12.discrete_booking_value_p99 - , subq_12.approximate_continuous_booking_value_p99 - , subq_12.approximate_discrete_booking_value_p99 + subq_32.ds__day + , subq_32.ds__week + , subq_32.ds__month + , subq_32.ds__quarter + , subq_32.ds__year + , subq_32.ds__extract_year + , subq_32.ds__extract_quarter + , subq_32.ds__extract_month + , subq_32.ds__extract_day + , subq_32.ds__extract_dow + , subq_32.ds__extract_doy + , subq_32.ds_partitioned__day + , subq_32.ds_partitioned__week + , subq_32.ds_partitioned__month + , subq_32.ds_partitioned__quarter + , subq_32.ds_partitioned__year + , subq_32.ds_partitioned__extract_year + , subq_32.ds_partitioned__extract_quarter + , subq_32.ds_partitioned__extract_month + , subq_32.ds_partitioned__extract_day + , subq_32.ds_partitioned__extract_dow + , subq_32.ds_partitioned__extract_doy + , subq_32.paid_at__day + , subq_32.paid_at__week + , subq_32.paid_at__month + , subq_32.paid_at__quarter + , subq_32.paid_at__year + , subq_32.paid_at__extract_year + , subq_32.paid_at__extract_quarter + , subq_32.paid_at__extract_month + , subq_32.paid_at__extract_day + , subq_32.paid_at__extract_dow + , subq_32.paid_at__extract_doy + , subq_32.booking__ds__day + , subq_32.booking__ds__week + , subq_32.booking__ds__month + , subq_32.booking__ds__quarter + , subq_32.booking__ds__year + , subq_32.booking__ds__extract_year + , subq_32.booking__ds__extract_quarter + , subq_32.booking__ds__extract_month + , subq_32.booking__ds__extract_day + , subq_32.booking__ds__extract_dow + , subq_32.booking__ds__extract_doy + , subq_32.booking__ds_partitioned__day + , subq_32.booking__ds_partitioned__week + , subq_32.booking__ds_partitioned__month + , subq_32.booking__ds_partitioned__quarter + , subq_32.booking__ds_partitioned__year + , subq_32.booking__ds_partitioned__extract_year + , subq_32.booking__ds_partitioned__extract_quarter + , subq_32.booking__ds_partitioned__extract_month + , subq_32.booking__ds_partitioned__extract_day + , subq_32.booking__ds_partitioned__extract_dow + , subq_32.booking__ds_partitioned__extract_doy + , subq_32.booking__paid_at__day + , subq_32.booking__paid_at__week + , subq_32.booking__paid_at__month + , subq_32.booking__paid_at__quarter + , subq_32.booking__paid_at__year + , subq_32.booking__paid_at__extract_year + , subq_32.booking__paid_at__extract_quarter + , subq_32.booking__paid_at__extract_month + , subq_32.booking__paid_at__extract_day + , subq_32.booking__paid_at__extract_dow + , subq_32.booking__paid_at__extract_doy + , subq_32.metric_time__day + , subq_32.metric_time__week + , subq_32.metric_time__month + , subq_32.metric_time__quarter + , subq_32.metric_time__year + , subq_32.metric_time__extract_year + , subq_32.metric_time__extract_quarter + , subq_32.metric_time__extract_month + , subq_32.metric_time__extract_day + , subq_32.metric_time__extract_dow + , subq_32.metric_time__extract_doy + , subq_32.listing + , subq_32.guest + , subq_32.host + , subq_32.booking__listing + , subq_32.booking__guest + , subq_32.booking__host + , subq_32.is_instant + , subq_32.booking__is_instant + , subq_32.bookings + , subq_32.instant_bookings + , subq_32.booking_value + , subq_32.max_booking_value + , subq_32.min_booking_value + , subq_32.bookers + , subq_32.average_booking_value + , subq_32.referred_bookings + , subq_32.median_booking_value + , subq_32.booking_value_p99 + , subq_32.discrete_booking_value_p99 + , subq_32.approximate_continuous_booking_value_p99 + , subq_32.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC(bookings_source_src_28000.ds, day) AS ds__day - , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS ds__week - , DATE_TRUNC(bookings_source_src_28000.ds, month) AS ds__month - , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS ds__quarter - , DATE_TRUNC(bookings_source_src_28000.ds, year) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS ds__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS ds_partitioned__day - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS ds_partitioned__week - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS ds_partitioned__month - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS ds_partitioned__quarter - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS ds_partitioned__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS paid_at__day - , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS paid_at__week - , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS paid_at__month - , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS paid_at__quarter - , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS paid_at__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC(bookings_source_src_28000.ds, day) AS booking__ds__day - , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS booking__ds__week - , DATE_TRUNC(bookings_source_src_28000.ds, month) AS booking__ds__month - , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS booking__ds__quarter - , DATE_TRUNC(bookings_source_src_28000.ds, year) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS booking__ds__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS booking__ds_partitioned__day - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS booking__ds_partitioned__week - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS booking__ds_partitioned__month - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS booking__ds_partitioned__quarter - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS booking__ds_partitioned__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS booking__paid_at__day - , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS booking__paid_at__week - , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS booking__paid_at__month - , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS booking__paid_at__quarter - , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS booking__paid_at__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_12 - ) subq_13 - ) subq_14 + subq_31.ds__day + , subq_31.ds__week + , subq_31.ds__month + , subq_31.ds__quarter + , subq_31.ds__year + , subq_31.ds__extract_year + , subq_31.ds__extract_quarter + , subq_31.ds__extract_month + , subq_31.ds__extract_day + , subq_31.ds__extract_dow + , subq_31.ds__extract_doy + , subq_31.ds_partitioned__day + , subq_31.ds_partitioned__week + , subq_31.ds_partitioned__month + , subq_31.ds_partitioned__quarter + , subq_31.ds_partitioned__year + , subq_31.ds_partitioned__extract_year + , subq_31.ds_partitioned__extract_quarter + , subq_31.ds_partitioned__extract_month + , subq_31.ds_partitioned__extract_day + , subq_31.ds_partitioned__extract_dow + , subq_31.ds_partitioned__extract_doy + , subq_31.paid_at__day + , subq_31.paid_at__week + , subq_31.paid_at__month + , subq_31.paid_at__quarter + , subq_31.paid_at__year + , subq_31.paid_at__extract_year + , subq_31.paid_at__extract_quarter + , subq_31.paid_at__extract_month + , subq_31.paid_at__extract_day + , subq_31.paid_at__extract_dow + , subq_31.paid_at__extract_doy + , subq_31.booking__ds__day + , subq_31.booking__ds__week + , subq_31.booking__ds__month + , subq_31.booking__ds__quarter + , subq_31.booking__ds__year + , subq_31.booking__ds__extract_year + , subq_31.booking__ds__extract_quarter + , subq_31.booking__ds__extract_month + , subq_31.booking__ds__extract_day + , subq_31.booking__ds__extract_dow + , subq_31.booking__ds__extract_doy + , subq_31.booking__ds_partitioned__day + , subq_31.booking__ds_partitioned__week + , subq_31.booking__ds_partitioned__month + , subq_31.booking__ds_partitioned__quarter + , subq_31.booking__ds_partitioned__year + , subq_31.booking__ds_partitioned__extract_year + , subq_31.booking__ds_partitioned__extract_quarter + , subq_31.booking__ds_partitioned__extract_month + , subq_31.booking__ds_partitioned__extract_day + , subq_31.booking__ds_partitioned__extract_dow + , subq_31.booking__ds_partitioned__extract_doy + , subq_31.booking__paid_at__day + , subq_31.booking__paid_at__week + , subq_31.booking__paid_at__month + , subq_31.booking__paid_at__quarter + , subq_31.booking__paid_at__year + , subq_31.booking__paid_at__extract_year + , subq_31.booking__paid_at__extract_quarter + , subq_31.booking__paid_at__extract_month + , subq_31.booking__paid_at__extract_day + , subq_31.booking__paid_at__extract_dow + , subq_31.booking__paid_at__extract_doy + , subq_31.ds__day AS metric_time__day + , subq_31.ds__week AS metric_time__week + , subq_31.ds__month AS metric_time__month + , subq_31.ds__quarter AS metric_time__quarter + , subq_31.ds__year AS metric_time__year + , subq_31.ds__extract_year AS metric_time__extract_year + , subq_31.ds__extract_quarter AS metric_time__extract_quarter + , subq_31.ds__extract_month AS metric_time__extract_month + , subq_31.ds__extract_day AS metric_time__extract_day + , subq_31.ds__extract_dow AS metric_time__extract_dow + , subq_31.ds__extract_doy AS metric_time__extract_doy + , subq_31.listing + , subq_31.guest + , subq_31.host + , subq_31.booking__listing + , subq_31.booking__guest + , subq_31.booking__host + , subq_31.is_instant + , subq_31.booking__is_instant + , subq_31.bookings + , subq_31.instant_bookings + , subq_31.booking_value + , subq_31.max_booking_value + , subq_31.min_booking_value + , subq_31.bookers + , subq_31.average_booking_value + , subq_31.referred_bookings + , subq_31.median_booking_value + , subq_31.booking_value_p99 + , subq_31.discrete_booking_value_p99 + , subq_31.approximate_continuous_booking_value_p99 + , subq_31.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC(bookings_source_src_28000.ds, day) AS ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC(bookings_source_src_28000.ds, day) AS booking__ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS booking__ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS booking__ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS booking__ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS booking__ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS booking__ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS booking__ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS booking__ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS booking__ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS booking__ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS booking__paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS booking__paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS booking__paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS booking__paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS booking__paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_31 + ) subq_32 + WHERE booking__is_instant + ) subq_33 + ) subq_34 LEFT OUTER JOIN ( -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_16.listing - , subq_16.is_lux_latest + subq_36.listing + , subq_36.is_lux_latest FROM ( -- Metric Time Dimension 'ds' SELECT - subq_15.ds__day - , subq_15.ds__week - , subq_15.ds__month - , subq_15.ds__quarter - , subq_15.ds__year - , subq_15.ds__extract_year - , subq_15.ds__extract_quarter - , subq_15.ds__extract_month - , subq_15.ds__extract_day - , subq_15.ds__extract_dow - , subq_15.ds__extract_doy - , subq_15.created_at__day - , subq_15.created_at__week - , subq_15.created_at__month - , subq_15.created_at__quarter - , subq_15.created_at__year - , subq_15.created_at__extract_year - , subq_15.created_at__extract_quarter - , subq_15.created_at__extract_month - , subq_15.created_at__extract_day - , subq_15.created_at__extract_dow - , subq_15.created_at__extract_doy - , subq_15.listing__ds__day - , subq_15.listing__ds__week - , subq_15.listing__ds__month - , subq_15.listing__ds__quarter - , subq_15.listing__ds__year - , subq_15.listing__ds__extract_year - , subq_15.listing__ds__extract_quarter - , subq_15.listing__ds__extract_month - , subq_15.listing__ds__extract_day - , subq_15.listing__ds__extract_dow - , subq_15.listing__ds__extract_doy - , subq_15.listing__created_at__day - , subq_15.listing__created_at__week - , subq_15.listing__created_at__month - , subq_15.listing__created_at__quarter - , subq_15.listing__created_at__year - , subq_15.listing__created_at__extract_year - , subq_15.listing__created_at__extract_quarter - , subq_15.listing__created_at__extract_month - , subq_15.listing__created_at__extract_day - , subq_15.listing__created_at__extract_dow - , subq_15.listing__created_at__extract_doy - , subq_15.ds__day AS metric_time__day - , subq_15.ds__week AS metric_time__week - , subq_15.ds__month AS metric_time__month - , subq_15.ds__quarter AS metric_time__quarter - , subq_15.ds__year AS metric_time__year - , subq_15.ds__extract_year AS metric_time__extract_year - , subq_15.ds__extract_quarter AS metric_time__extract_quarter - , subq_15.ds__extract_month AS metric_time__extract_month - , subq_15.ds__extract_day AS metric_time__extract_day - , subq_15.ds__extract_dow AS metric_time__extract_dow - , subq_15.ds__extract_doy AS metric_time__extract_doy - , subq_15.listing - , subq_15.user - , subq_15.listing__user - , subq_15.country_latest - , subq_15.is_lux_latest - , subq_15.capacity_latest - , subq_15.listing__country_latest - , subq_15.listing__is_lux_latest - , subq_15.listing__capacity_latest - , subq_15.listings - , subq_15.largest_listing - , subq_15.smallest_listing + subq_35.ds__day + , subq_35.ds__week + , subq_35.ds__month + , subq_35.ds__quarter + , subq_35.ds__year + , subq_35.ds__extract_year + , subq_35.ds__extract_quarter + , subq_35.ds__extract_month + , subq_35.ds__extract_day + , subq_35.ds__extract_dow + , subq_35.ds__extract_doy + , subq_35.created_at__day + , subq_35.created_at__week + , subq_35.created_at__month + , subq_35.created_at__quarter + , subq_35.created_at__year + , subq_35.created_at__extract_year + , subq_35.created_at__extract_quarter + , subq_35.created_at__extract_month + , subq_35.created_at__extract_day + , subq_35.created_at__extract_dow + , subq_35.created_at__extract_doy + , subq_35.listing__ds__day + , subq_35.listing__ds__week + , subq_35.listing__ds__month + , subq_35.listing__ds__quarter + , subq_35.listing__ds__year + , subq_35.listing__ds__extract_year + , subq_35.listing__ds__extract_quarter + , subq_35.listing__ds__extract_month + , subq_35.listing__ds__extract_day + , subq_35.listing__ds__extract_dow + , subq_35.listing__ds__extract_doy + , subq_35.listing__created_at__day + , subq_35.listing__created_at__week + , subq_35.listing__created_at__month + , subq_35.listing__created_at__quarter + , subq_35.listing__created_at__year + , subq_35.listing__created_at__extract_year + , subq_35.listing__created_at__extract_quarter + , subq_35.listing__created_at__extract_month + , subq_35.listing__created_at__extract_day + , subq_35.listing__created_at__extract_dow + , subq_35.listing__created_at__extract_doy + , subq_35.ds__day AS metric_time__day + , subq_35.ds__week AS metric_time__week + , subq_35.ds__month AS metric_time__month + , subq_35.ds__quarter AS metric_time__quarter + , subq_35.ds__year AS metric_time__year + , subq_35.ds__extract_year AS metric_time__extract_year + , subq_35.ds__extract_quarter AS metric_time__extract_quarter + , subq_35.ds__extract_month AS metric_time__extract_month + , subq_35.ds__extract_day AS metric_time__extract_day + , subq_35.ds__extract_dow AS metric_time__extract_dow + , subq_35.ds__extract_doy AS metric_time__extract_doy + , subq_35.listing + , subq_35.user + , subq_35.listing__user + , subq_35.country_latest + , subq_35.is_lux_latest + , subq_35.capacity_latest + , subq_35.listing__country_latest + , subq_35.listing__is_lux_latest + , subq_35.listing__capacity_latest + , subq_35.listings + , subq_35.largest_listing + , subq_35.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -759,240 +965,343 @@ FROM ( , listings_latest_src_28000.user_id AS user , listings_latest_src_28000.user_id AS listing__user FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_15 - ) subq_16 - ) subq_17 + ) subq_35 + ) subq_36 + ) subq_37 ON - subq_14.listing = subq_17.listing - ) subq_18 - ) subq_19 + subq_34.listing = subq_37.listing + ) subq_38 + ) subq_39 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_20 - ) subq_21 - ) subq_22 - ) subq_23 + ) subq_40 + ) subq_41 + ) subq_42 + ) subq_43 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_29.booking_value + subq_50.booking_value FROM ( -- Aggregate Measures SELECT - SUM(subq_28.booking_value) AS booking_value + SUM(subq_49.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value',] SELECT - subq_27.booking_value + subq_48.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_26.booking__is_instant - , subq_26.booking_value + subq_47.booking__is_instant + , subq_47.booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__is_instant'] SELECT - subq_25.booking__is_instant - , subq_25.booking_value + subq_46.booking__is_instant + , subq_46.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_24.ds__day - , subq_24.ds__week - , subq_24.ds__month - , subq_24.ds__quarter - , subq_24.ds__year - , subq_24.ds__extract_year - , subq_24.ds__extract_quarter - , subq_24.ds__extract_month - , subq_24.ds__extract_day - , subq_24.ds__extract_dow - , subq_24.ds__extract_doy - , subq_24.ds_partitioned__day - , subq_24.ds_partitioned__week - , subq_24.ds_partitioned__month - , subq_24.ds_partitioned__quarter - , subq_24.ds_partitioned__year - , subq_24.ds_partitioned__extract_year - , subq_24.ds_partitioned__extract_quarter - , subq_24.ds_partitioned__extract_month - , subq_24.ds_partitioned__extract_day - , subq_24.ds_partitioned__extract_dow - , subq_24.ds_partitioned__extract_doy - , subq_24.paid_at__day - , subq_24.paid_at__week - , subq_24.paid_at__month - , subq_24.paid_at__quarter - , subq_24.paid_at__year - , subq_24.paid_at__extract_year - , subq_24.paid_at__extract_quarter - , subq_24.paid_at__extract_month - , subq_24.paid_at__extract_day - , subq_24.paid_at__extract_dow - , subq_24.paid_at__extract_doy - , subq_24.booking__ds__day - , subq_24.booking__ds__week - , subq_24.booking__ds__month - , subq_24.booking__ds__quarter - , subq_24.booking__ds__year - , subq_24.booking__ds__extract_year - , subq_24.booking__ds__extract_quarter - , subq_24.booking__ds__extract_month - , subq_24.booking__ds__extract_day - , subq_24.booking__ds__extract_dow - , subq_24.booking__ds__extract_doy - , subq_24.booking__ds_partitioned__day - , subq_24.booking__ds_partitioned__week - , subq_24.booking__ds_partitioned__month - , subq_24.booking__ds_partitioned__quarter - , subq_24.booking__ds_partitioned__year - , subq_24.booking__ds_partitioned__extract_year - , subq_24.booking__ds_partitioned__extract_quarter - , subq_24.booking__ds_partitioned__extract_month - , subq_24.booking__ds_partitioned__extract_day - , subq_24.booking__ds_partitioned__extract_dow - , subq_24.booking__ds_partitioned__extract_doy - , subq_24.booking__paid_at__day - , subq_24.booking__paid_at__week - , subq_24.booking__paid_at__month - , subq_24.booking__paid_at__quarter - , subq_24.booking__paid_at__year - , subq_24.booking__paid_at__extract_year - , subq_24.booking__paid_at__extract_quarter - , subq_24.booking__paid_at__extract_month - , subq_24.booking__paid_at__extract_day - , subq_24.booking__paid_at__extract_dow - , subq_24.booking__paid_at__extract_doy - , subq_24.ds__day AS metric_time__day - , subq_24.ds__week AS metric_time__week - , subq_24.ds__month AS metric_time__month - , subq_24.ds__quarter AS metric_time__quarter - , subq_24.ds__year AS metric_time__year - , subq_24.ds__extract_year AS metric_time__extract_year - , subq_24.ds__extract_quarter AS metric_time__extract_quarter - , subq_24.ds__extract_month AS metric_time__extract_month - , subq_24.ds__extract_day AS metric_time__extract_day - , subq_24.ds__extract_dow AS metric_time__extract_dow - , subq_24.ds__extract_doy AS metric_time__extract_doy - , subq_24.listing - , subq_24.guest - , subq_24.host - , subq_24.booking__listing - , subq_24.booking__guest - , subq_24.booking__host - , subq_24.is_instant - , subq_24.booking__is_instant - , subq_24.bookings - , subq_24.instant_bookings - , subq_24.booking_value - , subq_24.max_booking_value - , subq_24.min_booking_value - , subq_24.bookers - , subq_24.average_booking_value - , subq_24.referred_bookings - , subq_24.median_booking_value - , subq_24.booking_value_p99 - , subq_24.discrete_booking_value_p99 - , subq_24.approximate_continuous_booking_value_p99 - , subq_24.approximate_discrete_booking_value_p99 + subq_45.ds__day + , subq_45.ds__week + , subq_45.ds__month + , subq_45.ds__quarter + , subq_45.ds__year + , subq_45.ds__extract_year + , subq_45.ds__extract_quarter + , subq_45.ds__extract_month + , subq_45.ds__extract_day + , subq_45.ds__extract_dow + , subq_45.ds__extract_doy + , subq_45.ds_partitioned__day + , subq_45.ds_partitioned__week + , subq_45.ds_partitioned__month + , subq_45.ds_partitioned__quarter + , subq_45.ds_partitioned__year + , subq_45.ds_partitioned__extract_year + , subq_45.ds_partitioned__extract_quarter + , subq_45.ds_partitioned__extract_month + , subq_45.ds_partitioned__extract_day + , subq_45.ds_partitioned__extract_dow + , subq_45.ds_partitioned__extract_doy + , subq_45.paid_at__day + , subq_45.paid_at__week + , subq_45.paid_at__month + , subq_45.paid_at__quarter + , subq_45.paid_at__year + , subq_45.paid_at__extract_year + , subq_45.paid_at__extract_quarter + , subq_45.paid_at__extract_month + , subq_45.paid_at__extract_day + , subq_45.paid_at__extract_dow + , subq_45.paid_at__extract_doy + , subq_45.booking__ds__day + , subq_45.booking__ds__week + , subq_45.booking__ds__month + , subq_45.booking__ds__quarter + , subq_45.booking__ds__year + , subq_45.booking__ds__extract_year + , subq_45.booking__ds__extract_quarter + , subq_45.booking__ds__extract_month + , subq_45.booking__ds__extract_day + , subq_45.booking__ds__extract_dow + , subq_45.booking__ds__extract_doy + , subq_45.booking__ds_partitioned__day + , subq_45.booking__ds_partitioned__week + , subq_45.booking__ds_partitioned__month + , subq_45.booking__ds_partitioned__quarter + , subq_45.booking__ds_partitioned__year + , subq_45.booking__ds_partitioned__extract_year + , subq_45.booking__ds_partitioned__extract_quarter + , subq_45.booking__ds_partitioned__extract_month + , subq_45.booking__ds_partitioned__extract_day + , subq_45.booking__ds_partitioned__extract_dow + , subq_45.booking__ds_partitioned__extract_doy + , subq_45.booking__paid_at__day + , subq_45.booking__paid_at__week + , subq_45.booking__paid_at__month + , subq_45.booking__paid_at__quarter + , subq_45.booking__paid_at__year + , subq_45.booking__paid_at__extract_year + , subq_45.booking__paid_at__extract_quarter + , subq_45.booking__paid_at__extract_month + , subq_45.booking__paid_at__extract_day + , subq_45.booking__paid_at__extract_dow + , subq_45.booking__paid_at__extract_doy + , subq_45.metric_time__day + , subq_45.metric_time__week + , subq_45.metric_time__month + , subq_45.metric_time__quarter + , subq_45.metric_time__year + , subq_45.metric_time__extract_year + , subq_45.metric_time__extract_quarter + , subq_45.metric_time__extract_month + , subq_45.metric_time__extract_day + , subq_45.metric_time__extract_dow + , subq_45.metric_time__extract_doy + , subq_45.listing + , subq_45.guest + , subq_45.host + , subq_45.booking__listing + , subq_45.booking__guest + , subq_45.booking__host + , subq_45.is_instant + , subq_45.booking__is_instant + , subq_45.bookings + , subq_45.instant_bookings + , subq_45.booking_value + , subq_45.max_booking_value + , subq_45.min_booking_value + , subq_45.bookers + , subq_45.average_booking_value + , subq_45.referred_bookings + , subq_45.median_booking_value + , subq_45.booking_value_p99 + , subq_45.discrete_booking_value_p99 + , subq_45.approximate_continuous_booking_value_p99 + , subq_45.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC(bookings_source_src_28000.ds, day) AS ds__day - , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS ds__week - , DATE_TRUNC(bookings_source_src_28000.ds, month) AS ds__month - , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS ds__quarter - , DATE_TRUNC(bookings_source_src_28000.ds, year) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS ds__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS ds_partitioned__day - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS ds_partitioned__week - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS ds_partitioned__month - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS ds_partitioned__quarter - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS ds_partitioned__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS paid_at__day - , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS paid_at__week - , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS paid_at__month - , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS paid_at__quarter - , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS paid_at__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC(bookings_source_src_28000.ds, day) AS booking__ds__day - , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS booking__ds__week - , DATE_TRUNC(bookings_source_src_28000.ds, month) AS booking__ds__month - , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS booking__ds__quarter - , DATE_TRUNC(bookings_source_src_28000.ds, year) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS booking__ds__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS booking__ds_partitioned__day - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS booking__ds_partitioned__week - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS booking__ds_partitioned__month - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS booking__ds_partitioned__quarter - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS booking__ds_partitioned__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS booking__paid_at__day - , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS booking__paid_at__week - , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS booking__paid_at__month - , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS booking__paid_at__quarter - , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS booking__paid_at__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_24 - ) subq_25 - ) subq_26 + subq_44.ds__day + , subq_44.ds__week + , subq_44.ds__month + , subq_44.ds__quarter + , subq_44.ds__year + , subq_44.ds__extract_year + , subq_44.ds__extract_quarter + , subq_44.ds__extract_month + , subq_44.ds__extract_day + , subq_44.ds__extract_dow + , subq_44.ds__extract_doy + , subq_44.ds_partitioned__day + , subq_44.ds_partitioned__week + , subq_44.ds_partitioned__month + , subq_44.ds_partitioned__quarter + , subq_44.ds_partitioned__year + , subq_44.ds_partitioned__extract_year + , subq_44.ds_partitioned__extract_quarter + , subq_44.ds_partitioned__extract_month + , subq_44.ds_partitioned__extract_day + , subq_44.ds_partitioned__extract_dow + , subq_44.ds_partitioned__extract_doy + , subq_44.paid_at__day + , subq_44.paid_at__week + , subq_44.paid_at__month + , subq_44.paid_at__quarter + , subq_44.paid_at__year + , subq_44.paid_at__extract_year + , subq_44.paid_at__extract_quarter + , subq_44.paid_at__extract_month + , subq_44.paid_at__extract_day + , subq_44.paid_at__extract_dow + , subq_44.paid_at__extract_doy + , subq_44.booking__ds__day + , subq_44.booking__ds__week + , subq_44.booking__ds__month + , subq_44.booking__ds__quarter + , subq_44.booking__ds__year + , subq_44.booking__ds__extract_year + , subq_44.booking__ds__extract_quarter + , subq_44.booking__ds__extract_month + , subq_44.booking__ds__extract_day + , subq_44.booking__ds__extract_dow + , subq_44.booking__ds__extract_doy + , subq_44.booking__ds_partitioned__day + , subq_44.booking__ds_partitioned__week + , subq_44.booking__ds_partitioned__month + , subq_44.booking__ds_partitioned__quarter + , subq_44.booking__ds_partitioned__year + , subq_44.booking__ds_partitioned__extract_year + , subq_44.booking__ds_partitioned__extract_quarter + , subq_44.booking__ds_partitioned__extract_month + , subq_44.booking__ds_partitioned__extract_day + , subq_44.booking__ds_partitioned__extract_dow + , subq_44.booking__ds_partitioned__extract_doy + , subq_44.booking__paid_at__day + , subq_44.booking__paid_at__week + , subq_44.booking__paid_at__month + , subq_44.booking__paid_at__quarter + , subq_44.booking__paid_at__year + , subq_44.booking__paid_at__extract_year + , subq_44.booking__paid_at__extract_quarter + , subq_44.booking__paid_at__extract_month + , subq_44.booking__paid_at__extract_day + , subq_44.booking__paid_at__extract_dow + , subq_44.booking__paid_at__extract_doy + , subq_44.ds__day AS metric_time__day + , subq_44.ds__week AS metric_time__week + , subq_44.ds__month AS metric_time__month + , subq_44.ds__quarter AS metric_time__quarter + , subq_44.ds__year AS metric_time__year + , subq_44.ds__extract_year AS metric_time__extract_year + , subq_44.ds__extract_quarter AS metric_time__extract_quarter + , subq_44.ds__extract_month AS metric_time__extract_month + , subq_44.ds__extract_day AS metric_time__extract_day + , subq_44.ds__extract_dow AS metric_time__extract_dow + , subq_44.ds__extract_doy AS metric_time__extract_doy + , subq_44.listing + , subq_44.guest + , subq_44.host + , subq_44.booking__listing + , subq_44.booking__guest + , subq_44.booking__host + , subq_44.is_instant + , subq_44.booking__is_instant + , subq_44.bookings + , subq_44.instant_bookings + , subq_44.booking_value + , subq_44.max_booking_value + , subq_44.min_booking_value + , subq_44.bookers + , subq_44.average_booking_value + , subq_44.referred_bookings + , subq_44.median_booking_value + , subq_44.booking_value_p99 + , subq_44.discrete_booking_value_p99 + , subq_44.approximate_continuous_booking_value_p99 + , subq_44.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC(bookings_source_src_28000.ds, day) AS ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC(bookings_source_src_28000.ds, day) AS booking__ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS booking__ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS booking__ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS booking__ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS booking__ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS booking__ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS booking__ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS booking__ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS booking__ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS booking__ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS booking__paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS booking__paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS booking__paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS booking__paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS booking__paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_44 + ) subq_45 + WHERE booking__is_instant + ) subq_46 + ) subq_47 WHERE booking__is_instant - ) subq_27 - ) subq_28 - ) subq_29 - ) subq_30 - ) subq_31 -) subq_32 + ) subq_48 + ) subq_49 + ) subq_50 + ) subq_51 + ) subq_52 +) subq_53 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_filters__plan0_optimized.sql index a73bfea928..a0fdc735bd 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_filters__plan0_optimized.sql @@ -8,9 +8,9 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_44.average_booking_value) AS average_booking_value - , MAX(subq_56.bookings) AS bookings - , MAX(subq_63.booking_value) AS booking_value + MAX(subq_66.average_booking_value) AS average_booking_value + , MAX(subq_79.bookings) AS bookings + , MAX(subq_87.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['average_booking_value',] @@ -22,17 +22,34 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - bookings_source_src_28000.is_instant AS booking__is_instant + subq_57.booking__is_instant AS booking__is_instant , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , bookings_source_src_28000.booking_value AS average_booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 + , subq_57.average_booking_value AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] + SELECT + listing + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_55 + WHERE booking__is_instant + ) subq_57 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - bookings_source_src_28000.listing_id = listings_latest_src_28000.listing_id - ) subq_40 + subq_57.listing = listings_latest_src_28000.listing_id + ) subq_62 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_44 + ) subq_66 CROSS JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings',] @@ -44,26 +61,34 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_47.booking__is_instant AS booking__is_instant + subq_70.booking__is_instant AS booking__is_instant , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , subq_47.bookings AS bookings + , subq_70.bookings AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - listing_id AS listing - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_47 + listing + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_68 + WHERE booking__is_instant + ) subq_70 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_47.listing = listings_latest_src_28000.listing_id - ) subq_52 + subq_70.listing = listings_latest_src_28000.listing_id + ) subq_75 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_56 + ) subq_79 CROSS JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value',] @@ -72,15 +97,22 @@ FROM ( SELECT SUM(booking_value) AS booking_value FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'booking__is_instant'] SELECT - is_instant AS booking__is_instant + booking__is_instant , booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_59 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_81 + WHERE booking__is_instant + ) subq_83 WHERE booking__is_instant - ) subq_63 - ) subq_64 -) subq_65 + ) subq_87 + ) subq_88 +) subq_89 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_filters__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_filters__plan0.sql index 94ca50b1fd..facafc599f 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_filters__plan0.sql @@ -8,317 +8,420 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_11.average_booking_value) AS average_booking_value - , MAX(subq_23.bookings) AS bookings - , MAX(subq_30.booking_value) AS booking_value + MAX(subq_30.average_booking_value) AS average_booking_value + , MAX(subq_43.bookings) AS bookings + , MAX(subq_51.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_10.average_booking_value + subq_29.average_booking_value FROM ( -- Aggregate Measures SELECT - AVG(subq_9.average_booking_value) AS average_booking_value + AVG(subq_28.average_booking_value) AS average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value',] SELECT - subq_8.average_booking_value + subq_27.average_booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_7.booking__is_instant - , subq_7.listing__is_lux_latest - , subq_7.average_booking_value + subq_26.booking__is_instant + , subq_26.listing__is_lux_latest + , subq_26.average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_6.booking__is_instant - , subq_6.listing__is_lux_latest - , subq_6.average_booking_value + subq_25.booking__is_instant + , subq_25.listing__is_lux_latest + , subq_25.average_booking_value FROM ( -- Join Standard Outputs SELECT - subq_2.listing AS listing - , subq_2.booking__is_instant AS booking__is_instant - , subq_5.is_lux_latest AS listing__is_lux_latest - , subq_2.average_booking_value AS average_booking_value + subq_21.listing AS listing + , subq_21.booking__is_instant AS booking__is_instant + , subq_24.is_lux_latest AS listing__is_lux_latest + , subq_21.average_booking_value AS average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] SELECT - subq_1.listing - , subq_1.booking__is_instant - , subq_1.average_booking_value + subq_20.listing + , subq_20.booking__is_instant + , subq_20.average_booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE 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.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.booking__paid_at__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.listing - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_19.ds__day + , subq_19.ds__week + , subq_19.ds__month + , subq_19.ds__quarter + , subq_19.ds__year + , subq_19.ds__extract_year + , subq_19.ds__extract_quarter + , subq_19.ds__extract_month + , subq_19.ds__extract_day + , subq_19.ds__extract_dow + , subq_19.ds__extract_doy + , subq_19.ds_partitioned__day + , subq_19.ds_partitioned__week + , subq_19.ds_partitioned__month + , subq_19.ds_partitioned__quarter + , subq_19.ds_partitioned__year + , subq_19.ds_partitioned__extract_year + , subq_19.ds_partitioned__extract_quarter + , subq_19.ds_partitioned__extract_month + , subq_19.ds_partitioned__extract_day + , subq_19.ds_partitioned__extract_dow + , subq_19.ds_partitioned__extract_doy + , subq_19.paid_at__day + , subq_19.paid_at__week + , subq_19.paid_at__month + , subq_19.paid_at__quarter + , subq_19.paid_at__year + , subq_19.paid_at__extract_year + , subq_19.paid_at__extract_quarter + , subq_19.paid_at__extract_month + , subq_19.paid_at__extract_day + , subq_19.paid_at__extract_dow + , subq_19.paid_at__extract_doy + , subq_19.booking__ds__day + , subq_19.booking__ds__week + , subq_19.booking__ds__month + , subq_19.booking__ds__quarter + , subq_19.booking__ds__year + , subq_19.booking__ds__extract_year + , subq_19.booking__ds__extract_quarter + , subq_19.booking__ds__extract_month + , subq_19.booking__ds__extract_day + , subq_19.booking__ds__extract_dow + , subq_19.booking__ds__extract_doy + , subq_19.booking__ds_partitioned__day + , subq_19.booking__ds_partitioned__week + , subq_19.booking__ds_partitioned__month + , subq_19.booking__ds_partitioned__quarter + , subq_19.booking__ds_partitioned__year + , subq_19.booking__ds_partitioned__extract_year + , subq_19.booking__ds_partitioned__extract_quarter + , subq_19.booking__ds_partitioned__extract_month + , subq_19.booking__ds_partitioned__extract_day + , subq_19.booking__ds_partitioned__extract_dow + , subq_19.booking__ds_partitioned__extract_doy + , subq_19.booking__paid_at__day + , subq_19.booking__paid_at__week + , subq_19.booking__paid_at__month + , subq_19.booking__paid_at__quarter + , subq_19.booking__paid_at__year + , subq_19.booking__paid_at__extract_year + , subq_19.booking__paid_at__extract_quarter + , subq_19.booking__paid_at__extract_month + , subq_19.booking__paid_at__extract_day + , subq_19.booking__paid_at__extract_dow + , subq_19.booking__paid_at__extract_doy + , subq_19.metric_time__day + , subq_19.metric_time__week + , subq_19.metric_time__month + , subq_19.metric_time__quarter + , subq_19.metric_time__year + , subq_19.metric_time__extract_year + , subq_19.metric_time__extract_quarter + , subq_19.metric_time__extract_month + , subq_19.metric_time__extract_day + , subq_19.metric_time__extract_dow + , subq_19.metric_time__extract_doy + , subq_19.listing + , subq_19.guest + , subq_19.host + , subq_19.booking__listing + , subq_19.booking__guest + , subq_19.booking__host + , subq_19.is_instant + , subq_19.booking__is_instant + , subq_19.bookings + , subq_19.instant_bookings + , subq_19.booking_value + , subq_19.max_booking_value + , subq_19.min_booking_value + , subq_19.bookers + , subq_19.average_booking_value + , subq_19.referred_bookings + , subq_19.median_booking_value + , subq_19.booking_value_p99 + , subq_19.discrete_booking_value_p99 + , subq_19.approximate_continuous_booking_value_p99 + , subq_19.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + subq_18.ds__day + , subq_18.ds__week + , subq_18.ds__month + , subq_18.ds__quarter + , subq_18.ds__year + , subq_18.ds__extract_year + , subq_18.ds__extract_quarter + , subq_18.ds__extract_month + , subq_18.ds__extract_day + , subq_18.ds__extract_dow + , subq_18.ds__extract_doy + , subq_18.ds_partitioned__day + , subq_18.ds_partitioned__week + , subq_18.ds_partitioned__month + , subq_18.ds_partitioned__quarter + , subq_18.ds_partitioned__year + , subq_18.ds_partitioned__extract_year + , subq_18.ds_partitioned__extract_quarter + , subq_18.ds_partitioned__extract_month + , subq_18.ds_partitioned__extract_day + , subq_18.ds_partitioned__extract_dow + , subq_18.ds_partitioned__extract_doy + , subq_18.paid_at__day + , subq_18.paid_at__week + , subq_18.paid_at__month + , subq_18.paid_at__quarter + , subq_18.paid_at__year + , subq_18.paid_at__extract_year + , subq_18.paid_at__extract_quarter + , subq_18.paid_at__extract_month + , subq_18.paid_at__extract_day + , subq_18.paid_at__extract_dow + , subq_18.paid_at__extract_doy + , subq_18.booking__ds__day + , subq_18.booking__ds__week + , subq_18.booking__ds__month + , subq_18.booking__ds__quarter + , subq_18.booking__ds__year + , subq_18.booking__ds__extract_year + , subq_18.booking__ds__extract_quarter + , subq_18.booking__ds__extract_month + , subq_18.booking__ds__extract_day + , subq_18.booking__ds__extract_dow + , subq_18.booking__ds__extract_doy + , subq_18.booking__ds_partitioned__day + , subq_18.booking__ds_partitioned__week + , subq_18.booking__ds_partitioned__month + , subq_18.booking__ds_partitioned__quarter + , subq_18.booking__ds_partitioned__year + , subq_18.booking__ds_partitioned__extract_year + , subq_18.booking__ds_partitioned__extract_quarter + , subq_18.booking__ds_partitioned__extract_month + , subq_18.booking__ds_partitioned__extract_day + , subq_18.booking__ds_partitioned__extract_dow + , subq_18.booking__ds_partitioned__extract_doy + , subq_18.booking__paid_at__day + , subq_18.booking__paid_at__week + , subq_18.booking__paid_at__month + , subq_18.booking__paid_at__quarter + , subq_18.booking__paid_at__year + , subq_18.booking__paid_at__extract_year + , subq_18.booking__paid_at__extract_quarter + , subq_18.booking__paid_at__extract_month + , subq_18.booking__paid_at__extract_day + , subq_18.booking__paid_at__extract_dow + , subq_18.booking__paid_at__extract_doy + , subq_18.ds__day AS metric_time__day + , subq_18.ds__week AS metric_time__week + , subq_18.ds__month AS metric_time__month + , subq_18.ds__quarter AS metric_time__quarter + , subq_18.ds__year AS metric_time__year + , subq_18.ds__extract_year AS metric_time__extract_year + , subq_18.ds__extract_quarter AS metric_time__extract_quarter + , subq_18.ds__extract_month AS metric_time__extract_month + , subq_18.ds__extract_day AS metric_time__extract_day + , subq_18.ds__extract_dow AS metric_time__extract_dow + , subq_18.ds__extract_doy AS metric_time__extract_doy + , subq_18.listing + , subq_18.guest + , subq_18.host + , subq_18.booking__listing + , subq_18.booking__guest + , subq_18.booking__host + , subq_18.is_instant + , subq_18.booking__is_instant + , subq_18.bookings + , subq_18.instant_bookings + , subq_18.booking_value + , subq_18.max_booking_value + , subq_18.min_booking_value + , subq_18.bookers + , subq_18.average_booking_value + , subq_18.referred_bookings + , subq_18.median_booking_value + , subq_18.booking_value_p99 + , subq_18.discrete_booking_value_p99 + , subq_18.approximate_continuous_booking_value_p99 + , subq_18.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_18 + ) subq_19 + WHERE booking__is_instant + ) subq_20 + ) subq_21 LEFT OUTER JOIN ( -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_4.listing - , subq_4.is_lux_latest + subq_23.listing + , subq_23.is_lux_latest FROM ( -- Metric Time Dimension 'ds' SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing + subq_22.ds__day + , subq_22.ds__week + , subq_22.ds__month + , subq_22.ds__quarter + , subq_22.ds__year + , subq_22.ds__extract_year + , subq_22.ds__extract_quarter + , subq_22.ds__extract_month + , subq_22.ds__extract_day + , subq_22.ds__extract_dow + , subq_22.ds__extract_doy + , subq_22.created_at__day + , subq_22.created_at__week + , subq_22.created_at__month + , subq_22.created_at__quarter + , subq_22.created_at__year + , subq_22.created_at__extract_year + , subq_22.created_at__extract_quarter + , subq_22.created_at__extract_month + , subq_22.created_at__extract_day + , subq_22.created_at__extract_dow + , subq_22.created_at__extract_doy + , subq_22.listing__ds__day + , subq_22.listing__ds__week + , subq_22.listing__ds__month + , subq_22.listing__ds__quarter + , subq_22.listing__ds__year + , subq_22.listing__ds__extract_year + , subq_22.listing__ds__extract_quarter + , subq_22.listing__ds__extract_month + , subq_22.listing__ds__extract_day + , subq_22.listing__ds__extract_dow + , subq_22.listing__ds__extract_doy + , subq_22.listing__created_at__day + , subq_22.listing__created_at__week + , subq_22.listing__created_at__month + , subq_22.listing__created_at__quarter + , subq_22.listing__created_at__year + , subq_22.listing__created_at__extract_year + , subq_22.listing__created_at__extract_quarter + , subq_22.listing__created_at__extract_month + , subq_22.listing__created_at__extract_day + , subq_22.listing__created_at__extract_dow + , subq_22.listing__created_at__extract_doy + , subq_22.ds__day AS metric_time__day + , subq_22.ds__week AS metric_time__week + , subq_22.ds__month AS metric_time__month + , subq_22.ds__quarter AS metric_time__quarter + , subq_22.ds__year AS metric_time__year + , subq_22.ds__extract_year AS metric_time__extract_year + , subq_22.ds__extract_quarter AS metric_time__extract_quarter + , subq_22.ds__extract_month AS metric_time__extract_month + , subq_22.ds__extract_day AS metric_time__extract_day + , subq_22.ds__extract_dow AS metric_time__extract_dow + , subq_22.ds__extract_doy AS metric_time__extract_doy + , subq_22.listing + , subq_22.user + , subq_22.listing__user + , subq_22.country_latest + , subq_22.is_lux_latest + , subq_22.capacity_latest + , subq_22.listing__country_latest + , subq_22.listing__is_lux_latest + , subq_22.listing__capacity_latest + , subq_22.listings + , subq_22.largest_listing + , subq_22.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -379,326 +482,429 @@ FROM ( , listings_latest_src_28000.user_id AS user , listings_latest_src_28000.user_id AS listing__user FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_3 - ) subq_4 - ) subq_5 + ) subq_22 + ) subq_23 + ) subq_24 ON - subq_2.listing = subq_5.listing - ) subq_6 - ) subq_7 + subq_21.listing = subq_24.listing + ) subq_25 + ) subq_26 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_8 - ) subq_9 - ) subq_10 - ) subq_11 + ) subq_27 + ) subq_28 + ) subq_29 + ) subq_30 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_22.bookings + subq_42.bookings FROM ( -- Aggregate Measures SELECT - SUM(subq_21.bookings) AS bookings + SUM(subq_41.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings',] SELECT - subq_20.bookings + subq_40.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_19.booking__is_instant - , subq_19.listing__is_lux_latest - , subq_19.bookings + subq_39.booking__is_instant + , subq_39.listing__is_lux_latest + , subq_39.bookings FROM ( -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_18.booking__is_instant - , subq_18.listing__is_lux_latest - , subq_18.bookings + subq_38.booking__is_instant + , subq_38.listing__is_lux_latest + , subq_38.bookings FROM ( -- Join Standard Outputs SELECT - subq_14.listing AS listing - , subq_14.booking__is_instant AS booking__is_instant - , subq_17.is_lux_latest AS listing__is_lux_latest - , subq_14.bookings AS bookings + subq_34.listing AS listing + , subq_34.booking__is_instant AS booking__is_instant + , subq_37.is_lux_latest AS listing__is_lux_latest + , subq_34.bookings AS bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - subq_13.listing - , subq_13.booking__is_instant - , subq_13.bookings + subq_33.listing + , subq_33.booking__is_instant + , subq_33.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_12.ds__day - , subq_12.ds__week - , subq_12.ds__month - , subq_12.ds__quarter - , subq_12.ds__year - , subq_12.ds__extract_year - , subq_12.ds__extract_quarter - , subq_12.ds__extract_month - , subq_12.ds__extract_day - , subq_12.ds__extract_dow - , subq_12.ds__extract_doy - , subq_12.ds_partitioned__day - , subq_12.ds_partitioned__week - , subq_12.ds_partitioned__month - , subq_12.ds_partitioned__quarter - , subq_12.ds_partitioned__year - , subq_12.ds_partitioned__extract_year - , subq_12.ds_partitioned__extract_quarter - , subq_12.ds_partitioned__extract_month - , subq_12.ds_partitioned__extract_day - , subq_12.ds_partitioned__extract_dow - , subq_12.ds_partitioned__extract_doy - , subq_12.paid_at__day - , subq_12.paid_at__week - , subq_12.paid_at__month - , subq_12.paid_at__quarter - , subq_12.paid_at__year - , subq_12.paid_at__extract_year - , subq_12.paid_at__extract_quarter - , subq_12.paid_at__extract_month - , subq_12.paid_at__extract_day - , subq_12.paid_at__extract_dow - , subq_12.paid_at__extract_doy - , subq_12.booking__ds__day - , subq_12.booking__ds__week - , subq_12.booking__ds__month - , subq_12.booking__ds__quarter - , subq_12.booking__ds__year - , subq_12.booking__ds__extract_year - , subq_12.booking__ds__extract_quarter - , subq_12.booking__ds__extract_month - , subq_12.booking__ds__extract_day - , subq_12.booking__ds__extract_dow - , subq_12.booking__ds__extract_doy - , subq_12.booking__ds_partitioned__day - , subq_12.booking__ds_partitioned__week - , subq_12.booking__ds_partitioned__month - , subq_12.booking__ds_partitioned__quarter - , subq_12.booking__ds_partitioned__year - , subq_12.booking__ds_partitioned__extract_year - , subq_12.booking__ds_partitioned__extract_quarter - , subq_12.booking__ds_partitioned__extract_month - , subq_12.booking__ds_partitioned__extract_day - , subq_12.booking__ds_partitioned__extract_dow - , subq_12.booking__ds_partitioned__extract_doy - , subq_12.booking__paid_at__day - , subq_12.booking__paid_at__week - , subq_12.booking__paid_at__month - , subq_12.booking__paid_at__quarter - , subq_12.booking__paid_at__year - , subq_12.booking__paid_at__extract_year - , subq_12.booking__paid_at__extract_quarter - , subq_12.booking__paid_at__extract_month - , subq_12.booking__paid_at__extract_day - , subq_12.booking__paid_at__extract_dow - , subq_12.booking__paid_at__extract_doy - , subq_12.ds__day AS metric_time__day - , subq_12.ds__week AS metric_time__week - , subq_12.ds__month AS metric_time__month - , subq_12.ds__quarter AS metric_time__quarter - , subq_12.ds__year AS metric_time__year - , subq_12.ds__extract_year AS metric_time__extract_year - , subq_12.ds__extract_quarter AS metric_time__extract_quarter - , subq_12.ds__extract_month AS metric_time__extract_month - , subq_12.ds__extract_day AS metric_time__extract_day - , subq_12.ds__extract_dow AS metric_time__extract_dow - , subq_12.ds__extract_doy AS metric_time__extract_doy - , subq_12.listing - , subq_12.guest - , subq_12.host - , subq_12.booking__listing - , subq_12.booking__guest - , subq_12.booking__host - , subq_12.is_instant - , subq_12.booking__is_instant - , subq_12.bookings - , subq_12.instant_bookings - , subq_12.booking_value - , subq_12.max_booking_value - , subq_12.min_booking_value - , subq_12.bookers - , subq_12.average_booking_value - , subq_12.referred_bookings - , subq_12.median_booking_value - , subq_12.booking_value_p99 - , subq_12.discrete_booking_value_p99 - , subq_12.approximate_continuous_booking_value_p99 - , subq_12.approximate_discrete_booking_value_p99 + subq_32.ds__day + , subq_32.ds__week + , subq_32.ds__month + , subq_32.ds__quarter + , subq_32.ds__year + , subq_32.ds__extract_year + , subq_32.ds__extract_quarter + , subq_32.ds__extract_month + , subq_32.ds__extract_day + , subq_32.ds__extract_dow + , subq_32.ds__extract_doy + , subq_32.ds_partitioned__day + , subq_32.ds_partitioned__week + , subq_32.ds_partitioned__month + , subq_32.ds_partitioned__quarter + , subq_32.ds_partitioned__year + , subq_32.ds_partitioned__extract_year + , subq_32.ds_partitioned__extract_quarter + , subq_32.ds_partitioned__extract_month + , subq_32.ds_partitioned__extract_day + , subq_32.ds_partitioned__extract_dow + , subq_32.ds_partitioned__extract_doy + , subq_32.paid_at__day + , subq_32.paid_at__week + , subq_32.paid_at__month + , subq_32.paid_at__quarter + , subq_32.paid_at__year + , subq_32.paid_at__extract_year + , subq_32.paid_at__extract_quarter + , subq_32.paid_at__extract_month + , subq_32.paid_at__extract_day + , subq_32.paid_at__extract_dow + , subq_32.paid_at__extract_doy + , subq_32.booking__ds__day + , subq_32.booking__ds__week + , subq_32.booking__ds__month + , subq_32.booking__ds__quarter + , subq_32.booking__ds__year + , subq_32.booking__ds__extract_year + , subq_32.booking__ds__extract_quarter + , subq_32.booking__ds__extract_month + , subq_32.booking__ds__extract_day + , subq_32.booking__ds__extract_dow + , subq_32.booking__ds__extract_doy + , subq_32.booking__ds_partitioned__day + , subq_32.booking__ds_partitioned__week + , subq_32.booking__ds_partitioned__month + , subq_32.booking__ds_partitioned__quarter + , subq_32.booking__ds_partitioned__year + , subq_32.booking__ds_partitioned__extract_year + , subq_32.booking__ds_partitioned__extract_quarter + , subq_32.booking__ds_partitioned__extract_month + , subq_32.booking__ds_partitioned__extract_day + , subq_32.booking__ds_partitioned__extract_dow + , subq_32.booking__ds_partitioned__extract_doy + , subq_32.booking__paid_at__day + , subq_32.booking__paid_at__week + , subq_32.booking__paid_at__month + , subq_32.booking__paid_at__quarter + , subq_32.booking__paid_at__year + , subq_32.booking__paid_at__extract_year + , subq_32.booking__paid_at__extract_quarter + , subq_32.booking__paid_at__extract_month + , subq_32.booking__paid_at__extract_day + , subq_32.booking__paid_at__extract_dow + , subq_32.booking__paid_at__extract_doy + , subq_32.metric_time__day + , subq_32.metric_time__week + , subq_32.metric_time__month + , subq_32.metric_time__quarter + , subq_32.metric_time__year + , subq_32.metric_time__extract_year + , subq_32.metric_time__extract_quarter + , subq_32.metric_time__extract_month + , subq_32.metric_time__extract_day + , subq_32.metric_time__extract_dow + , subq_32.metric_time__extract_doy + , subq_32.listing + , subq_32.guest + , subq_32.host + , subq_32.booking__listing + , subq_32.booking__guest + , subq_32.booking__host + , subq_32.is_instant + , subq_32.booking__is_instant + , subq_32.bookings + , subq_32.instant_bookings + , subq_32.booking_value + , subq_32.max_booking_value + , subq_32.min_booking_value + , subq_32.bookers + , subq_32.average_booking_value + , subq_32.referred_bookings + , subq_32.median_booking_value + , subq_32.booking_value_p99 + , subq_32.discrete_booking_value_p99 + , subq_32.approximate_continuous_booking_value_p99 + , subq_32.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_12 - ) subq_13 - ) subq_14 + subq_31.ds__day + , subq_31.ds__week + , subq_31.ds__month + , subq_31.ds__quarter + , subq_31.ds__year + , subq_31.ds__extract_year + , subq_31.ds__extract_quarter + , subq_31.ds__extract_month + , subq_31.ds__extract_day + , subq_31.ds__extract_dow + , subq_31.ds__extract_doy + , subq_31.ds_partitioned__day + , subq_31.ds_partitioned__week + , subq_31.ds_partitioned__month + , subq_31.ds_partitioned__quarter + , subq_31.ds_partitioned__year + , subq_31.ds_partitioned__extract_year + , subq_31.ds_partitioned__extract_quarter + , subq_31.ds_partitioned__extract_month + , subq_31.ds_partitioned__extract_day + , subq_31.ds_partitioned__extract_dow + , subq_31.ds_partitioned__extract_doy + , subq_31.paid_at__day + , subq_31.paid_at__week + , subq_31.paid_at__month + , subq_31.paid_at__quarter + , subq_31.paid_at__year + , subq_31.paid_at__extract_year + , subq_31.paid_at__extract_quarter + , subq_31.paid_at__extract_month + , subq_31.paid_at__extract_day + , subq_31.paid_at__extract_dow + , subq_31.paid_at__extract_doy + , subq_31.booking__ds__day + , subq_31.booking__ds__week + , subq_31.booking__ds__month + , subq_31.booking__ds__quarter + , subq_31.booking__ds__year + , subq_31.booking__ds__extract_year + , subq_31.booking__ds__extract_quarter + , subq_31.booking__ds__extract_month + , subq_31.booking__ds__extract_day + , subq_31.booking__ds__extract_dow + , subq_31.booking__ds__extract_doy + , subq_31.booking__ds_partitioned__day + , subq_31.booking__ds_partitioned__week + , subq_31.booking__ds_partitioned__month + , subq_31.booking__ds_partitioned__quarter + , subq_31.booking__ds_partitioned__year + , subq_31.booking__ds_partitioned__extract_year + , subq_31.booking__ds_partitioned__extract_quarter + , subq_31.booking__ds_partitioned__extract_month + , subq_31.booking__ds_partitioned__extract_day + , subq_31.booking__ds_partitioned__extract_dow + , subq_31.booking__ds_partitioned__extract_doy + , subq_31.booking__paid_at__day + , subq_31.booking__paid_at__week + , subq_31.booking__paid_at__month + , subq_31.booking__paid_at__quarter + , subq_31.booking__paid_at__year + , subq_31.booking__paid_at__extract_year + , subq_31.booking__paid_at__extract_quarter + , subq_31.booking__paid_at__extract_month + , subq_31.booking__paid_at__extract_day + , subq_31.booking__paid_at__extract_dow + , subq_31.booking__paid_at__extract_doy + , subq_31.ds__day AS metric_time__day + , subq_31.ds__week AS metric_time__week + , subq_31.ds__month AS metric_time__month + , subq_31.ds__quarter AS metric_time__quarter + , subq_31.ds__year AS metric_time__year + , subq_31.ds__extract_year AS metric_time__extract_year + , subq_31.ds__extract_quarter AS metric_time__extract_quarter + , subq_31.ds__extract_month AS metric_time__extract_month + , subq_31.ds__extract_day AS metric_time__extract_day + , subq_31.ds__extract_dow AS metric_time__extract_dow + , subq_31.ds__extract_doy AS metric_time__extract_doy + , subq_31.listing + , subq_31.guest + , subq_31.host + , subq_31.booking__listing + , subq_31.booking__guest + , subq_31.booking__host + , subq_31.is_instant + , subq_31.booking__is_instant + , subq_31.bookings + , subq_31.instant_bookings + , subq_31.booking_value + , subq_31.max_booking_value + , subq_31.min_booking_value + , subq_31.bookers + , subq_31.average_booking_value + , subq_31.referred_bookings + , subq_31.median_booking_value + , subq_31.booking_value_p99 + , subq_31.discrete_booking_value_p99 + , subq_31.approximate_continuous_booking_value_p99 + , subq_31.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_31 + ) subq_32 + WHERE booking__is_instant + ) subq_33 + ) subq_34 LEFT OUTER JOIN ( -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_16.listing - , subq_16.is_lux_latest + subq_36.listing + , subq_36.is_lux_latest FROM ( -- Metric Time Dimension 'ds' SELECT - subq_15.ds__day - , subq_15.ds__week - , subq_15.ds__month - , subq_15.ds__quarter - , subq_15.ds__year - , subq_15.ds__extract_year - , subq_15.ds__extract_quarter - , subq_15.ds__extract_month - , subq_15.ds__extract_day - , subq_15.ds__extract_dow - , subq_15.ds__extract_doy - , subq_15.created_at__day - , subq_15.created_at__week - , subq_15.created_at__month - , subq_15.created_at__quarter - , subq_15.created_at__year - , subq_15.created_at__extract_year - , subq_15.created_at__extract_quarter - , subq_15.created_at__extract_month - , subq_15.created_at__extract_day - , subq_15.created_at__extract_dow - , subq_15.created_at__extract_doy - , subq_15.listing__ds__day - , subq_15.listing__ds__week - , subq_15.listing__ds__month - , subq_15.listing__ds__quarter - , subq_15.listing__ds__year - , subq_15.listing__ds__extract_year - , subq_15.listing__ds__extract_quarter - , subq_15.listing__ds__extract_month - , subq_15.listing__ds__extract_day - , subq_15.listing__ds__extract_dow - , subq_15.listing__ds__extract_doy - , subq_15.listing__created_at__day - , subq_15.listing__created_at__week - , subq_15.listing__created_at__month - , subq_15.listing__created_at__quarter - , subq_15.listing__created_at__year - , subq_15.listing__created_at__extract_year - , subq_15.listing__created_at__extract_quarter - , subq_15.listing__created_at__extract_month - , subq_15.listing__created_at__extract_day - , subq_15.listing__created_at__extract_dow - , subq_15.listing__created_at__extract_doy - , subq_15.ds__day AS metric_time__day - , subq_15.ds__week AS metric_time__week - , subq_15.ds__month AS metric_time__month - , subq_15.ds__quarter AS metric_time__quarter - , subq_15.ds__year AS metric_time__year - , subq_15.ds__extract_year AS metric_time__extract_year - , subq_15.ds__extract_quarter AS metric_time__extract_quarter - , subq_15.ds__extract_month AS metric_time__extract_month - , subq_15.ds__extract_day AS metric_time__extract_day - , subq_15.ds__extract_dow AS metric_time__extract_dow - , subq_15.ds__extract_doy AS metric_time__extract_doy - , subq_15.listing - , subq_15.user - , subq_15.listing__user - , subq_15.country_latest - , subq_15.is_lux_latest - , subq_15.capacity_latest - , subq_15.listing__country_latest - , subq_15.listing__is_lux_latest - , subq_15.listing__capacity_latest - , subq_15.listings - , subq_15.largest_listing - , subq_15.smallest_listing + subq_35.ds__day + , subq_35.ds__week + , subq_35.ds__month + , subq_35.ds__quarter + , subq_35.ds__year + , subq_35.ds__extract_year + , subq_35.ds__extract_quarter + , subq_35.ds__extract_month + , subq_35.ds__extract_day + , subq_35.ds__extract_dow + , subq_35.ds__extract_doy + , subq_35.created_at__day + , subq_35.created_at__week + , subq_35.created_at__month + , subq_35.created_at__quarter + , subq_35.created_at__year + , subq_35.created_at__extract_year + , subq_35.created_at__extract_quarter + , subq_35.created_at__extract_month + , subq_35.created_at__extract_day + , subq_35.created_at__extract_dow + , subq_35.created_at__extract_doy + , subq_35.listing__ds__day + , subq_35.listing__ds__week + , subq_35.listing__ds__month + , subq_35.listing__ds__quarter + , subq_35.listing__ds__year + , subq_35.listing__ds__extract_year + , subq_35.listing__ds__extract_quarter + , subq_35.listing__ds__extract_month + , subq_35.listing__ds__extract_day + , subq_35.listing__ds__extract_dow + , subq_35.listing__ds__extract_doy + , subq_35.listing__created_at__day + , subq_35.listing__created_at__week + , subq_35.listing__created_at__month + , subq_35.listing__created_at__quarter + , subq_35.listing__created_at__year + , subq_35.listing__created_at__extract_year + , subq_35.listing__created_at__extract_quarter + , subq_35.listing__created_at__extract_month + , subq_35.listing__created_at__extract_day + , subq_35.listing__created_at__extract_dow + , subq_35.listing__created_at__extract_doy + , subq_35.ds__day AS metric_time__day + , subq_35.ds__week AS metric_time__week + , subq_35.ds__month AS metric_time__month + , subq_35.ds__quarter AS metric_time__quarter + , subq_35.ds__year AS metric_time__year + , subq_35.ds__extract_year AS metric_time__extract_year + , subq_35.ds__extract_quarter AS metric_time__extract_quarter + , subq_35.ds__extract_month AS metric_time__extract_month + , subq_35.ds__extract_day AS metric_time__extract_day + , subq_35.ds__extract_dow AS metric_time__extract_dow + , subq_35.ds__extract_doy AS metric_time__extract_doy + , subq_35.listing + , subq_35.user + , subq_35.listing__user + , subq_35.country_latest + , subq_35.is_lux_latest + , subq_35.capacity_latest + , subq_35.listing__country_latest + , subq_35.listing__is_lux_latest + , subq_35.listing__capacity_latest + , subq_35.listings + , subq_35.largest_listing + , subq_35.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -759,240 +965,343 @@ FROM ( , listings_latest_src_28000.user_id AS user , listings_latest_src_28000.user_id AS listing__user FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_15 - ) subq_16 - ) subq_17 + ) subq_35 + ) subq_36 + ) subq_37 ON - subq_14.listing = subq_17.listing - ) subq_18 - ) subq_19 + subq_34.listing = subq_37.listing + ) subq_38 + ) subq_39 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_20 - ) subq_21 - ) subq_22 - ) subq_23 + ) subq_40 + ) subq_41 + ) subq_42 + ) subq_43 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_29.booking_value + subq_50.booking_value FROM ( -- Aggregate Measures SELECT - SUM(subq_28.booking_value) AS booking_value + SUM(subq_49.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value',] SELECT - subq_27.booking_value + subq_48.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_26.booking__is_instant - , subq_26.booking_value + subq_47.booking__is_instant + , subq_47.booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__is_instant'] SELECT - subq_25.booking__is_instant - , subq_25.booking_value + subq_46.booking__is_instant + , subq_46.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_24.ds__day - , subq_24.ds__week - , subq_24.ds__month - , subq_24.ds__quarter - , subq_24.ds__year - , subq_24.ds__extract_year - , subq_24.ds__extract_quarter - , subq_24.ds__extract_month - , subq_24.ds__extract_day - , subq_24.ds__extract_dow - , subq_24.ds__extract_doy - , subq_24.ds_partitioned__day - , subq_24.ds_partitioned__week - , subq_24.ds_partitioned__month - , subq_24.ds_partitioned__quarter - , subq_24.ds_partitioned__year - , subq_24.ds_partitioned__extract_year - , subq_24.ds_partitioned__extract_quarter - , subq_24.ds_partitioned__extract_month - , subq_24.ds_partitioned__extract_day - , subq_24.ds_partitioned__extract_dow - , subq_24.ds_partitioned__extract_doy - , subq_24.paid_at__day - , subq_24.paid_at__week - , subq_24.paid_at__month - , subq_24.paid_at__quarter - , subq_24.paid_at__year - , subq_24.paid_at__extract_year - , subq_24.paid_at__extract_quarter - , subq_24.paid_at__extract_month - , subq_24.paid_at__extract_day - , subq_24.paid_at__extract_dow - , subq_24.paid_at__extract_doy - , subq_24.booking__ds__day - , subq_24.booking__ds__week - , subq_24.booking__ds__month - , subq_24.booking__ds__quarter - , subq_24.booking__ds__year - , subq_24.booking__ds__extract_year - , subq_24.booking__ds__extract_quarter - , subq_24.booking__ds__extract_month - , subq_24.booking__ds__extract_day - , subq_24.booking__ds__extract_dow - , subq_24.booking__ds__extract_doy - , subq_24.booking__ds_partitioned__day - , subq_24.booking__ds_partitioned__week - , subq_24.booking__ds_partitioned__month - , subq_24.booking__ds_partitioned__quarter - , subq_24.booking__ds_partitioned__year - , subq_24.booking__ds_partitioned__extract_year - , subq_24.booking__ds_partitioned__extract_quarter - , subq_24.booking__ds_partitioned__extract_month - , subq_24.booking__ds_partitioned__extract_day - , subq_24.booking__ds_partitioned__extract_dow - , subq_24.booking__ds_partitioned__extract_doy - , subq_24.booking__paid_at__day - , subq_24.booking__paid_at__week - , subq_24.booking__paid_at__month - , subq_24.booking__paid_at__quarter - , subq_24.booking__paid_at__year - , subq_24.booking__paid_at__extract_year - , subq_24.booking__paid_at__extract_quarter - , subq_24.booking__paid_at__extract_month - , subq_24.booking__paid_at__extract_day - , subq_24.booking__paid_at__extract_dow - , subq_24.booking__paid_at__extract_doy - , subq_24.ds__day AS metric_time__day - , subq_24.ds__week AS metric_time__week - , subq_24.ds__month AS metric_time__month - , subq_24.ds__quarter AS metric_time__quarter - , subq_24.ds__year AS metric_time__year - , subq_24.ds__extract_year AS metric_time__extract_year - , subq_24.ds__extract_quarter AS metric_time__extract_quarter - , subq_24.ds__extract_month AS metric_time__extract_month - , subq_24.ds__extract_day AS metric_time__extract_day - , subq_24.ds__extract_dow AS metric_time__extract_dow - , subq_24.ds__extract_doy AS metric_time__extract_doy - , subq_24.listing - , subq_24.guest - , subq_24.host - , subq_24.booking__listing - , subq_24.booking__guest - , subq_24.booking__host - , subq_24.is_instant - , subq_24.booking__is_instant - , subq_24.bookings - , subq_24.instant_bookings - , subq_24.booking_value - , subq_24.max_booking_value - , subq_24.min_booking_value - , subq_24.bookers - , subq_24.average_booking_value - , subq_24.referred_bookings - , subq_24.median_booking_value - , subq_24.booking_value_p99 - , subq_24.discrete_booking_value_p99 - , subq_24.approximate_continuous_booking_value_p99 - , subq_24.approximate_discrete_booking_value_p99 + subq_45.ds__day + , subq_45.ds__week + , subq_45.ds__month + , subq_45.ds__quarter + , subq_45.ds__year + , subq_45.ds__extract_year + , subq_45.ds__extract_quarter + , subq_45.ds__extract_month + , subq_45.ds__extract_day + , subq_45.ds__extract_dow + , subq_45.ds__extract_doy + , subq_45.ds_partitioned__day + , subq_45.ds_partitioned__week + , subq_45.ds_partitioned__month + , subq_45.ds_partitioned__quarter + , subq_45.ds_partitioned__year + , subq_45.ds_partitioned__extract_year + , subq_45.ds_partitioned__extract_quarter + , subq_45.ds_partitioned__extract_month + , subq_45.ds_partitioned__extract_day + , subq_45.ds_partitioned__extract_dow + , subq_45.ds_partitioned__extract_doy + , subq_45.paid_at__day + , subq_45.paid_at__week + , subq_45.paid_at__month + , subq_45.paid_at__quarter + , subq_45.paid_at__year + , subq_45.paid_at__extract_year + , subq_45.paid_at__extract_quarter + , subq_45.paid_at__extract_month + , subq_45.paid_at__extract_day + , subq_45.paid_at__extract_dow + , subq_45.paid_at__extract_doy + , subq_45.booking__ds__day + , subq_45.booking__ds__week + , subq_45.booking__ds__month + , subq_45.booking__ds__quarter + , subq_45.booking__ds__year + , subq_45.booking__ds__extract_year + , subq_45.booking__ds__extract_quarter + , subq_45.booking__ds__extract_month + , subq_45.booking__ds__extract_day + , subq_45.booking__ds__extract_dow + , subq_45.booking__ds__extract_doy + , subq_45.booking__ds_partitioned__day + , subq_45.booking__ds_partitioned__week + , subq_45.booking__ds_partitioned__month + , subq_45.booking__ds_partitioned__quarter + , subq_45.booking__ds_partitioned__year + , subq_45.booking__ds_partitioned__extract_year + , subq_45.booking__ds_partitioned__extract_quarter + , subq_45.booking__ds_partitioned__extract_month + , subq_45.booking__ds_partitioned__extract_day + , subq_45.booking__ds_partitioned__extract_dow + , subq_45.booking__ds_partitioned__extract_doy + , subq_45.booking__paid_at__day + , subq_45.booking__paid_at__week + , subq_45.booking__paid_at__month + , subq_45.booking__paid_at__quarter + , subq_45.booking__paid_at__year + , subq_45.booking__paid_at__extract_year + , subq_45.booking__paid_at__extract_quarter + , subq_45.booking__paid_at__extract_month + , subq_45.booking__paid_at__extract_day + , subq_45.booking__paid_at__extract_dow + , subq_45.booking__paid_at__extract_doy + , subq_45.metric_time__day + , subq_45.metric_time__week + , subq_45.metric_time__month + , subq_45.metric_time__quarter + , subq_45.metric_time__year + , subq_45.metric_time__extract_year + , subq_45.metric_time__extract_quarter + , subq_45.metric_time__extract_month + , subq_45.metric_time__extract_day + , subq_45.metric_time__extract_dow + , subq_45.metric_time__extract_doy + , subq_45.listing + , subq_45.guest + , subq_45.host + , subq_45.booking__listing + , subq_45.booking__guest + , subq_45.booking__host + , subq_45.is_instant + , subq_45.booking__is_instant + , subq_45.bookings + , subq_45.instant_bookings + , subq_45.booking_value + , subq_45.max_booking_value + , subq_45.min_booking_value + , subq_45.bookers + , subq_45.average_booking_value + , subq_45.referred_bookings + , subq_45.median_booking_value + , subq_45.booking_value_p99 + , subq_45.discrete_booking_value_p99 + , subq_45.approximate_continuous_booking_value_p99 + , subq_45.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_24 - ) subq_25 - ) subq_26 + subq_44.ds__day + , subq_44.ds__week + , subq_44.ds__month + , subq_44.ds__quarter + , subq_44.ds__year + , subq_44.ds__extract_year + , subq_44.ds__extract_quarter + , subq_44.ds__extract_month + , subq_44.ds__extract_day + , subq_44.ds__extract_dow + , subq_44.ds__extract_doy + , subq_44.ds_partitioned__day + , subq_44.ds_partitioned__week + , subq_44.ds_partitioned__month + , subq_44.ds_partitioned__quarter + , subq_44.ds_partitioned__year + , subq_44.ds_partitioned__extract_year + , subq_44.ds_partitioned__extract_quarter + , subq_44.ds_partitioned__extract_month + , subq_44.ds_partitioned__extract_day + , subq_44.ds_partitioned__extract_dow + , subq_44.ds_partitioned__extract_doy + , subq_44.paid_at__day + , subq_44.paid_at__week + , subq_44.paid_at__month + , subq_44.paid_at__quarter + , subq_44.paid_at__year + , subq_44.paid_at__extract_year + , subq_44.paid_at__extract_quarter + , subq_44.paid_at__extract_month + , subq_44.paid_at__extract_day + , subq_44.paid_at__extract_dow + , subq_44.paid_at__extract_doy + , subq_44.booking__ds__day + , subq_44.booking__ds__week + , subq_44.booking__ds__month + , subq_44.booking__ds__quarter + , subq_44.booking__ds__year + , subq_44.booking__ds__extract_year + , subq_44.booking__ds__extract_quarter + , subq_44.booking__ds__extract_month + , subq_44.booking__ds__extract_day + , subq_44.booking__ds__extract_dow + , subq_44.booking__ds__extract_doy + , subq_44.booking__ds_partitioned__day + , subq_44.booking__ds_partitioned__week + , subq_44.booking__ds_partitioned__month + , subq_44.booking__ds_partitioned__quarter + , subq_44.booking__ds_partitioned__year + , subq_44.booking__ds_partitioned__extract_year + , subq_44.booking__ds_partitioned__extract_quarter + , subq_44.booking__ds_partitioned__extract_month + , subq_44.booking__ds_partitioned__extract_day + , subq_44.booking__ds_partitioned__extract_dow + , subq_44.booking__ds_partitioned__extract_doy + , subq_44.booking__paid_at__day + , subq_44.booking__paid_at__week + , subq_44.booking__paid_at__month + , subq_44.booking__paid_at__quarter + , subq_44.booking__paid_at__year + , subq_44.booking__paid_at__extract_year + , subq_44.booking__paid_at__extract_quarter + , subq_44.booking__paid_at__extract_month + , subq_44.booking__paid_at__extract_day + , subq_44.booking__paid_at__extract_dow + , subq_44.booking__paid_at__extract_doy + , subq_44.ds__day AS metric_time__day + , subq_44.ds__week AS metric_time__week + , subq_44.ds__month AS metric_time__month + , subq_44.ds__quarter AS metric_time__quarter + , subq_44.ds__year AS metric_time__year + , subq_44.ds__extract_year AS metric_time__extract_year + , subq_44.ds__extract_quarter AS metric_time__extract_quarter + , subq_44.ds__extract_month AS metric_time__extract_month + , subq_44.ds__extract_day AS metric_time__extract_day + , subq_44.ds__extract_dow AS metric_time__extract_dow + , subq_44.ds__extract_doy AS metric_time__extract_doy + , subq_44.listing + , subq_44.guest + , subq_44.host + , subq_44.booking__listing + , subq_44.booking__guest + , subq_44.booking__host + , subq_44.is_instant + , subq_44.booking__is_instant + , subq_44.bookings + , subq_44.instant_bookings + , subq_44.booking_value + , subq_44.max_booking_value + , subq_44.min_booking_value + , subq_44.bookers + , subq_44.average_booking_value + , subq_44.referred_bookings + , subq_44.median_booking_value + , subq_44.booking_value_p99 + , subq_44.discrete_booking_value_p99 + , subq_44.approximate_continuous_booking_value_p99 + , subq_44.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_44 + ) subq_45 + WHERE booking__is_instant + ) subq_46 + ) subq_47 WHERE booking__is_instant - ) subq_27 - ) subq_28 - ) subq_29 - ) subq_30 - ) subq_31 -) subq_32 + ) subq_48 + ) subq_49 + ) subq_50 + ) subq_51 + ) subq_52 +) subq_53 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_filters__plan0_optimized.sql index a73bfea928..a0fdc735bd 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_filters__plan0_optimized.sql @@ -8,9 +8,9 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_44.average_booking_value) AS average_booking_value - , MAX(subq_56.bookings) AS bookings - , MAX(subq_63.booking_value) AS booking_value + MAX(subq_66.average_booking_value) AS average_booking_value + , MAX(subq_79.bookings) AS bookings + , MAX(subq_87.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['average_booking_value',] @@ -22,17 +22,34 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - bookings_source_src_28000.is_instant AS booking__is_instant + subq_57.booking__is_instant AS booking__is_instant , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , bookings_source_src_28000.booking_value AS average_booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 + , subq_57.average_booking_value AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] + SELECT + listing + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_55 + WHERE booking__is_instant + ) subq_57 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - bookings_source_src_28000.listing_id = listings_latest_src_28000.listing_id - ) subq_40 + subq_57.listing = listings_latest_src_28000.listing_id + ) subq_62 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_44 + ) subq_66 CROSS JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings',] @@ -44,26 +61,34 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_47.booking__is_instant AS booking__is_instant + subq_70.booking__is_instant AS booking__is_instant , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , subq_47.bookings AS bookings + , subq_70.bookings AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - listing_id AS listing - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_47 + listing + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_68 + WHERE booking__is_instant + ) subq_70 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_47.listing = listings_latest_src_28000.listing_id - ) subq_52 + subq_70.listing = listings_latest_src_28000.listing_id + ) subq_75 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_56 + ) subq_79 CROSS JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value',] @@ -72,15 +97,22 @@ FROM ( SELECT SUM(booking_value) AS booking_value FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'booking__is_instant'] SELECT - is_instant AS booking__is_instant + booking__is_instant , booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_59 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_81 + WHERE booking__is_instant + ) subq_83 WHERE booking__is_instant - ) subq_63 - ) subq_64 -) subq_65 + ) subq_87 + ) subq_88 +) subq_89 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_filters__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_filters__plan0.sql index 4569d672d5..a54923e15b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_filters__plan0.sql @@ -8,317 +8,420 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_11.average_booking_value) AS average_booking_value - , MAX(subq_23.bookings) AS bookings - , MAX(subq_30.booking_value) AS booking_value + MAX(subq_30.average_booking_value) AS average_booking_value + , MAX(subq_43.bookings) AS bookings + , MAX(subq_51.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_10.average_booking_value + subq_29.average_booking_value FROM ( -- Aggregate Measures SELECT - AVG(subq_9.average_booking_value) AS average_booking_value + AVG(subq_28.average_booking_value) AS average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value',] SELECT - subq_8.average_booking_value + subq_27.average_booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_7.booking__is_instant - , subq_7.listing__is_lux_latest - , subq_7.average_booking_value + subq_26.booking__is_instant + , subq_26.listing__is_lux_latest + , subq_26.average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_6.booking__is_instant - , subq_6.listing__is_lux_latest - , subq_6.average_booking_value + subq_25.booking__is_instant + , subq_25.listing__is_lux_latest + , subq_25.average_booking_value FROM ( -- Join Standard Outputs SELECT - subq_2.listing AS listing - , subq_2.booking__is_instant AS booking__is_instant - , subq_5.is_lux_latest AS listing__is_lux_latest - , subq_2.average_booking_value AS average_booking_value + subq_21.listing AS listing + , subq_21.booking__is_instant AS booking__is_instant + , subq_24.is_lux_latest AS listing__is_lux_latest + , subq_21.average_booking_value AS average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] SELECT - subq_1.listing - , subq_1.booking__is_instant - , subq_1.average_booking_value + subq_20.listing + , subq_20.booking__is_instant + , subq_20.average_booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE 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.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.booking__paid_at__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.listing - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_19.ds__day + , subq_19.ds__week + , subq_19.ds__month + , subq_19.ds__quarter + , subq_19.ds__year + , subq_19.ds__extract_year + , subq_19.ds__extract_quarter + , subq_19.ds__extract_month + , subq_19.ds__extract_day + , subq_19.ds__extract_dow + , subq_19.ds__extract_doy + , subq_19.ds_partitioned__day + , subq_19.ds_partitioned__week + , subq_19.ds_partitioned__month + , subq_19.ds_partitioned__quarter + , subq_19.ds_partitioned__year + , subq_19.ds_partitioned__extract_year + , subq_19.ds_partitioned__extract_quarter + , subq_19.ds_partitioned__extract_month + , subq_19.ds_partitioned__extract_day + , subq_19.ds_partitioned__extract_dow + , subq_19.ds_partitioned__extract_doy + , subq_19.paid_at__day + , subq_19.paid_at__week + , subq_19.paid_at__month + , subq_19.paid_at__quarter + , subq_19.paid_at__year + , subq_19.paid_at__extract_year + , subq_19.paid_at__extract_quarter + , subq_19.paid_at__extract_month + , subq_19.paid_at__extract_day + , subq_19.paid_at__extract_dow + , subq_19.paid_at__extract_doy + , subq_19.booking__ds__day + , subq_19.booking__ds__week + , subq_19.booking__ds__month + , subq_19.booking__ds__quarter + , subq_19.booking__ds__year + , subq_19.booking__ds__extract_year + , subq_19.booking__ds__extract_quarter + , subq_19.booking__ds__extract_month + , subq_19.booking__ds__extract_day + , subq_19.booking__ds__extract_dow + , subq_19.booking__ds__extract_doy + , subq_19.booking__ds_partitioned__day + , subq_19.booking__ds_partitioned__week + , subq_19.booking__ds_partitioned__month + , subq_19.booking__ds_partitioned__quarter + , subq_19.booking__ds_partitioned__year + , subq_19.booking__ds_partitioned__extract_year + , subq_19.booking__ds_partitioned__extract_quarter + , subq_19.booking__ds_partitioned__extract_month + , subq_19.booking__ds_partitioned__extract_day + , subq_19.booking__ds_partitioned__extract_dow + , subq_19.booking__ds_partitioned__extract_doy + , subq_19.booking__paid_at__day + , subq_19.booking__paid_at__week + , subq_19.booking__paid_at__month + , subq_19.booking__paid_at__quarter + , subq_19.booking__paid_at__year + , subq_19.booking__paid_at__extract_year + , subq_19.booking__paid_at__extract_quarter + , subq_19.booking__paid_at__extract_month + , subq_19.booking__paid_at__extract_day + , subq_19.booking__paid_at__extract_dow + , subq_19.booking__paid_at__extract_doy + , subq_19.metric_time__day + , subq_19.metric_time__week + , subq_19.metric_time__month + , subq_19.metric_time__quarter + , subq_19.metric_time__year + , subq_19.metric_time__extract_year + , subq_19.metric_time__extract_quarter + , subq_19.metric_time__extract_month + , subq_19.metric_time__extract_day + , subq_19.metric_time__extract_dow + , subq_19.metric_time__extract_doy + , subq_19.listing + , subq_19.guest + , subq_19.host + , subq_19.booking__listing + , subq_19.booking__guest + , subq_19.booking__host + , subq_19.is_instant + , subq_19.booking__is_instant + , subq_19.bookings + , subq_19.instant_bookings + , subq_19.booking_value + , subq_19.max_booking_value + , subq_19.min_booking_value + , subq_19.bookers + , subq_19.average_booking_value + , subq_19.referred_bookings + , subq_19.median_booking_value + , subq_19.booking_value_p99 + , subq_19.discrete_booking_value_p99 + , subq_19.approximate_continuous_booking_value_p99 + , subq_19.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + subq_18.ds__day + , subq_18.ds__week + , subq_18.ds__month + , subq_18.ds__quarter + , subq_18.ds__year + , subq_18.ds__extract_year + , subq_18.ds__extract_quarter + , subq_18.ds__extract_month + , subq_18.ds__extract_day + , subq_18.ds__extract_dow + , subq_18.ds__extract_doy + , subq_18.ds_partitioned__day + , subq_18.ds_partitioned__week + , subq_18.ds_partitioned__month + , subq_18.ds_partitioned__quarter + , subq_18.ds_partitioned__year + , subq_18.ds_partitioned__extract_year + , subq_18.ds_partitioned__extract_quarter + , subq_18.ds_partitioned__extract_month + , subq_18.ds_partitioned__extract_day + , subq_18.ds_partitioned__extract_dow + , subq_18.ds_partitioned__extract_doy + , subq_18.paid_at__day + , subq_18.paid_at__week + , subq_18.paid_at__month + , subq_18.paid_at__quarter + , subq_18.paid_at__year + , subq_18.paid_at__extract_year + , subq_18.paid_at__extract_quarter + , subq_18.paid_at__extract_month + , subq_18.paid_at__extract_day + , subq_18.paid_at__extract_dow + , subq_18.paid_at__extract_doy + , subq_18.booking__ds__day + , subq_18.booking__ds__week + , subq_18.booking__ds__month + , subq_18.booking__ds__quarter + , subq_18.booking__ds__year + , subq_18.booking__ds__extract_year + , subq_18.booking__ds__extract_quarter + , subq_18.booking__ds__extract_month + , subq_18.booking__ds__extract_day + , subq_18.booking__ds__extract_dow + , subq_18.booking__ds__extract_doy + , subq_18.booking__ds_partitioned__day + , subq_18.booking__ds_partitioned__week + , subq_18.booking__ds_partitioned__month + , subq_18.booking__ds_partitioned__quarter + , subq_18.booking__ds_partitioned__year + , subq_18.booking__ds_partitioned__extract_year + , subq_18.booking__ds_partitioned__extract_quarter + , subq_18.booking__ds_partitioned__extract_month + , subq_18.booking__ds_partitioned__extract_day + , subq_18.booking__ds_partitioned__extract_dow + , subq_18.booking__ds_partitioned__extract_doy + , subq_18.booking__paid_at__day + , subq_18.booking__paid_at__week + , subq_18.booking__paid_at__month + , subq_18.booking__paid_at__quarter + , subq_18.booking__paid_at__year + , subq_18.booking__paid_at__extract_year + , subq_18.booking__paid_at__extract_quarter + , subq_18.booking__paid_at__extract_month + , subq_18.booking__paid_at__extract_day + , subq_18.booking__paid_at__extract_dow + , subq_18.booking__paid_at__extract_doy + , subq_18.ds__day AS metric_time__day + , subq_18.ds__week AS metric_time__week + , subq_18.ds__month AS metric_time__month + , subq_18.ds__quarter AS metric_time__quarter + , subq_18.ds__year AS metric_time__year + , subq_18.ds__extract_year AS metric_time__extract_year + , subq_18.ds__extract_quarter AS metric_time__extract_quarter + , subq_18.ds__extract_month AS metric_time__extract_month + , subq_18.ds__extract_day AS metric_time__extract_day + , subq_18.ds__extract_dow AS metric_time__extract_dow + , subq_18.ds__extract_doy AS metric_time__extract_doy + , subq_18.listing + , subq_18.guest + , subq_18.host + , subq_18.booking__listing + , subq_18.booking__guest + , subq_18.booking__host + , subq_18.is_instant + , subq_18.booking__is_instant + , subq_18.bookings + , subq_18.instant_bookings + , subq_18.booking_value + , subq_18.max_booking_value + , subq_18.min_booking_value + , subq_18.bookers + , subq_18.average_booking_value + , subq_18.referred_bookings + , subq_18.median_booking_value + , subq_18.booking_value_p99 + , subq_18.discrete_booking_value_p99 + , subq_18.approximate_continuous_booking_value_p99 + , subq_18.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_18 + ) subq_19 + WHERE booking__is_instant + ) subq_20 + ) subq_21 LEFT OUTER JOIN ( -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_4.listing - , subq_4.is_lux_latest + subq_23.listing + , subq_23.is_lux_latest FROM ( -- Metric Time Dimension 'ds' SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing + subq_22.ds__day + , subq_22.ds__week + , subq_22.ds__month + , subq_22.ds__quarter + , subq_22.ds__year + , subq_22.ds__extract_year + , subq_22.ds__extract_quarter + , subq_22.ds__extract_month + , subq_22.ds__extract_day + , subq_22.ds__extract_dow + , subq_22.ds__extract_doy + , subq_22.created_at__day + , subq_22.created_at__week + , subq_22.created_at__month + , subq_22.created_at__quarter + , subq_22.created_at__year + , subq_22.created_at__extract_year + , subq_22.created_at__extract_quarter + , subq_22.created_at__extract_month + , subq_22.created_at__extract_day + , subq_22.created_at__extract_dow + , subq_22.created_at__extract_doy + , subq_22.listing__ds__day + , subq_22.listing__ds__week + , subq_22.listing__ds__month + , subq_22.listing__ds__quarter + , subq_22.listing__ds__year + , subq_22.listing__ds__extract_year + , subq_22.listing__ds__extract_quarter + , subq_22.listing__ds__extract_month + , subq_22.listing__ds__extract_day + , subq_22.listing__ds__extract_dow + , subq_22.listing__ds__extract_doy + , subq_22.listing__created_at__day + , subq_22.listing__created_at__week + , subq_22.listing__created_at__month + , subq_22.listing__created_at__quarter + , subq_22.listing__created_at__year + , subq_22.listing__created_at__extract_year + , subq_22.listing__created_at__extract_quarter + , subq_22.listing__created_at__extract_month + , subq_22.listing__created_at__extract_day + , subq_22.listing__created_at__extract_dow + , subq_22.listing__created_at__extract_doy + , subq_22.ds__day AS metric_time__day + , subq_22.ds__week AS metric_time__week + , subq_22.ds__month AS metric_time__month + , subq_22.ds__quarter AS metric_time__quarter + , subq_22.ds__year AS metric_time__year + , subq_22.ds__extract_year AS metric_time__extract_year + , subq_22.ds__extract_quarter AS metric_time__extract_quarter + , subq_22.ds__extract_month AS metric_time__extract_month + , subq_22.ds__extract_day AS metric_time__extract_day + , subq_22.ds__extract_dow AS metric_time__extract_dow + , subq_22.ds__extract_doy AS metric_time__extract_doy + , subq_22.listing + , subq_22.user + , subq_22.listing__user + , subq_22.country_latest + , subq_22.is_lux_latest + , subq_22.capacity_latest + , subq_22.listing__country_latest + , subq_22.listing__is_lux_latest + , subq_22.listing__capacity_latest + , subq_22.listings + , subq_22.largest_listing + , subq_22.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -379,326 +482,429 @@ FROM ( , listings_latest_src_28000.user_id AS user , listings_latest_src_28000.user_id AS listing__user FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_3 - ) subq_4 - ) subq_5 + ) subq_22 + ) subq_23 + ) subq_24 ON - subq_2.listing = subq_5.listing - ) subq_6 - ) subq_7 + subq_21.listing = subq_24.listing + ) subq_25 + ) subq_26 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_8 - ) subq_9 - ) subq_10 - ) subq_11 + ) subq_27 + ) subq_28 + ) subq_29 + ) subq_30 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_22.bookings + subq_42.bookings FROM ( -- Aggregate Measures SELECT - SUM(subq_21.bookings) AS bookings + SUM(subq_41.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings',] SELECT - subq_20.bookings + subq_40.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_19.booking__is_instant - , subq_19.listing__is_lux_latest - , subq_19.bookings + subq_39.booking__is_instant + , subq_39.listing__is_lux_latest + , subq_39.bookings FROM ( -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_18.booking__is_instant - , subq_18.listing__is_lux_latest - , subq_18.bookings + subq_38.booking__is_instant + , subq_38.listing__is_lux_latest + , subq_38.bookings FROM ( -- Join Standard Outputs SELECT - subq_14.listing AS listing - , subq_14.booking__is_instant AS booking__is_instant - , subq_17.is_lux_latest AS listing__is_lux_latest - , subq_14.bookings AS bookings + subq_34.listing AS listing + , subq_34.booking__is_instant AS booking__is_instant + , subq_37.is_lux_latest AS listing__is_lux_latest + , subq_34.bookings AS bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - subq_13.listing - , subq_13.booking__is_instant - , subq_13.bookings + subq_33.listing + , subq_33.booking__is_instant + , subq_33.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_12.ds__day - , subq_12.ds__week - , subq_12.ds__month - , subq_12.ds__quarter - , subq_12.ds__year - , subq_12.ds__extract_year - , subq_12.ds__extract_quarter - , subq_12.ds__extract_month - , subq_12.ds__extract_day - , subq_12.ds__extract_dow - , subq_12.ds__extract_doy - , subq_12.ds_partitioned__day - , subq_12.ds_partitioned__week - , subq_12.ds_partitioned__month - , subq_12.ds_partitioned__quarter - , subq_12.ds_partitioned__year - , subq_12.ds_partitioned__extract_year - , subq_12.ds_partitioned__extract_quarter - , subq_12.ds_partitioned__extract_month - , subq_12.ds_partitioned__extract_day - , subq_12.ds_partitioned__extract_dow - , subq_12.ds_partitioned__extract_doy - , subq_12.paid_at__day - , subq_12.paid_at__week - , subq_12.paid_at__month - , subq_12.paid_at__quarter - , subq_12.paid_at__year - , subq_12.paid_at__extract_year - , subq_12.paid_at__extract_quarter - , subq_12.paid_at__extract_month - , subq_12.paid_at__extract_day - , subq_12.paid_at__extract_dow - , subq_12.paid_at__extract_doy - , subq_12.booking__ds__day - , subq_12.booking__ds__week - , subq_12.booking__ds__month - , subq_12.booking__ds__quarter - , subq_12.booking__ds__year - , subq_12.booking__ds__extract_year - , subq_12.booking__ds__extract_quarter - , subq_12.booking__ds__extract_month - , subq_12.booking__ds__extract_day - , subq_12.booking__ds__extract_dow - , subq_12.booking__ds__extract_doy - , subq_12.booking__ds_partitioned__day - , subq_12.booking__ds_partitioned__week - , subq_12.booking__ds_partitioned__month - , subq_12.booking__ds_partitioned__quarter - , subq_12.booking__ds_partitioned__year - , subq_12.booking__ds_partitioned__extract_year - , subq_12.booking__ds_partitioned__extract_quarter - , subq_12.booking__ds_partitioned__extract_month - , subq_12.booking__ds_partitioned__extract_day - , subq_12.booking__ds_partitioned__extract_dow - , subq_12.booking__ds_partitioned__extract_doy - , subq_12.booking__paid_at__day - , subq_12.booking__paid_at__week - , subq_12.booking__paid_at__month - , subq_12.booking__paid_at__quarter - , subq_12.booking__paid_at__year - , subq_12.booking__paid_at__extract_year - , subq_12.booking__paid_at__extract_quarter - , subq_12.booking__paid_at__extract_month - , subq_12.booking__paid_at__extract_day - , subq_12.booking__paid_at__extract_dow - , subq_12.booking__paid_at__extract_doy - , subq_12.ds__day AS metric_time__day - , subq_12.ds__week AS metric_time__week - , subq_12.ds__month AS metric_time__month - , subq_12.ds__quarter AS metric_time__quarter - , subq_12.ds__year AS metric_time__year - , subq_12.ds__extract_year AS metric_time__extract_year - , subq_12.ds__extract_quarter AS metric_time__extract_quarter - , subq_12.ds__extract_month AS metric_time__extract_month - , subq_12.ds__extract_day AS metric_time__extract_day - , subq_12.ds__extract_dow AS metric_time__extract_dow - , subq_12.ds__extract_doy AS metric_time__extract_doy - , subq_12.listing - , subq_12.guest - , subq_12.host - , subq_12.booking__listing - , subq_12.booking__guest - , subq_12.booking__host - , subq_12.is_instant - , subq_12.booking__is_instant - , subq_12.bookings - , subq_12.instant_bookings - , subq_12.booking_value - , subq_12.max_booking_value - , subq_12.min_booking_value - , subq_12.bookers - , subq_12.average_booking_value - , subq_12.referred_bookings - , subq_12.median_booking_value - , subq_12.booking_value_p99 - , subq_12.discrete_booking_value_p99 - , subq_12.approximate_continuous_booking_value_p99 - , subq_12.approximate_discrete_booking_value_p99 + subq_32.ds__day + , subq_32.ds__week + , subq_32.ds__month + , subq_32.ds__quarter + , subq_32.ds__year + , subq_32.ds__extract_year + , subq_32.ds__extract_quarter + , subq_32.ds__extract_month + , subq_32.ds__extract_day + , subq_32.ds__extract_dow + , subq_32.ds__extract_doy + , subq_32.ds_partitioned__day + , subq_32.ds_partitioned__week + , subq_32.ds_partitioned__month + , subq_32.ds_partitioned__quarter + , subq_32.ds_partitioned__year + , subq_32.ds_partitioned__extract_year + , subq_32.ds_partitioned__extract_quarter + , subq_32.ds_partitioned__extract_month + , subq_32.ds_partitioned__extract_day + , subq_32.ds_partitioned__extract_dow + , subq_32.ds_partitioned__extract_doy + , subq_32.paid_at__day + , subq_32.paid_at__week + , subq_32.paid_at__month + , subq_32.paid_at__quarter + , subq_32.paid_at__year + , subq_32.paid_at__extract_year + , subq_32.paid_at__extract_quarter + , subq_32.paid_at__extract_month + , subq_32.paid_at__extract_day + , subq_32.paid_at__extract_dow + , subq_32.paid_at__extract_doy + , subq_32.booking__ds__day + , subq_32.booking__ds__week + , subq_32.booking__ds__month + , subq_32.booking__ds__quarter + , subq_32.booking__ds__year + , subq_32.booking__ds__extract_year + , subq_32.booking__ds__extract_quarter + , subq_32.booking__ds__extract_month + , subq_32.booking__ds__extract_day + , subq_32.booking__ds__extract_dow + , subq_32.booking__ds__extract_doy + , subq_32.booking__ds_partitioned__day + , subq_32.booking__ds_partitioned__week + , subq_32.booking__ds_partitioned__month + , subq_32.booking__ds_partitioned__quarter + , subq_32.booking__ds_partitioned__year + , subq_32.booking__ds_partitioned__extract_year + , subq_32.booking__ds_partitioned__extract_quarter + , subq_32.booking__ds_partitioned__extract_month + , subq_32.booking__ds_partitioned__extract_day + , subq_32.booking__ds_partitioned__extract_dow + , subq_32.booking__ds_partitioned__extract_doy + , subq_32.booking__paid_at__day + , subq_32.booking__paid_at__week + , subq_32.booking__paid_at__month + , subq_32.booking__paid_at__quarter + , subq_32.booking__paid_at__year + , subq_32.booking__paid_at__extract_year + , subq_32.booking__paid_at__extract_quarter + , subq_32.booking__paid_at__extract_month + , subq_32.booking__paid_at__extract_day + , subq_32.booking__paid_at__extract_dow + , subq_32.booking__paid_at__extract_doy + , subq_32.metric_time__day + , subq_32.metric_time__week + , subq_32.metric_time__month + , subq_32.metric_time__quarter + , subq_32.metric_time__year + , subq_32.metric_time__extract_year + , subq_32.metric_time__extract_quarter + , subq_32.metric_time__extract_month + , subq_32.metric_time__extract_day + , subq_32.metric_time__extract_dow + , subq_32.metric_time__extract_doy + , subq_32.listing + , subq_32.guest + , subq_32.host + , subq_32.booking__listing + , subq_32.booking__guest + , subq_32.booking__host + , subq_32.is_instant + , subq_32.booking__is_instant + , subq_32.bookings + , subq_32.instant_bookings + , subq_32.booking_value + , subq_32.max_booking_value + , subq_32.min_booking_value + , subq_32.bookers + , subq_32.average_booking_value + , subq_32.referred_bookings + , subq_32.median_booking_value + , subq_32.booking_value_p99 + , subq_32.discrete_booking_value_p99 + , subq_32.approximate_continuous_booking_value_p99 + , subq_32.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_12 - ) subq_13 - ) subq_14 + subq_31.ds__day + , subq_31.ds__week + , subq_31.ds__month + , subq_31.ds__quarter + , subq_31.ds__year + , subq_31.ds__extract_year + , subq_31.ds__extract_quarter + , subq_31.ds__extract_month + , subq_31.ds__extract_day + , subq_31.ds__extract_dow + , subq_31.ds__extract_doy + , subq_31.ds_partitioned__day + , subq_31.ds_partitioned__week + , subq_31.ds_partitioned__month + , subq_31.ds_partitioned__quarter + , subq_31.ds_partitioned__year + , subq_31.ds_partitioned__extract_year + , subq_31.ds_partitioned__extract_quarter + , subq_31.ds_partitioned__extract_month + , subq_31.ds_partitioned__extract_day + , subq_31.ds_partitioned__extract_dow + , subq_31.ds_partitioned__extract_doy + , subq_31.paid_at__day + , subq_31.paid_at__week + , subq_31.paid_at__month + , subq_31.paid_at__quarter + , subq_31.paid_at__year + , subq_31.paid_at__extract_year + , subq_31.paid_at__extract_quarter + , subq_31.paid_at__extract_month + , subq_31.paid_at__extract_day + , subq_31.paid_at__extract_dow + , subq_31.paid_at__extract_doy + , subq_31.booking__ds__day + , subq_31.booking__ds__week + , subq_31.booking__ds__month + , subq_31.booking__ds__quarter + , subq_31.booking__ds__year + , subq_31.booking__ds__extract_year + , subq_31.booking__ds__extract_quarter + , subq_31.booking__ds__extract_month + , subq_31.booking__ds__extract_day + , subq_31.booking__ds__extract_dow + , subq_31.booking__ds__extract_doy + , subq_31.booking__ds_partitioned__day + , subq_31.booking__ds_partitioned__week + , subq_31.booking__ds_partitioned__month + , subq_31.booking__ds_partitioned__quarter + , subq_31.booking__ds_partitioned__year + , subq_31.booking__ds_partitioned__extract_year + , subq_31.booking__ds_partitioned__extract_quarter + , subq_31.booking__ds_partitioned__extract_month + , subq_31.booking__ds_partitioned__extract_day + , subq_31.booking__ds_partitioned__extract_dow + , subq_31.booking__ds_partitioned__extract_doy + , subq_31.booking__paid_at__day + , subq_31.booking__paid_at__week + , subq_31.booking__paid_at__month + , subq_31.booking__paid_at__quarter + , subq_31.booking__paid_at__year + , subq_31.booking__paid_at__extract_year + , subq_31.booking__paid_at__extract_quarter + , subq_31.booking__paid_at__extract_month + , subq_31.booking__paid_at__extract_day + , subq_31.booking__paid_at__extract_dow + , subq_31.booking__paid_at__extract_doy + , subq_31.ds__day AS metric_time__day + , subq_31.ds__week AS metric_time__week + , subq_31.ds__month AS metric_time__month + , subq_31.ds__quarter AS metric_time__quarter + , subq_31.ds__year AS metric_time__year + , subq_31.ds__extract_year AS metric_time__extract_year + , subq_31.ds__extract_quarter AS metric_time__extract_quarter + , subq_31.ds__extract_month AS metric_time__extract_month + , subq_31.ds__extract_day AS metric_time__extract_day + , subq_31.ds__extract_dow AS metric_time__extract_dow + , subq_31.ds__extract_doy AS metric_time__extract_doy + , subq_31.listing + , subq_31.guest + , subq_31.host + , subq_31.booking__listing + , subq_31.booking__guest + , subq_31.booking__host + , subq_31.is_instant + , subq_31.booking__is_instant + , subq_31.bookings + , subq_31.instant_bookings + , subq_31.booking_value + , subq_31.max_booking_value + , subq_31.min_booking_value + , subq_31.bookers + , subq_31.average_booking_value + , subq_31.referred_bookings + , subq_31.median_booking_value + , subq_31.booking_value_p99 + , subq_31.discrete_booking_value_p99 + , subq_31.approximate_continuous_booking_value_p99 + , subq_31.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_31 + ) subq_32 + WHERE booking__is_instant + ) subq_33 + ) subq_34 LEFT OUTER JOIN ( -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_16.listing - , subq_16.is_lux_latest + subq_36.listing + , subq_36.is_lux_latest FROM ( -- Metric Time Dimension 'ds' SELECT - subq_15.ds__day - , subq_15.ds__week - , subq_15.ds__month - , subq_15.ds__quarter - , subq_15.ds__year - , subq_15.ds__extract_year - , subq_15.ds__extract_quarter - , subq_15.ds__extract_month - , subq_15.ds__extract_day - , subq_15.ds__extract_dow - , subq_15.ds__extract_doy - , subq_15.created_at__day - , subq_15.created_at__week - , subq_15.created_at__month - , subq_15.created_at__quarter - , subq_15.created_at__year - , subq_15.created_at__extract_year - , subq_15.created_at__extract_quarter - , subq_15.created_at__extract_month - , subq_15.created_at__extract_day - , subq_15.created_at__extract_dow - , subq_15.created_at__extract_doy - , subq_15.listing__ds__day - , subq_15.listing__ds__week - , subq_15.listing__ds__month - , subq_15.listing__ds__quarter - , subq_15.listing__ds__year - , subq_15.listing__ds__extract_year - , subq_15.listing__ds__extract_quarter - , subq_15.listing__ds__extract_month - , subq_15.listing__ds__extract_day - , subq_15.listing__ds__extract_dow - , subq_15.listing__ds__extract_doy - , subq_15.listing__created_at__day - , subq_15.listing__created_at__week - , subq_15.listing__created_at__month - , subq_15.listing__created_at__quarter - , subq_15.listing__created_at__year - , subq_15.listing__created_at__extract_year - , subq_15.listing__created_at__extract_quarter - , subq_15.listing__created_at__extract_month - , subq_15.listing__created_at__extract_day - , subq_15.listing__created_at__extract_dow - , subq_15.listing__created_at__extract_doy - , subq_15.ds__day AS metric_time__day - , subq_15.ds__week AS metric_time__week - , subq_15.ds__month AS metric_time__month - , subq_15.ds__quarter AS metric_time__quarter - , subq_15.ds__year AS metric_time__year - , subq_15.ds__extract_year AS metric_time__extract_year - , subq_15.ds__extract_quarter AS metric_time__extract_quarter - , subq_15.ds__extract_month AS metric_time__extract_month - , subq_15.ds__extract_day AS metric_time__extract_day - , subq_15.ds__extract_dow AS metric_time__extract_dow - , subq_15.ds__extract_doy AS metric_time__extract_doy - , subq_15.listing - , subq_15.user - , subq_15.listing__user - , subq_15.country_latest - , subq_15.is_lux_latest - , subq_15.capacity_latest - , subq_15.listing__country_latest - , subq_15.listing__is_lux_latest - , subq_15.listing__capacity_latest - , subq_15.listings - , subq_15.largest_listing - , subq_15.smallest_listing + subq_35.ds__day + , subq_35.ds__week + , subq_35.ds__month + , subq_35.ds__quarter + , subq_35.ds__year + , subq_35.ds__extract_year + , subq_35.ds__extract_quarter + , subq_35.ds__extract_month + , subq_35.ds__extract_day + , subq_35.ds__extract_dow + , subq_35.ds__extract_doy + , subq_35.created_at__day + , subq_35.created_at__week + , subq_35.created_at__month + , subq_35.created_at__quarter + , subq_35.created_at__year + , subq_35.created_at__extract_year + , subq_35.created_at__extract_quarter + , subq_35.created_at__extract_month + , subq_35.created_at__extract_day + , subq_35.created_at__extract_dow + , subq_35.created_at__extract_doy + , subq_35.listing__ds__day + , subq_35.listing__ds__week + , subq_35.listing__ds__month + , subq_35.listing__ds__quarter + , subq_35.listing__ds__year + , subq_35.listing__ds__extract_year + , subq_35.listing__ds__extract_quarter + , subq_35.listing__ds__extract_month + , subq_35.listing__ds__extract_day + , subq_35.listing__ds__extract_dow + , subq_35.listing__ds__extract_doy + , subq_35.listing__created_at__day + , subq_35.listing__created_at__week + , subq_35.listing__created_at__month + , subq_35.listing__created_at__quarter + , subq_35.listing__created_at__year + , subq_35.listing__created_at__extract_year + , subq_35.listing__created_at__extract_quarter + , subq_35.listing__created_at__extract_month + , subq_35.listing__created_at__extract_day + , subq_35.listing__created_at__extract_dow + , subq_35.listing__created_at__extract_doy + , subq_35.ds__day AS metric_time__day + , subq_35.ds__week AS metric_time__week + , subq_35.ds__month AS metric_time__month + , subq_35.ds__quarter AS metric_time__quarter + , subq_35.ds__year AS metric_time__year + , subq_35.ds__extract_year AS metric_time__extract_year + , subq_35.ds__extract_quarter AS metric_time__extract_quarter + , subq_35.ds__extract_month AS metric_time__extract_month + , subq_35.ds__extract_day AS metric_time__extract_day + , subq_35.ds__extract_dow AS metric_time__extract_dow + , subq_35.ds__extract_doy AS metric_time__extract_doy + , subq_35.listing + , subq_35.user + , subq_35.listing__user + , subq_35.country_latest + , subq_35.is_lux_latest + , subq_35.capacity_latest + , subq_35.listing__country_latest + , subq_35.listing__is_lux_latest + , subq_35.listing__capacity_latest + , subq_35.listings + , subq_35.largest_listing + , subq_35.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -759,240 +965,343 @@ FROM ( , listings_latest_src_28000.user_id AS user , listings_latest_src_28000.user_id AS listing__user FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_15 - ) subq_16 - ) subq_17 + ) subq_35 + ) subq_36 + ) subq_37 ON - subq_14.listing = subq_17.listing - ) subq_18 - ) subq_19 + subq_34.listing = subq_37.listing + ) subq_38 + ) subq_39 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_20 - ) subq_21 - ) subq_22 - ) subq_23 + ) subq_40 + ) subq_41 + ) subq_42 + ) subq_43 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_29.booking_value + subq_50.booking_value FROM ( -- Aggregate Measures SELECT - SUM(subq_28.booking_value) AS booking_value + SUM(subq_49.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value',] SELECT - subq_27.booking_value + subq_48.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_26.booking__is_instant - , subq_26.booking_value + subq_47.booking__is_instant + , subq_47.booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__is_instant'] SELECT - subq_25.booking__is_instant - , subq_25.booking_value + subq_46.booking__is_instant + , subq_46.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_24.ds__day - , subq_24.ds__week - , subq_24.ds__month - , subq_24.ds__quarter - , subq_24.ds__year - , subq_24.ds__extract_year - , subq_24.ds__extract_quarter - , subq_24.ds__extract_month - , subq_24.ds__extract_day - , subq_24.ds__extract_dow - , subq_24.ds__extract_doy - , subq_24.ds_partitioned__day - , subq_24.ds_partitioned__week - , subq_24.ds_partitioned__month - , subq_24.ds_partitioned__quarter - , subq_24.ds_partitioned__year - , subq_24.ds_partitioned__extract_year - , subq_24.ds_partitioned__extract_quarter - , subq_24.ds_partitioned__extract_month - , subq_24.ds_partitioned__extract_day - , subq_24.ds_partitioned__extract_dow - , subq_24.ds_partitioned__extract_doy - , subq_24.paid_at__day - , subq_24.paid_at__week - , subq_24.paid_at__month - , subq_24.paid_at__quarter - , subq_24.paid_at__year - , subq_24.paid_at__extract_year - , subq_24.paid_at__extract_quarter - , subq_24.paid_at__extract_month - , subq_24.paid_at__extract_day - , subq_24.paid_at__extract_dow - , subq_24.paid_at__extract_doy - , subq_24.booking__ds__day - , subq_24.booking__ds__week - , subq_24.booking__ds__month - , subq_24.booking__ds__quarter - , subq_24.booking__ds__year - , subq_24.booking__ds__extract_year - , subq_24.booking__ds__extract_quarter - , subq_24.booking__ds__extract_month - , subq_24.booking__ds__extract_day - , subq_24.booking__ds__extract_dow - , subq_24.booking__ds__extract_doy - , subq_24.booking__ds_partitioned__day - , subq_24.booking__ds_partitioned__week - , subq_24.booking__ds_partitioned__month - , subq_24.booking__ds_partitioned__quarter - , subq_24.booking__ds_partitioned__year - , subq_24.booking__ds_partitioned__extract_year - , subq_24.booking__ds_partitioned__extract_quarter - , subq_24.booking__ds_partitioned__extract_month - , subq_24.booking__ds_partitioned__extract_day - , subq_24.booking__ds_partitioned__extract_dow - , subq_24.booking__ds_partitioned__extract_doy - , subq_24.booking__paid_at__day - , subq_24.booking__paid_at__week - , subq_24.booking__paid_at__month - , subq_24.booking__paid_at__quarter - , subq_24.booking__paid_at__year - , subq_24.booking__paid_at__extract_year - , subq_24.booking__paid_at__extract_quarter - , subq_24.booking__paid_at__extract_month - , subq_24.booking__paid_at__extract_day - , subq_24.booking__paid_at__extract_dow - , subq_24.booking__paid_at__extract_doy - , subq_24.ds__day AS metric_time__day - , subq_24.ds__week AS metric_time__week - , subq_24.ds__month AS metric_time__month - , subq_24.ds__quarter AS metric_time__quarter - , subq_24.ds__year AS metric_time__year - , subq_24.ds__extract_year AS metric_time__extract_year - , subq_24.ds__extract_quarter AS metric_time__extract_quarter - , subq_24.ds__extract_month AS metric_time__extract_month - , subq_24.ds__extract_day AS metric_time__extract_day - , subq_24.ds__extract_dow AS metric_time__extract_dow - , subq_24.ds__extract_doy AS metric_time__extract_doy - , subq_24.listing - , subq_24.guest - , subq_24.host - , subq_24.booking__listing - , subq_24.booking__guest - , subq_24.booking__host - , subq_24.is_instant - , subq_24.booking__is_instant - , subq_24.bookings - , subq_24.instant_bookings - , subq_24.booking_value - , subq_24.max_booking_value - , subq_24.min_booking_value - , subq_24.bookers - , subq_24.average_booking_value - , subq_24.referred_bookings - , subq_24.median_booking_value - , subq_24.booking_value_p99 - , subq_24.discrete_booking_value_p99 - , subq_24.approximate_continuous_booking_value_p99 - , subq_24.approximate_discrete_booking_value_p99 + subq_45.ds__day + , subq_45.ds__week + , subq_45.ds__month + , subq_45.ds__quarter + , subq_45.ds__year + , subq_45.ds__extract_year + , subq_45.ds__extract_quarter + , subq_45.ds__extract_month + , subq_45.ds__extract_day + , subq_45.ds__extract_dow + , subq_45.ds__extract_doy + , subq_45.ds_partitioned__day + , subq_45.ds_partitioned__week + , subq_45.ds_partitioned__month + , subq_45.ds_partitioned__quarter + , subq_45.ds_partitioned__year + , subq_45.ds_partitioned__extract_year + , subq_45.ds_partitioned__extract_quarter + , subq_45.ds_partitioned__extract_month + , subq_45.ds_partitioned__extract_day + , subq_45.ds_partitioned__extract_dow + , subq_45.ds_partitioned__extract_doy + , subq_45.paid_at__day + , subq_45.paid_at__week + , subq_45.paid_at__month + , subq_45.paid_at__quarter + , subq_45.paid_at__year + , subq_45.paid_at__extract_year + , subq_45.paid_at__extract_quarter + , subq_45.paid_at__extract_month + , subq_45.paid_at__extract_day + , subq_45.paid_at__extract_dow + , subq_45.paid_at__extract_doy + , subq_45.booking__ds__day + , subq_45.booking__ds__week + , subq_45.booking__ds__month + , subq_45.booking__ds__quarter + , subq_45.booking__ds__year + , subq_45.booking__ds__extract_year + , subq_45.booking__ds__extract_quarter + , subq_45.booking__ds__extract_month + , subq_45.booking__ds__extract_day + , subq_45.booking__ds__extract_dow + , subq_45.booking__ds__extract_doy + , subq_45.booking__ds_partitioned__day + , subq_45.booking__ds_partitioned__week + , subq_45.booking__ds_partitioned__month + , subq_45.booking__ds_partitioned__quarter + , subq_45.booking__ds_partitioned__year + , subq_45.booking__ds_partitioned__extract_year + , subq_45.booking__ds_partitioned__extract_quarter + , subq_45.booking__ds_partitioned__extract_month + , subq_45.booking__ds_partitioned__extract_day + , subq_45.booking__ds_partitioned__extract_dow + , subq_45.booking__ds_partitioned__extract_doy + , subq_45.booking__paid_at__day + , subq_45.booking__paid_at__week + , subq_45.booking__paid_at__month + , subq_45.booking__paid_at__quarter + , subq_45.booking__paid_at__year + , subq_45.booking__paid_at__extract_year + , subq_45.booking__paid_at__extract_quarter + , subq_45.booking__paid_at__extract_month + , subq_45.booking__paid_at__extract_day + , subq_45.booking__paid_at__extract_dow + , subq_45.booking__paid_at__extract_doy + , subq_45.metric_time__day + , subq_45.metric_time__week + , subq_45.metric_time__month + , subq_45.metric_time__quarter + , subq_45.metric_time__year + , subq_45.metric_time__extract_year + , subq_45.metric_time__extract_quarter + , subq_45.metric_time__extract_month + , subq_45.metric_time__extract_day + , subq_45.metric_time__extract_dow + , subq_45.metric_time__extract_doy + , subq_45.listing + , subq_45.guest + , subq_45.host + , subq_45.booking__listing + , subq_45.booking__guest + , subq_45.booking__host + , subq_45.is_instant + , subq_45.booking__is_instant + , subq_45.bookings + , subq_45.instant_bookings + , subq_45.booking_value + , subq_45.max_booking_value + , subq_45.min_booking_value + , subq_45.bookers + , subq_45.average_booking_value + , subq_45.referred_bookings + , subq_45.median_booking_value + , subq_45.booking_value_p99 + , subq_45.discrete_booking_value_p99 + , subq_45.approximate_continuous_booking_value_p99 + , subq_45.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_24 - ) subq_25 - ) subq_26 + subq_44.ds__day + , subq_44.ds__week + , subq_44.ds__month + , subq_44.ds__quarter + , subq_44.ds__year + , subq_44.ds__extract_year + , subq_44.ds__extract_quarter + , subq_44.ds__extract_month + , subq_44.ds__extract_day + , subq_44.ds__extract_dow + , subq_44.ds__extract_doy + , subq_44.ds_partitioned__day + , subq_44.ds_partitioned__week + , subq_44.ds_partitioned__month + , subq_44.ds_partitioned__quarter + , subq_44.ds_partitioned__year + , subq_44.ds_partitioned__extract_year + , subq_44.ds_partitioned__extract_quarter + , subq_44.ds_partitioned__extract_month + , subq_44.ds_partitioned__extract_day + , subq_44.ds_partitioned__extract_dow + , subq_44.ds_partitioned__extract_doy + , subq_44.paid_at__day + , subq_44.paid_at__week + , subq_44.paid_at__month + , subq_44.paid_at__quarter + , subq_44.paid_at__year + , subq_44.paid_at__extract_year + , subq_44.paid_at__extract_quarter + , subq_44.paid_at__extract_month + , subq_44.paid_at__extract_day + , subq_44.paid_at__extract_dow + , subq_44.paid_at__extract_doy + , subq_44.booking__ds__day + , subq_44.booking__ds__week + , subq_44.booking__ds__month + , subq_44.booking__ds__quarter + , subq_44.booking__ds__year + , subq_44.booking__ds__extract_year + , subq_44.booking__ds__extract_quarter + , subq_44.booking__ds__extract_month + , subq_44.booking__ds__extract_day + , subq_44.booking__ds__extract_dow + , subq_44.booking__ds__extract_doy + , subq_44.booking__ds_partitioned__day + , subq_44.booking__ds_partitioned__week + , subq_44.booking__ds_partitioned__month + , subq_44.booking__ds_partitioned__quarter + , subq_44.booking__ds_partitioned__year + , subq_44.booking__ds_partitioned__extract_year + , subq_44.booking__ds_partitioned__extract_quarter + , subq_44.booking__ds_partitioned__extract_month + , subq_44.booking__ds_partitioned__extract_day + , subq_44.booking__ds_partitioned__extract_dow + , subq_44.booking__ds_partitioned__extract_doy + , subq_44.booking__paid_at__day + , subq_44.booking__paid_at__week + , subq_44.booking__paid_at__month + , subq_44.booking__paid_at__quarter + , subq_44.booking__paid_at__year + , subq_44.booking__paid_at__extract_year + , subq_44.booking__paid_at__extract_quarter + , subq_44.booking__paid_at__extract_month + , subq_44.booking__paid_at__extract_day + , subq_44.booking__paid_at__extract_dow + , subq_44.booking__paid_at__extract_doy + , subq_44.ds__day AS metric_time__day + , subq_44.ds__week AS metric_time__week + , subq_44.ds__month AS metric_time__month + , subq_44.ds__quarter AS metric_time__quarter + , subq_44.ds__year AS metric_time__year + , subq_44.ds__extract_year AS metric_time__extract_year + , subq_44.ds__extract_quarter AS metric_time__extract_quarter + , subq_44.ds__extract_month AS metric_time__extract_month + , subq_44.ds__extract_day AS metric_time__extract_day + , subq_44.ds__extract_dow AS metric_time__extract_dow + , subq_44.ds__extract_doy AS metric_time__extract_doy + , subq_44.listing + , subq_44.guest + , subq_44.host + , subq_44.booking__listing + , subq_44.booking__guest + , subq_44.booking__host + , subq_44.is_instant + , subq_44.booking__is_instant + , subq_44.bookings + , subq_44.instant_bookings + , subq_44.booking_value + , subq_44.max_booking_value + , subq_44.min_booking_value + , subq_44.bookers + , subq_44.average_booking_value + , subq_44.referred_bookings + , subq_44.median_booking_value + , subq_44.booking_value_p99 + , subq_44.discrete_booking_value_p99 + , subq_44.approximate_continuous_booking_value_p99 + , subq_44.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_44 + ) subq_45 + WHERE booking__is_instant + ) subq_46 + ) subq_47 WHERE booking__is_instant - ) subq_27 - ) subq_28 - ) subq_29 - ) subq_30 - ) subq_31 -) subq_32 + ) subq_48 + ) subq_49 + ) subq_50 + ) subq_51 + ) subq_52 +) subq_53 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_filters__plan0_optimized.sql index a73bfea928..a0fdc735bd 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_filters__plan0_optimized.sql @@ -8,9 +8,9 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_44.average_booking_value) AS average_booking_value - , MAX(subq_56.bookings) AS bookings - , MAX(subq_63.booking_value) AS booking_value + MAX(subq_66.average_booking_value) AS average_booking_value + , MAX(subq_79.bookings) AS bookings + , MAX(subq_87.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['average_booking_value',] @@ -22,17 +22,34 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - bookings_source_src_28000.is_instant AS booking__is_instant + subq_57.booking__is_instant AS booking__is_instant , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , bookings_source_src_28000.booking_value AS average_booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 + , subq_57.average_booking_value AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] + SELECT + listing + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_55 + WHERE booking__is_instant + ) subq_57 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - bookings_source_src_28000.listing_id = listings_latest_src_28000.listing_id - ) subq_40 + subq_57.listing = listings_latest_src_28000.listing_id + ) subq_62 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_44 + ) subq_66 CROSS JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings',] @@ -44,26 +61,34 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_47.booking__is_instant AS booking__is_instant + subq_70.booking__is_instant AS booking__is_instant , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , subq_47.bookings AS bookings + , subq_70.bookings AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - listing_id AS listing - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_47 + listing + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_68 + WHERE booking__is_instant + ) subq_70 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_47.listing = listings_latest_src_28000.listing_id - ) subq_52 + subq_70.listing = listings_latest_src_28000.listing_id + ) subq_75 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_56 + ) subq_79 CROSS JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value',] @@ -72,15 +97,22 @@ FROM ( SELECT SUM(booking_value) AS booking_value FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'booking__is_instant'] SELECT - is_instant AS booking__is_instant + booking__is_instant , booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_59 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_81 + WHERE booking__is_instant + ) subq_83 WHERE booking__is_instant - ) subq_63 - ) subq_64 -) subq_65 + ) subq_87 + ) subq_88 +) subq_89 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_filters__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_filters__plan0.sql index 5db13f9c09..3b1d93b7d3 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_filters__plan0.sql @@ -8,317 +8,420 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_11.average_booking_value) AS average_booking_value - , MAX(subq_23.bookings) AS bookings - , MAX(subq_30.booking_value) AS booking_value + MAX(subq_30.average_booking_value) AS average_booking_value + , MAX(subq_43.bookings) AS bookings + , MAX(subq_51.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_10.average_booking_value + subq_29.average_booking_value FROM ( -- Aggregate Measures SELECT - AVG(subq_9.average_booking_value) AS average_booking_value + AVG(subq_28.average_booking_value) AS average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value',] SELECT - subq_8.average_booking_value + subq_27.average_booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_7.booking__is_instant - , subq_7.listing__is_lux_latest - , subq_7.average_booking_value + subq_26.booking__is_instant + , subq_26.listing__is_lux_latest + , subq_26.average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_6.booking__is_instant - , subq_6.listing__is_lux_latest - , subq_6.average_booking_value + subq_25.booking__is_instant + , subq_25.listing__is_lux_latest + , subq_25.average_booking_value FROM ( -- Join Standard Outputs SELECT - subq_2.listing AS listing - , subq_2.booking__is_instant AS booking__is_instant - , subq_5.is_lux_latest AS listing__is_lux_latest - , subq_2.average_booking_value AS average_booking_value + subq_21.listing AS listing + , subq_21.booking__is_instant AS booking__is_instant + , subq_24.is_lux_latest AS listing__is_lux_latest + , subq_21.average_booking_value AS average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] SELECT - subq_1.listing - , subq_1.booking__is_instant - , subq_1.average_booking_value + subq_20.listing + , subq_20.booking__is_instant + , subq_20.average_booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE 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.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.booking__paid_at__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.listing - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_19.ds__day + , subq_19.ds__week + , subq_19.ds__month + , subq_19.ds__quarter + , subq_19.ds__year + , subq_19.ds__extract_year + , subq_19.ds__extract_quarter + , subq_19.ds__extract_month + , subq_19.ds__extract_day + , subq_19.ds__extract_dow + , subq_19.ds__extract_doy + , subq_19.ds_partitioned__day + , subq_19.ds_partitioned__week + , subq_19.ds_partitioned__month + , subq_19.ds_partitioned__quarter + , subq_19.ds_partitioned__year + , subq_19.ds_partitioned__extract_year + , subq_19.ds_partitioned__extract_quarter + , subq_19.ds_partitioned__extract_month + , subq_19.ds_partitioned__extract_day + , subq_19.ds_partitioned__extract_dow + , subq_19.ds_partitioned__extract_doy + , subq_19.paid_at__day + , subq_19.paid_at__week + , subq_19.paid_at__month + , subq_19.paid_at__quarter + , subq_19.paid_at__year + , subq_19.paid_at__extract_year + , subq_19.paid_at__extract_quarter + , subq_19.paid_at__extract_month + , subq_19.paid_at__extract_day + , subq_19.paid_at__extract_dow + , subq_19.paid_at__extract_doy + , subq_19.booking__ds__day + , subq_19.booking__ds__week + , subq_19.booking__ds__month + , subq_19.booking__ds__quarter + , subq_19.booking__ds__year + , subq_19.booking__ds__extract_year + , subq_19.booking__ds__extract_quarter + , subq_19.booking__ds__extract_month + , subq_19.booking__ds__extract_day + , subq_19.booking__ds__extract_dow + , subq_19.booking__ds__extract_doy + , subq_19.booking__ds_partitioned__day + , subq_19.booking__ds_partitioned__week + , subq_19.booking__ds_partitioned__month + , subq_19.booking__ds_partitioned__quarter + , subq_19.booking__ds_partitioned__year + , subq_19.booking__ds_partitioned__extract_year + , subq_19.booking__ds_partitioned__extract_quarter + , subq_19.booking__ds_partitioned__extract_month + , subq_19.booking__ds_partitioned__extract_day + , subq_19.booking__ds_partitioned__extract_dow + , subq_19.booking__ds_partitioned__extract_doy + , subq_19.booking__paid_at__day + , subq_19.booking__paid_at__week + , subq_19.booking__paid_at__month + , subq_19.booking__paid_at__quarter + , subq_19.booking__paid_at__year + , subq_19.booking__paid_at__extract_year + , subq_19.booking__paid_at__extract_quarter + , subq_19.booking__paid_at__extract_month + , subq_19.booking__paid_at__extract_day + , subq_19.booking__paid_at__extract_dow + , subq_19.booking__paid_at__extract_doy + , subq_19.metric_time__day + , subq_19.metric_time__week + , subq_19.metric_time__month + , subq_19.metric_time__quarter + , subq_19.metric_time__year + , subq_19.metric_time__extract_year + , subq_19.metric_time__extract_quarter + , subq_19.metric_time__extract_month + , subq_19.metric_time__extract_day + , subq_19.metric_time__extract_dow + , subq_19.metric_time__extract_doy + , subq_19.listing + , subq_19.guest + , subq_19.host + , subq_19.booking__listing + , subq_19.booking__guest + , subq_19.booking__host + , subq_19.is_instant + , subq_19.booking__is_instant + , subq_19.bookings + , subq_19.instant_bookings + , subq_19.booking_value + , subq_19.max_booking_value + , subq_19.min_booking_value + , subq_19.bookers + , subq_19.average_booking_value + , subq_19.referred_bookings + , subq_19.median_booking_value + , subq_19.booking_value_p99 + , subq_19.discrete_booking_value_p99 + , subq_19.approximate_continuous_booking_value_p99 + , subq_19.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + subq_18.ds__day + , subq_18.ds__week + , subq_18.ds__month + , subq_18.ds__quarter + , subq_18.ds__year + , subq_18.ds__extract_year + , subq_18.ds__extract_quarter + , subq_18.ds__extract_month + , subq_18.ds__extract_day + , subq_18.ds__extract_dow + , subq_18.ds__extract_doy + , subq_18.ds_partitioned__day + , subq_18.ds_partitioned__week + , subq_18.ds_partitioned__month + , subq_18.ds_partitioned__quarter + , subq_18.ds_partitioned__year + , subq_18.ds_partitioned__extract_year + , subq_18.ds_partitioned__extract_quarter + , subq_18.ds_partitioned__extract_month + , subq_18.ds_partitioned__extract_day + , subq_18.ds_partitioned__extract_dow + , subq_18.ds_partitioned__extract_doy + , subq_18.paid_at__day + , subq_18.paid_at__week + , subq_18.paid_at__month + , subq_18.paid_at__quarter + , subq_18.paid_at__year + , subq_18.paid_at__extract_year + , subq_18.paid_at__extract_quarter + , subq_18.paid_at__extract_month + , subq_18.paid_at__extract_day + , subq_18.paid_at__extract_dow + , subq_18.paid_at__extract_doy + , subq_18.booking__ds__day + , subq_18.booking__ds__week + , subq_18.booking__ds__month + , subq_18.booking__ds__quarter + , subq_18.booking__ds__year + , subq_18.booking__ds__extract_year + , subq_18.booking__ds__extract_quarter + , subq_18.booking__ds__extract_month + , subq_18.booking__ds__extract_day + , subq_18.booking__ds__extract_dow + , subq_18.booking__ds__extract_doy + , subq_18.booking__ds_partitioned__day + , subq_18.booking__ds_partitioned__week + , subq_18.booking__ds_partitioned__month + , subq_18.booking__ds_partitioned__quarter + , subq_18.booking__ds_partitioned__year + , subq_18.booking__ds_partitioned__extract_year + , subq_18.booking__ds_partitioned__extract_quarter + , subq_18.booking__ds_partitioned__extract_month + , subq_18.booking__ds_partitioned__extract_day + , subq_18.booking__ds_partitioned__extract_dow + , subq_18.booking__ds_partitioned__extract_doy + , subq_18.booking__paid_at__day + , subq_18.booking__paid_at__week + , subq_18.booking__paid_at__month + , subq_18.booking__paid_at__quarter + , subq_18.booking__paid_at__year + , subq_18.booking__paid_at__extract_year + , subq_18.booking__paid_at__extract_quarter + , subq_18.booking__paid_at__extract_month + , subq_18.booking__paid_at__extract_day + , subq_18.booking__paid_at__extract_dow + , subq_18.booking__paid_at__extract_doy + , subq_18.ds__day AS metric_time__day + , subq_18.ds__week AS metric_time__week + , subq_18.ds__month AS metric_time__month + , subq_18.ds__quarter AS metric_time__quarter + , subq_18.ds__year AS metric_time__year + , subq_18.ds__extract_year AS metric_time__extract_year + , subq_18.ds__extract_quarter AS metric_time__extract_quarter + , subq_18.ds__extract_month AS metric_time__extract_month + , subq_18.ds__extract_day AS metric_time__extract_day + , subq_18.ds__extract_dow AS metric_time__extract_dow + , subq_18.ds__extract_doy AS metric_time__extract_doy + , subq_18.listing + , subq_18.guest + , subq_18.host + , subq_18.booking__listing + , subq_18.booking__guest + , subq_18.booking__host + , subq_18.is_instant + , subq_18.booking__is_instant + , subq_18.bookings + , subq_18.instant_bookings + , subq_18.booking_value + , subq_18.max_booking_value + , subq_18.min_booking_value + , subq_18.bookers + , subq_18.average_booking_value + , subq_18.referred_bookings + , subq_18.median_booking_value + , subq_18.booking_value_p99 + , subq_18.discrete_booking_value_p99 + , subq_18.approximate_continuous_booking_value_p99 + , subq_18.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_18 + ) subq_19 + WHERE booking__is_instant + ) subq_20 + ) subq_21 LEFT OUTER JOIN ( -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_4.listing - , subq_4.is_lux_latest + subq_23.listing + , subq_23.is_lux_latest FROM ( -- Metric Time Dimension 'ds' SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing + subq_22.ds__day + , subq_22.ds__week + , subq_22.ds__month + , subq_22.ds__quarter + , subq_22.ds__year + , subq_22.ds__extract_year + , subq_22.ds__extract_quarter + , subq_22.ds__extract_month + , subq_22.ds__extract_day + , subq_22.ds__extract_dow + , subq_22.ds__extract_doy + , subq_22.created_at__day + , subq_22.created_at__week + , subq_22.created_at__month + , subq_22.created_at__quarter + , subq_22.created_at__year + , subq_22.created_at__extract_year + , subq_22.created_at__extract_quarter + , subq_22.created_at__extract_month + , subq_22.created_at__extract_day + , subq_22.created_at__extract_dow + , subq_22.created_at__extract_doy + , subq_22.listing__ds__day + , subq_22.listing__ds__week + , subq_22.listing__ds__month + , subq_22.listing__ds__quarter + , subq_22.listing__ds__year + , subq_22.listing__ds__extract_year + , subq_22.listing__ds__extract_quarter + , subq_22.listing__ds__extract_month + , subq_22.listing__ds__extract_day + , subq_22.listing__ds__extract_dow + , subq_22.listing__ds__extract_doy + , subq_22.listing__created_at__day + , subq_22.listing__created_at__week + , subq_22.listing__created_at__month + , subq_22.listing__created_at__quarter + , subq_22.listing__created_at__year + , subq_22.listing__created_at__extract_year + , subq_22.listing__created_at__extract_quarter + , subq_22.listing__created_at__extract_month + , subq_22.listing__created_at__extract_day + , subq_22.listing__created_at__extract_dow + , subq_22.listing__created_at__extract_doy + , subq_22.ds__day AS metric_time__day + , subq_22.ds__week AS metric_time__week + , subq_22.ds__month AS metric_time__month + , subq_22.ds__quarter AS metric_time__quarter + , subq_22.ds__year AS metric_time__year + , subq_22.ds__extract_year AS metric_time__extract_year + , subq_22.ds__extract_quarter AS metric_time__extract_quarter + , subq_22.ds__extract_month AS metric_time__extract_month + , subq_22.ds__extract_day AS metric_time__extract_day + , subq_22.ds__extract_dow AS metric_time__extract_dow + , subq_22.ds__extract_doy AS metric_time__extract_doy + , subq_22.listing + , subq_22.user + , subq_22.listing__user + , subq_22.country_latest + , subq_22.is_lux_latest + , subq_22.capacity_latest + , subq_22.listing__country_latest + , subq_22.listing__is_lux_latest + , subq_22.listing__capacity_latest + , subq_22.listings + , subq_22.largest_listing + , subq_22.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -379,326 +482,429 @@ FROM ( , listings_latest_src_28000.user_id AS user , listings_latest_src_28000.user_id AS listing__user FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_3 - ) subq_4 - ) subq_5 + ) subq_22 + ) subq_23 + ) subq_24 ON - subq_2.listing = subq_5.listing - ) subq_6 - ) subq_7 + subq_21.listing = subq_24.listing + ) subq_25 + ) subq_26 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_8 - ) subq_9 - ) subq_10 - ) subq_11 + ) subq_27 + ) subq_28 + ) subq_29 + ) subq_30 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_22.bookings + subq_42.bookings FROM ( -- Aggregate Measures SELECT - SUM(subq_21.bookings) AS bookings + SUM(subq_41.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings',] SELECT - subq_20.bookings + subq_40.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_19.booking__is_instant - , subq_19.listing__is_lux_latest - , subq_19.bookings + subq_39.booking__is_instant + , subq_39.listing__is_lux_latest + , subq_39.bookings FROM ( -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_18.booking__is_instant - , subq_18.listing__is_lux_latest - , subq_18.bookings + subq_38.booking__is_instant + , subq_38.listing__is_lux_latest + , subq_38.bookings FROM ( -- Join Standard Outputs SELECT - subq_14.listing AS listing - , subq_14.booking__is_instant AS booking__is_instant - , subq_17.is_lux_latest AS listing__is_lux_latest - , subq_14.bookings AS bookings + subq_34.listing AS listing + , subq_34.booking__is_instant AS booking__is_instant + , subq_37.is_lux_latest AS listing__is_lux_latest + , subq_34.bookings AS bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - subq_13.listing - , subq_13.booking__is_instant - , subq_13.bookings + subq_33.listing + , subq_33.booking__is_instant + , subq_33.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_12.ds__day - , subq_12.ds__week - , subq_12.ds__month - , subq_12.ds__quarter - , subq_12.ds__year - , subq_12.ds__extract_year - , subq_12.ds__extract_quarter - , subq_12.ds__extract_month - , subq_12.ds__extract_day - , subq_12.ds__extract_dow - , subq_12.ds__extract_doy - , subq_12.ds_partitioned__day - , subq_12.ds_partitioned__week - , subq_12.ds_partitioned__month - , subq_12.ds_partitioned__quarter - , subq_12.ds_partitioned__year - , subq_12.ds_partitioned__extract_year - , subq_12.ds_partitioned__extract_quarter - , subq_12.ds_partitioned__extract_month - , subq_12.ds_partitioned__extract_day - , subq_12.ds_partitioned__extract_dow - , subq_12.ds_partitioned__extract_doy - , subq_12.paid_at__day - , subq_12.paid_at__week - , subq_12.paid_at__month - , subq_12.paid_at__quarter - , subq_12.paid_at__year - , subq_12.paid_at__extract_year - , subq_12.paid_at__extract_quarter - , subq_12.paid_at__extract_month - , subq_12.paid_at__extract_day - , subq_12.paid_at__extract_dow - , subq_12.paid_at__extract_doy - , subq_12.booking__ds__day - , subq_12.booking__ds__week - , subq_12.booking__ds__month - , subq_12.booking__ds__quarter - , subq_12.booking__ds__year - , subq_12.booking__ds__extract_year - , subq_12.booking__ds__extract_quarter - , subq_12.booking__ds__extract_month - , subq_12.booking__ds__extract_day - , subq_12.booking__ds__extract_dow - , subq_12.booking__ds__extract_doy - , subq_12.booking__ds_partitioned__day - , subq_12.booking__ds_partitioned__week - , subq_12.booking__ds_partitioned__month - , subq_12.booking__ds_partitioned__quarter - , subq_12.booking__ds_partitioned__year - , subq_12.booking__ds_partitioned__extract_year - , subq_12.booking__ds_partitioned__extract_quarter - , subq_12.booking__ds_partitioned__extract_month - , subq_12.booking__ds_partitioned__extract_day - , subq_12.booking__ds_partitioned__extract_dow - , subq_12.booking__ds_partitioned__extract_doy - , subq_12.booking__paid_at__day - , subq_12.booking__paid_at__week - , subq_12.booking__paid_at__month - , subq_12.booking__paid_at__quarter - , subq_12.booking__paid_at__year - , subq_12.booking__paid_at__extract_year - , subq_12.booking__paid_at__extract_quarter - , subq_12.booking__paid_at__extract_month - , subq_12.booking__paid_at__extract_day - , subq_12.booking__paid_at__extract_dow - , subq_12.booking__paid_at__extract_doy - , subq_12.ds__day AS metric_time__day - , subq_12.ds__week AS metric_time__week - , subq_12.ds__month AS metric_time__month - , subq_12.ds__quarter AS metric_time__quarter - , subq_12.ds__year AS metric_time__year - , subq_12.ds__extract_year AS metric_time__extract_year - , subq_12.ds__extract_quarter AS metric_time__extract_quarter - , subq_12.ds__extract_month AS metric_time__extract_month - , subq_12.ds__extract_day AS metric_time__extract_day - , subq_12.ds__extract_dow AS metric_time__extract_dow - , subq_12.ds__extract_doy AS metric_time__extract_doy - , subq_12.listing - , subq_12.guest - , subq_12.host - , subq_12.booking__listing - , subq_12.booking__guest - , subq_12.booking__host - , subq_12.is_instant - , subq_12.booking__is_instant - , subq_12.bookings - , subq_12.instant_bookings - , subq_12.booking_value - , subq_12.max_booking_value - , subq_12.min_booking_value - , subq_12.bookers - , subq_12.average_booking_value - , subq_12.referred_bookings - , subq_12.median_booking_value - , subq_12.booking_value_p99 - , subq_12.discrete_booking_value_p99 - , subq_12.approximate_continuous_booking_value_p99 - , subq_12.approximate_discrete_booking_value_p99 + subq_32.ds__day + , subq_32.ds__week + , subq_32.ds__month + , subq_32.ds__quarter + , subq_32.ds__year + , subq_32.ds__extract_year + , subq_32.ds__extract_quarter + , subq_32.ds__extract_month + , subq_32.ds__extract_day + , subq_32.ds__extract_dow + , subq_32.ds__extract_doy + , subq_32.ds_partitioned__day + , subq_32.ds_partitioned__week + , subq_32.ds_partitioned__month + , subq_32.ds_partitioned__quarter + , subq_32.ds_partitioned__year + , subq_32.ds_partitioned__extract_year + , subq_32.ds_partitioned__extract_quarter + , subq_32.ds_partitioned__extract_month + , subq_32.ds_partitioned__extract_day + , subq_32.ds_partitioned__extract_dow + , subq_32.ds_partitioned__extract_doy + , subq_32.paid_at__day + , subq_32.paid_at__week + , subq_32.paid_at__month + , subq_32.paid_at__quarter + , subq_32.paid_at__year + , subq_32.paid_at__extract_year + , subq_32.paid_at__extract_quarter + , subq_32.paid_at__extract_month + , subq_32.paid_at__extract_day + , subq_32.paid_at__extract_dow + , subq_32.paid_at__extract_doy + , subq_32.booking__ds__day + , subq_32.booking__ds__week + , subq_32.booking__ds__month + , subq_32.booking__ds__quarter + , subq_32.booking__ds__year + , subq_32.booking__ds__extract_year + , subq_32.booking__ds__extract_quarter + , subq_32.booking__ds__extract_month + , subq_32.booking__ds__extract_day + , subq_32.booking__ds__extract_dow + , subq_32.booking__ds__extract_doy + , subq_32.booking__ds_partitioned__day + , subq_32.booking__ds_partitioned__week + , subq_32.booking__ds_partitioned__month + , subq_32.booking__ds_partitioned__quarter + , subq_32.booking__ds_partitioned__year + , subq_32.booking__ds_partitioned__extract_year + , subq_32.booking__ds_partitioned__extract_quarter + , subq_32.booking__ds_partitioned__extract_month + , subq_32.booking__ds_partitioned__extract_day + , subq_32.booking__ds_partitioned__extract_dow + , subq_32.booking__ds_partitioned__extract_doy + , subq_32.booking__paid_at__day + , subq_32.booking__paid_at__week + , subq_32.booking__paid_at__month + , subq_32.booking__paid_at__quarter + , subq_32.booking__paid_at__year + , subq_32.booking__paid_at__extract_year + , subq_32.booking__paid_at__extract_quarter + , subq_32.booking__paid_at__extract_month + , subq_32.booking__paid_at__extract_day + , subq_32.booking__paid_at__extract_dow + , subq_32.booking__paid_at__extract_doy + , subq_32.metric_time__day + , subq_32.metric_time__week + , subq_32.metric_time__month + , subq_32.metric_time__quarter + , subq_32.metric_time__year + , subq_32.metric_time__extract_year + , subq_32.metric_time__extract_quarter + , subq_32.metric_time__extract_month + , subq_32.metric_time__extract_day + , subq_32.metric_time__extract_dow + , subq_32.metric_time__extract_doy + , subq_32.listing + , subq_32.guest + , subq_32.host + , subq_32.booking__listing + , subq_32.booking__guest + , subq_32.booking__host + , subq_32.is_instant + , subq_32.booking__is_instant + , subq_32.bookings + , subq_32.instant_bookings + , subq_32.booking_value + , subq_32.max_booking_value + , subq_32.min_booking_value + , subq_32.bookers + , subq_32.average_booking_value + , subq_32.referred_bookings + , subq_32.median_booking_value + , subq_32.booking_value_p99 + , subq_32.discrete_booking_value_p99 + , subq_32.approximate_continuous_booking_value_p99 + , subq_32.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_12 - ) subq_13 - ) subq_14 + subq_31.ds__day + , subq_31.ds__week + , subq_31.ds__month + , subq_31.ds__quarter + , subq_31.ds__year + , subq_31.ds__extract_year + , subq_31.ds__extract_quarter + , subq_31.ds__extract_month + , subq_31.ds__extract_day + , subq_31.ds__extract_dow + , subq_31.ds__extract_doy + , subq_31.ds_partitioned__day + , subq_31.ds_partitioned__week + , subq_31.ds_partitioned__month + , subq_31.ds_partitioned__quarter + , subq_31.ds_partitioned__year + , subq_31.ds_partitioned__extract_year + , subq_31.ds_partitioned__extract_quarter + , subq_31.ds_partitioned__extract_month + , subq_31.ds_partitioned__extract_day + , subq_31.ds_partitioned__extract_dow + , subq_31.ds_partitioned__extract_doy + , subq_31.paid_at__day + , subq_31.paid_at__week + , subq_31.paid_at__month + , subq_31.paid_at__quarter + , subq_31.paid_at__year + , subq_31.paid_at__extract_year + , subq_31.paid_at__extract_quarter + , subq_31.paid_at__extract_month + , subq_31.paid_at__extract_day + , subq_31.paid_at__extract_dow + , subq_31.paid_at__extract_doy + , subq_31.booking__ds__day + , subq_31.booking__ds__week + , subq_31.booking__ds__month + , subq_31.booking__ds__quarter + , subq_31.booking__ds__year + , subq_31.booking__ds__extract_year + , subq_31.booking__ds__extract_quarter + , subq_31.booking__ds__extract_month + , subq_31.booking__ds__extract_day + , subq_31.booking__ds__extract_dow + , subq_31.booking__ds__extract_doy + , subq_31.booking__ds_partitioned__day + , subq_31.booking__ds_partitioned__week + , subq_31.booking__ds_partitioned__month + , subq_31.booking__ds_partitioned__quarter + , subq_31.booking__ds_partitioned__year + , subq_31.booking__ds_partitioned__extract_year + , subq_31.booking__ds_partitioned__extract_quarter + , subq_31.booking__ds_partitioned__extract_month + , subq_31.booking__ds_partitioned__extract_day + , subq_31.booking__ds_partitioned__extract_dow + , subq_31.booking__ds_partitioned__extract_doy + , subq_31.booking__paid_at__day + , subq_31.booking__paid_at__week + , subq_31.booking__paid_at__month + , subq_31.booking__paid_at__quarter + , subq_31.booking__paid_at__year + , subq_31.booking__paid_at__extract_year + , subq_31.booking__paid_at__extract_quarter + , subq_31.booking__paid_at__extract_month + , subq_31.booking__paid_at__extract_day + , subq_31.booking__paid_at__extract_dow + , subq_31.booking__paid_at__extract_doy + , subq_31.ds__day AS metric_time__day + , subq_31.ds__week AS metric_time__week + , subq_31.ds__month AS metric_time__month + , subq_31.ds__quarter AS metric_time__quarter + , subq_31.ds__year AS metric_time__year + , subq_31.ds__extract_year AS metric_time__extract_year + , subq_31.ds__extract_quarter AS metric_time__extract_quarter + , subq_31.ds__extract_month AS metric_time__extract_month + , subq_31.ds__extract_day AS metric_time__extract_day + , subq_31.ds__extract_dow AS metric_time__extract_dow + , subq_31.ds__extract_doy AS metric_time__extract_doy + , subq_31.listing + , subq_31.guest + , subq_31.host + , subq_31.booking__listing + , subq_31.booking__guest + , subq_31.booking__host + , subq_31.is_instant + , subq_31.booking__is_instant + , subq_31.bookings + , subq_31.instant_bookings + , subq_31.booking_value + , subq_31.max_booking_value + , subq_31.min_booking_value + , subq_31.bookers + , subq_31.average_booking_value + , subq_31.referred_bookings + , subq_31.median_booking_value + , subq_31.booking_value_p99 + , subq_31.discrete_booking_value_p99 + , subq_31.approximate_continuous_booking_value_p99 + , subq_31.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_31 + ) subq_32 + WHERE booking__is_instant + ) subq_33 + ) subq_34 LEFT OUTER JOIN ( -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_16.listing - , subq_16.is_lux_latest + subq_36.listing + , subq_36.is_lux_latest FROM ( -- Metric Time Dimension 'ds' SELECT - subq_15.ds__day - , subq_15.ds__week - , subq_15.ds__month - , subq_15.ds__quarter - , subq_15.ds__year - , subq_15.ds__extract_year - , subq_15.ds__extract_quarter - , subq_15.ds__extract_month - , subq_15.ds__extract_day - , subq_15.ds__extract_dow - , subq_15.ds__extract_doy - , subq_15.created_at__day - , subq_15.created_at__week - , subq_15.created_at__month - , subq_15.created_at__quarter - , subq_15.created_at__year - , subq_15.created_at__extract_year - , subq_15.created_at__extract_quarter - , subq_15.created_at__extract_month - , subq_15.created_at__extract_day - , subq_15.created_at__extract_dow - , subq_15.created_at__extract_doy - , subq_15.listing__ds__day - , subq_15.listing__ds__week - , subq_15.listing__ds__month - , subq_15.listing__ds__quarter - , subq_15.listing__ds__year - , subq_15.listing__ds__extract_year - , subq_15.listing__ds__extract_quarter - , subq_15.listing__ds__extract_month - , subq_15.listing__ds__extract_day - , subq_15.listing__ds__extract_dow - , subq_15.listing__ds__extract_doy - , subq_15.listing__created_at__day - , subq_15.listing__created_at__week - , subq_15.listing__created_at__month - , subq_15.listing__created_at__quarter - , subq_15.listing__created_at__year - , subq_15.listing__created_at__extract_year - , subq_15.listing__created_at__extract_quarter - , subq_15.listing__created_at__extract_month - , subq_15.listing__created_at__extract_day - , subq_15.listing__created_at__extract_dow - , subq_15.listing__created_at__extract_doy - , subq_15.ds__day AS metric_time__day - , subq_15.ds__week AS metric_time__week - , subq_15.ds__month AS metric_time__month - , subq_15.ds__quarter AS metric_time__quarter - , subq_15.ds__year AS metric_time__year - , subq_15.ds__extract_year AS metric_time__extract_year - , subq_15.ds__extract_quarter AS metric_time__extract_quarter - , subq_15.ds__extract_month AS metric_time__extract_month - , subq_15.ds__extract_day AS metric_time__extract_day - , subq_15.ds__extract_dow AS metric_time__extract_dow - , subq_15.ds__extract_doy AS metric_time__extract_doy - , subq_15.listing - , subq_15.user - , subq_15.listing__user - , subq_15.country_latest - , subq_15.is_lux_latest - , subq_15.capacity_latest - , subq_15.listing__country_latest - , subq_15.listing__is_lux_latest - , subq_15.listing__capacity_latest - , subq_15.listings - , subq_15.largest_listing - , subq_15.smallest_listing + subq_35.ds__day + , subq_35.ds__week + , subq_35.ds__month + , subq_35.ds__quarter + , subq_35.ds__year + , subq_35.ds__extract_year + , subq_35.ds__extract_quarter + , subq_35.ds__extract_month + , subq_35.ds__extract_day + , subq_35.ds__extract_dow + , subq_35.ds__extract_doy + , subq_35.created_at__day + , subq_35.created_at__week + , subq_35.created_at__month + , subq_35.created_at__quarter + , subq_35.created_at__year + , subq_35.created_at__extract_year + , subq_35.created_at__extract_quarter + , subq_35.created_at__extract_month + , subq_35.created_at__extract_day + , subq_35.created_at__extract_dow + , subq_35.created_at__extract_doy + , subq_35.listing__ds__day + , subq_35.listing__ds__week + , subq_35.listing__ds__month + , subq_35.listing__ds__quarter + , subq_35.listing__ds__year + , subq_35.listing__ds__extract_year + , subq_35.listing__ds__extract_quarter + , subq_35.listing__ds__extract_month + , subq_35.listing__ds__extract_day + , subq_35.listing__ds__extract_dow + , subq_35.listing__ds__extract_doy + , subq_35.listing__created_at__day + , subq_35.listing__created_at__week + , subq_35.listing__created_at__month + , subq_35.listing__created_at__quarter + , subq_35.listing__created_at__year + , subq_35.listing__created_at__extract_year + , subq_35.listing__created_at__extract_quarter + , subq_35.listing__created_at__extract_month + , subq_35.listing__created_at__extract_day + , subq_35.listing__created_at__extract_dow + , subq_35.listing__created_at__extract_doy + , subq_35.ds__day AS metric_time__day + , subq_35.ds__week AS metric_time__week + , subq_35.ds__month AS metric_time__month + , subq_35.ds__quarter AS metric_time__quarter + , subq_35.ds__year AS metric_time__year + , subq_35.ds__extract_year AS metric_time__extract_year + , subq_35.ds__extract_quarter AS metric_time__extract_quarter + , subq_35.ds__extract_month AS metric_time__extract_month + , subq_35.ds__extract_day AS metric_time__extract_day + , subq_35.ds__extract_dow AS metric_time__extract_dow + , subq_35.ds__extract_doy AS metric_time__extract_doy + , subq_35.listing + , subq_35.user + , subq_35.listing__user + , subq_35.country_latest + , subq_35.is_lux_latest + , subq_35.capacity_latest + , subq_35.listing__country_latest + , subq_35.listing__is_lux_latest + , subq_35.listing__capacity_latest + , subq_35.listings + , subq_35.largest_listing + , subq_35.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -759,240 +965,343 @@ FROM ( , listings_latest_src_28000.user_id AS user , listings_latest_src_28000.user_id AS listing__user FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_15 - ) subq_16 - ) subq_17 + ) subq_35 + ) subq_36 + ) subq_37 ON - subq_14.listing = subq_17.listing - ) subq_18 - ) subq_19 + subq_34.listing = subq_37.listing + ) subq_38 + ) subq_39 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_20 - ) subq_21 - ) subq_22 - ) subq_23 + ) subq_40 + ) subq_41 + ) subq_42 + ) subq_43 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_29.booking_value + subq_50.booking_value FROM ( -- Aggregate Measures SELECT - SUM(subq_28.booking_value) AS booking_value + SUM(subq_49.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value',] SELECT - subq_27.booking_value + subq_48.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_26.booking__is_instant - , subq_26.booking_value + subq_47.booking__is_instant + , subq_47.booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__is_instant'] SELECT - subq_25.booking__is_instant - , subq_25.booking_value + subq_46.booking__is_instant + , subq_46.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_24.ds__day - , subq_24.ds__week - , subq_24.ds__month - , subq_24.ds__quarter - , subq_24.ds__year - , subq_24.ds__extract_year - , subq_24.ds__extract_quarter - , subq_24.ds__extract_month - , subq_24.ds__extract_day - , subq_24.ds__extract_dow - , subq_24.ds__extract_doy - , subq_24.ds_partitioned__day - , subq_24.ds_partitioned__week - , subq_24.ds_partitioned__month - , subq_24.ds_partitioned__quarter - , subq_24.ds_partitioned__year - , subq_24.ds_partitioned__extract_year - , subq_24.ds_partitioned__extract_quarter - , subq_24.ds_partitioned__extract_month - , subq_24.ds_partitioned__extract_day - , subq_24.ds_partitioned__extract_dow - , subq_24.ds_partitioned__extract_doy - , subq_24.paid_at__day - , subq_24.paid_at__week - , subq_24.paid_at__month - , subq_24.paid_at__quarter - , subq_24.paid_at__year - , subq_24.paid_at__extract_year - , subq_24.paid_at__extract_quarter - , subq_24.paid_at__extract_month - , subq_24.paid_at__extract_day - , subq_24.paid_at__extract_dow - , subq_24.paid_at__extract_doy - , subq_24.booking__ds__day - , subq_24.booking__ds__week - , subq_24.booking__ds__month - , subq_24.booking__ds__quarter - , subq_24.booking__ds__year - , subq_24.booking__ds__extract_year - , subq_24.booking__ds__extract_quarter - , subq_24.booking__ds__extract_month - , subq_24.booking__ds__extract_day - , subq_24.booking__ds__extract_dow - , subq_24.booking__ds__extract_doy - , subq_24.booking__ds_partitioned__day - , subq_24.booking__ds_partitioned__week - , subq_24.booking__ds_partitioned__month - , subq_24.booking__ds_partitioned__quarter - , subq_24.booking__ds_partitioned__year - , subq_24.booking__ds_partitioned__extract_year - , subq_24.booking__ds_partitioned__extract_quarter - , subq_24.booking__ds_partitioned__extract_month - , subq_24.booking__ds_partitioned__extract_day - , subq_24.booking__ds_partitioned__extract_dow - , subq_24.booking__ds_partitioned__extract_doy - , subq_24.booking__paid_at__day - , subq_24.booking__paid_at__week - , subq_24.booking__paid_at__month - , subq_24.booking__paid_at__quarter - , subq_24.booking__paid_at__year - , subq_24.booking__paid_at__extract_year - , subq_24.booking__paid_at__extract_quarter - , subq_24.booking__paid_at__extract_month - , subq_24.booking__paid_at__extract_day - , subq_24.booking__paid_at__extract_dow - , subq_24.booking__paid_at__extract_doy - , subq_24.ds__day AS metric_time__day - , subq_24.ds__week AS metric_time__week - , subq_24.ds__month AS metric_time__month - , subq_24.ds__quarter AS metric_time__quarter - , subq_24.ds__year AS metric_time__year - , subq_24.ds__extract_year AS metric_time__extract_year - , subq_24.ds__extract_quarter AS metric_time__extract_quarter - , subq_24.ds__extract_month AS metric_time__extract_month - , subq_24.ds__extract_day AS metric_time__extract_day - , subq_24.ds__extract_dow AS metric_time__extract_dow - , subq_24.ds__extract_doy AS metric_time__extract_doy - , subq_24.listing - , subq_24.guest - , subq_24.host - , subq_24.booking__listing - , subq_24.booking__guest - , subq_24.booking__host - , subq_24.is_instant - , subq_24.booking__is_instant - , subq_24.bookings - , subq_24.instant_bookings - , subq_24.booking_value - , subq_24.max_booking_value - , subq_24.min_booking_value - , subq_24.bookers - , subq_24.average_booking_value - , subq_24.referred_bookings - , subq_24.median_booking_value - , subq_24.booking_value_p99 - , subq_24.discrete_booking_value_p99 - , subq_24.approximate_continuous_booking_value_p99 - , subq_24.approximate_discrete_booking_value_p99 + subq_45.ds__day + , subq_45.ds__week + , subq_45.ds__month + , subq_45.ds__quarter + , subq_45.ds__year + , subq_45.ds__extract_year + , subq_45.ds__extract_quarter + , subq_45.ds__extract_month + , subq_45.ds__extract_day + , subq_45.ds__extract_dow + , subq_45.ds__extract_doy + , subq_45.ds_partitioned__day + , subq_45.ds_partitioned__week + , subq_45.ds_partitioned__month + , subq_45.ds_partitioned__quarter + , subq_45.ds_partitioned__year + , subq_45.ds_partitioned__extract_year + , subq_45.ds_partitioned__extract_quarter + , subq_45.ds_partitioned__extract_month + , subq_45.ds_partitioned__extract_day + , subq_45.ds_partitioned__extract_dow + , subq_45.ds_partitioned__extract_doy + , subq_45.paid_at__day + , subq_45.paid_at__week + , subq_45.paid_at__month + , subq_45.paid_at__quarter + , subq_45.paid_at__year + , subq_45.paid_at__extract_year + , subq_45.paid_at__extract_quarter + , subq_45.paid_at__extract_month + , subq_45.paid_at__extract_day + , subq_45.paid_at__extract_dow + , subq_45.paid_at__extract_doy + , subq_45.booking__ds__day + , subq_45.booking__ds__week + , subq_45.booking__ds__month + , subq_45.booking__ds__quarter + , subq_45.booking__ds__year + , subq_45.booking__ds__extract_year + , subq_45.booking__ds__extract_quarter + , subq_45.booking__ds__extract_month + , subq_45.booking__ds__extract_day + , subq_45.booking__ds__extract_dow + , subq_45.booking__ds__extract_doy + , subq_45.booking__ds_partitioned__day + , subq_45.booking__ds_partitioned__week + , subq_45.booking__ds_partitioned__month + , subq_45.booking__ds_partitioned__quarter + , subq_45.booking__ds_partitioned__year + , subq_45.booking__ds_partitioned__extract_year + , subq_45.booking__ds_partitioned__extract_quarter + , subq_45.booking__ds_partitioned__extract_month + , subq_45.booking__ds_partitioned__extract_day + , subq_45.booking__ds_partitioned__extract_dow + , subq_45.booking__ds_partitioned__extract_doy + , subq_45.booking__paid_at__day + , subq_45.booking__paid_at__week + , subq_45.booking__paid_at__month + , subq_45.booking__paid_at__quarter + , subq_45.booking__paid_at__year + , subq_45.booking__paid_at__extract_year + , subq_45.booking__paid_at__extract_quarter + , subq_45.booking__paid_at__extract_month + , subq_45.booking__paid_at__extract_day + , subq_45.booking__paid_at__extract_dow + , subq_45.booking__paid_at__extract_doy + , subq_45.metric_time__day + , subq_45.metric_time__week + , subq_45.metric_time__month + , subq_45.metric_time__quarter + , subq_45.metric_time__year + , subq_45.metric_time__extract_year + , subq_45.metric_time__extract_quarter + , subq_45.metric_time__extract_month + , subq_45.metric_time__extract_day + , subq_45.metric_time__extract_dow + , subq_45.metric_time__extract_doy + , subq_45.listing + , subq_45.guest + , subq_45.host + , subq_45.booking__listing + , subq_45.booking__guest + , subq_45.booking__host + , subq_45.is_instant + , subq_45.booking__is_instant + , subq_45.bookings + , subq_45.instant_bookings + , subq_45.booking_value + , subq_45.max_booking_value + , subq_45.min_booking_value + , subq_45.bookers + , subq_45.average_booking_value + , subq_45.referred_bookings + , subq_45.median_booking_value + , subq_45.booking_value_p99 + , subq_45.discrete_booking_value_p99 + , subq_45.approximate_continuous_booking_value_p99 + , subq_45.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_24 - ) subq_25 - ) subq_26 + subq_44.ds__day + , subq_44.ds__week + , subq_44.ds__month + , subq_44.ds__quarter + , subq_44.ds__year + , subq_44.ds__extract_year + , subq_44.ds__extract_quarter + , subq_44.ds__extract_month + , subq_44.ds__extract_day + , subq_44.ds__extract_dow + , subq_44.ds__extract_doy + , subq_44.ds_partitioned__day + , subq_44.ds_partitioned__week + , subq_44.ds_partitioned__month + , subq_44.ds_partitioned__quarter + , subq_44.ds_partitioned__year + , subq_44.ds_partitioned__extract_year + , subq_44.ds_partitioned__extract_quarter + , subq_44.ds_partitioned__extract_month + , subq_44.ds_partitioned__extract_day + , subq_44.ds_partitioned__extract_dow + , subq_44.ds_partitioned__extract_doy + , subq_44.paid_at__day + , subq_44.paid_at__week + , subq_44.paid_at__month + , subq_44.paid_at__quarter + , subq_44.paid_at__year + , subq_44.paid_at__extract_year + , subq_44.paid_at__extract_quarter + , subq_44.paid_at__extract_month + , subq_44.paid_at__extract_day + , subq_44.paid_at__extract_dow + , subq_44.paid_at__extract_doy + , subq_44.booking__ds__day + , subq_44.booking__ds__week + , subq_44.booking__ds__month + , subq_44.booking__ds__quarter + , subq_44.booking__ds__year + , subq_44.booking__ds__extract_year + , subq_44.booking__ds__extract_quarter + , subq_44.booking__ds__extract_month + , subq_44.booking__ds__extract_day + , subq_44.booking__ds__extract_dow + , subq_44.booking__ds__extract_doy + , subq_44.booking__ds_partitioned__day + , subq_44.booking__ds_partitioned__week + , subq_44.booking__ds_partitioned__month + , subq_44.booking__ds_partitioned__quarter + , subq_44.booking__ds_partitioned__year + , subq_44.booking__ds_partitioned__extract_year + , subq_44.booking__ds_partitioned__extract_quarter + , subq_44.booking__ds_partitioned__extract_month + , subq_44.booking__ds_partitioned__extract_day + , subq_44.booking__ds_partitioned__extract_dow + , subq_44.booking__ds_partitioned__extract_doy + , subq_44.booking__paid_at__day + , subq_44.booking__paid_at__week + , subq_44.booking__paid_at__month + , subq_44.booking__paid_at__quarter + , subq_44.booking__paid_at__year + , subq_44.booking__paid_at__extract_year + , subq_44.booking__paid_at__extract_quarter + , subq_44.booking__paid_at__extract_month + , subq_44.booking__paid_at__extract_day + , subq_44.booking__paid_at__extract_dow + , subq_44.booking__paid_at__extract_doy + , subq_44.ds__day AS metric_time__day + , subq_44.ds__week AS metric_time__week + , subq_44.ds__month AS metric_time__month + , subq_44.ds__quarter AS metric_time__quarter + , subq_44.ds__year AS metric_time__year + , subq_44.ds__extract_year AS metric_time__extract_year + , subq_44.ds__extract_quarter AS metric_time__extract_quarter + , subq_44.ds__extract_month AS metric_time__extract_month + , subq_44.ds__extract_day AS metric_time__extract_day + , subq_44.ds__extract_dow AS metric_time__extract_dow + , subq_44.ds__extract_doy AS metric_time__extract_doy + , subq_44.listing + , subq_44.guest + , subq_44.host + , subq_44.booking__listing + , subq_44.booking__guest + , subq_44.booking__host + , subq_44.is_instant + , subq_44.booking__is_instant + , subq_44.bookings + , subq_44.instant_bookings + , subq_44.booking_value + , subq_44.max_booking_value + , subq_44.min_booking_value + , subq_44.bookers + , subq_44.average_booking_value + , subq_44.referred_bookings + , subq_44.median_booking_value + , subq_44.booking_value_p99 + , subq_44.discrete_booking_value_p99 + , subq_44.approximate_continuous_booking_value_p99 + , subq_44.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_44 + ) subq_45 + WHERE booking__is_instant + ) subq_46 + ) subq_47 WHERE booking__is_instant - ) subq_27 - ) subq_28 - ) subq_29 - ) subq_30 - ) subq_31 -) subq_32 + ) subq_48 + ) subq_49 + ) subq_50 + ) subq_51 + ) subq_52 +) subq_53 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_filters__plan0_optimized.sql index a73bfea928..a0fdc735bd 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_filters__plan0_optimized.sql @@ -8,9 +8,9 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_44.average_booking_value) AS average_booking_value - , MAX(subq_56.bookings) AS bookings - , MAX(subq_63.booking_value) AS booking_value + MAX(subq_66.average_booking_value) AS average_booking_value + , MAX(subq_79.bookings) AS bookings + , MAX(subq_87.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['average_booking_value',] @@ -22,17 +22,34 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - bookings_source_src_28000.is_instant AS booking__is_instant + subq_57.booking__is_instant AS booking__is_instant , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , bookings_source_src_28000.booking_value AS average_booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 + , subq_57.average_booking_value AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] + SELECT + listing + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_55 + WHERE booking__is_instant + ) subq_57 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - bookings_source_src_28000.listing_id = listings_latest_src_28000.listing_id - ) subq_40 + subq_57.listing = listings_latest_src_28000.listing_id + ) subq_62 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_44 + ) subq_66 CROSS JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings',] @@ -44,26 +61,34 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_47.booking__is_instant AS booking__is_instant + subq_70.booking__is_instant AS booking__is_instant , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , subq_47.bookings AS bookings + , subq_70.bookings AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - listing_id AS listing - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_47 + listing + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_68 + WHERE booking__is_instant + ) subq_70 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_47.listing = listings_latest_src_28000.listing_id - ) subq_52 + subq_70.listing = listings_latest_src_28000.listing_id + ) subq_75 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_56 + ) subq_79 CROSS JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value',] @@ -72,15 +97,22 @@ FROM ( SELECT SUM(booking_value) AS booking_value FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'booking__is_instant'] SELECT - is_instant AS booking__is_instant + booking__is_instant , booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_59 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_81 + WHERE booking__is_instant + ) subq_83 WHERE booking__is_instant - ) subq_63 - ) subq_64 -) subq_65 + ) subq_87 + ) subq_88 +) subq_89 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_filters__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_filters__plan0.sql index ed681431ce..bc02f3bba4 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_filters__plan0.sql @@ -8,317 +8,420 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_11.average_booking_value) AS average_booking_value - , MAX(subq_23.bookings) AS bookings - , MAX(subq_30.booking_value) AS booking_value + MAX(subq_30.average_booking_value) AS average_booking_value + , MAX(subq_43.bookings) AS bookings + , MAX(subq_51.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_10.average_booking_value + subq_29.average_booking_value FROM ( -- Aggregate Measures SELECT - AVG(subq_9.average_booking_value) AS average_booking_value + AVG(subq_28.average_booking_value) AS average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value',] SELECT - subq_8.average_booking_value + subq_27.average_booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_7.booking__is_instant - , subq_7.listing__is_lux_latest - , subq_7.average_booking_value + subq_26.booking__is_instant + , subq_26.listing__is_lux_latest + , subq_26.average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_6.booking__is_instant - , subq_6.listing__is_lux_latest - , subq_6.average_booking_value + subq_25.booking__is_instant + , subq_25.listing__is_lux_latest + , subq_25.average_booking_value FROM ( -- Join Standard Outputs SELECT - subq_2.listing AS listing - , subq_2.booking__is_instant AS booking__is_instant - , subq_5.is_lux_latest AS listing__is_lux_latest - , subq_2.average_booking_value AS average_booking_value + subq_21.listing AS listing + , subq_21.booking__is_instant AS booking__is_instant + , subq_24.is_lux_latest AS listing__is_lux_latest + , subq_21.average_booking_value AS average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] SELECT - subq_1.listing - , subq_1.booking__is_instant - , subq_1.average_booking_value + subq_20.listing + , subq_20.booking__is_instant + , subq_20.average_booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE 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.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.booking__paid_at__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.listing - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_19.ds__day + , subq_19.ds__week + , subq_19.ds__month + , subq_19.ds__quarter + , subq_19.ds__year + , subq_19.ds__extract_year + , subq_19.ds__extract_quarter + , subq_19.ds__extract_month + , subq_19.ds__extract_day + , subq_19.ds__extract_dow + , subq_19.ds__extract_doy + , subq_19.ds_partitioned__day + , subq_19.ds_partitioned__week + , subq_19.ds_partitioned__month + , subq_19.ds_partitioned__quarter + , subq_19.ds_partitioned__year + , subq_19.ds_partitioned__extract_year + , subq_19.ds_partitioned__extract_quarter + , subq_19.ds_partitioned__extract_month + , subq_19.ds_partitioned__extract_day + , subq_19.ds_partitioned__extract_dow + , subq_19.ds_partitioned__extract_doy + , subq_19.paid_at__day + , subq_19.paid_at__week + , subq_19.paid_at__month + , subq_19.paid_at__quarter + , subq_19.paid_at__year + , subq_19.paid_at__extract_year + , subq_19.paid_at__extract_quarter + , subq_19.paid_at__extract_month + , subq_19.paid_at__extract_day + , subq_19.paid_at__extract_dow + , subq_19.paid_at__extract_doy + , subq_19.booking__ds__day + , subq_19.booking__ds__week + , subq_19.booking__ds__month + , subq_19.booking__ds__quarter + , subq_19.booking__ds__year + , subq_19.booking__ds__extract_year + , subq_19.booking__ds__extract_quarter + , subq_19.booking__ds__extract_month + , subq_19.booking__ds__extract_day + , subq_19.booking__ds__extract_dow + , subq_19.booking__ds__extract_doy + , subq_19.booking__ds_partitioned__day + , subq_19.booking__ds_partitioned__week + , subq_19.booking__ds_partitioned__month + , subq_19.booking__ds_partitioned__quarter + , subq_19.booking__ds_partitioned__year + , subq_19.booking__ds_partitioned__extract_year + , subq_19.booking__ds_partitioned__extract_quarter + , subq_19.booking__ds_partitioned__extract_month + , subq_19.booking__ds_partitioned__extract_day + , subq_19.booking__ds_partitioned__extract_dow + , subq_19.booking__ds_partitioned__extract_doy + , subq_19.booking__paid_at__day + , subq_19.booking__paid_at__week + , subq_19.booking__paid_at__month + , subq_19.booking__paid_at__quarter + , subq_19.booking__paid_at__year + , subq_19.booking__paid_at__extract_year + , subq_19.booking__paid_at__extract_quarter + , subq_19.booking__paid_at__extract_month + , subq_19.booking__paid_at__extract_day + , subq_19.booking__paid_at__extract_dow + , subq_19.booking__paid_at__extract_doy + , subq_19.metric_time__day + , subq_19.metric_time__week + , subq_19.metric_time__month + , subq_19.metric_time__quarter + , subq_19.metric_time__year + , subq_19.metric_time__extract_year + , subq_19.metric_time__extract_quarter + , subq_19.metric_time__extract_month + , subq_19.metric_time__extract_day + , subq_19.metric_time__extract_dow + , subq_19.metric_time__extract_doy + , subq_19.listing + , subq_19.guest + , subq_19.host + , subq_19.booking__listing + , subq_19.booking__guest + , subq_19.booking__host + , subq_19.is_instant + , subq_19.booking__is_instant + , subq_19.bookings + , subq_19.instant_bookings + , subq_19.booking_value + , subq_19.max_booking_value + , subq_19.min_booking_value + , subq_19.bookers + , subq_19.average_booking_value + , subq_19.referred_bookings + , subq_19.median_booking_value + , subq_19.booking_value_p99 + , subq_19.discrete_booking_value_p99 + , subq_19.approximate_continuous_booking_value_p99 + , subq_19.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + subq_18.ds__day + , subq_18.ds__week + , subq_18.ds__month + , subq_18.ds__quarter + , subq_18.ds__year + , subq_18.ds__extract_year + , subq_18.ds__extract_quarter + , subq_18.ds__extract_month + , subq_18.ds__extract_day + , subq_18.ds__extract_dow + , subq_18.ds__extract_doy + , subq_18.ds_partitioned__day + , subq_18.ds_partitioned__week + , subq_18.ds_partitioned__month + , subq_18.ds_partitioned__quarter + , subq_18.ds_partitioned__year + , subq_18.ds_partitioned__extract_year + , subq_18.ds_partitioned__extract_quarter + , subq_18.ds_partitioned__extract_month + , subq_18.ds_partitioned__extract_day + , subq_18.ds_partitioned__extract_dow + , subq_18.ds_partitioned__extract_doy + , subq_18.paid_at__day + , subq_18.paid_at__week + , subq_18.paid_at__month + , subq_18.paid_at__quarter + , subq_18.paid_at__year + , subq_18.paid_at__extract_year + , subq_18.paid_at__extract_quarter + , subq_18.paid_at__extract_month + , subq_18.paid_at__extract_day + , subq_18.paid_at__extract_dow + , subq_18.paid_at__extract_doy + , subq_18.booking__ds__day + , subq_18.booking__ds__week + , subq_18.booking__ds__month + , subq_18.booking__ds__quarter + , subq_18.booking__ds__year + , subq_18.booking__ds__extract_year + , subq_18.booking__ds__extract_quarter + , subq_18.booking__ds__extract_month + , subq_18.booking__ds__extract_day + , subq_18.booking__ds__extract_dow + , subq_18.booking__ds__extract_doy + , subq_18.booking__ds_partitioned__day + , subq_18.booking__ds_partitioned__week + , subq_18.booking__ds_partitioned__month + , subq_18.booking__ds_partitioned__quarter + , subq_18.booking__ds_partitioned__year + , subq_18.booking__ds_partitioned__extract_year + , subq_18.booking__ds_partitioned__extract_quarter + , subq_18.booking__ds_partitioned__extract_month + , subq_18.booking__ds_partitioned__extract_day + , subq_18.booking__ds_partitioned__extract_dow + , subq_18.booking__ds_partitioned__extract_doy + , subq_18.booking__paid_at__day + , subq_18.booking__paid_at__week + , subq_18.booking__paid_at__month + , subq_18.booking__paid_at__quarter + , subq_18.booking__paid_at__year + , subq_18.booking__paid_at__extract_year + , subq_18.booking__paid_at__extract_quarter + , subq_18.booking__paid_at__extract_month + , subq_18.booking__paid_at__extract_day + , subq_18.booking__paid_at__extract_dow + , subq_18.booking__paid_at__extract_doy + , subq_18.ds__day AS metric_time__day + , subq_18.ds__week AS metric_time__week + , subq_18.ds__month AS metric_time__month + , subq_18.ds__quarter AS metric_time__quarter + , subq_18.ds__year AS metric_time__year + , subq_18.ds__extract_year AS metric_time__extract_year + , subq_18.ds__extract_quarter AS metric_time__extract_quarter + , subq_18.ds__extract_month AS metric_time__extract_month + , subq_18.ds__extract_day AS metric_time__extract_day + , subq_18.ds__extract_dow AS metric_time__extract_dow + , subq_18.ds__extract_doy AS metric_time__extract_doy + , subq_18.listing + , subq_18.guest + , subq_18.host + , subq_18.booking__listing + , subq_18.booking__guest + , subq_18.booking__host + , subq_18.is_instant + , subq_18.booking__is_instant + , subq_18.bookings + , subq_18.instant_bookings + , subq_18.booking_value + , subq_18.max_booking_value + , subq_18.min_booking_value + , subq_18.bookers + , subq_18.average_booking_value + , subq_18.referred_bookings + , subq_18.median_booking_value + , subq_18.booking_value_p99 + , subq_18.discrete_booking_value_p99 + , subq_18.approximate_continuous_booking_value_p99 + , subq_18.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_18 + ) subq_19 + WHERE booking__is_instant + ) subq_20 + ) subq_21 LEFT OUTER JOIN ( -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_4.listing - , subq_4.is_lux_latest + subq_23.listing + , subq_23.is_lux_latest FROM ( -- Metric Time Dimension 'ds' SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing + subq_22.ds__day + , subq_22.ds__week + , subq_22.ds__month + , subq_22.ds__quarter + , subq_22.ds__year + , subq_22.ds__extract_year + , subq_22.ds__extract_quarter + , subq_22.ds__extract_month + , subq_22.ds__extract_day + , subq_22.ds__extract_dow + , subq_22.ds__extract_doy + , subq_22.created_at__day + , subq_22.created_at__week + , subq_22.created_at__month + , subq_22.created_at__quarter + , subq_22.created_at__year + , subq_22.created_at__extract_year + , subq_22.created_at__extract_quarter + , subq_22.created_at__extract_month + , subq_22.created_at__extract_day + , subq_22.created_at__extract_dow + , subq_22.created_at__extract_doy + , subq_22.listing__ds__day + , subq_22.listing__ds__week + , subq_22.listing__ds__month + , subq_22.listing__ds__quarter + , subq_22.listing__ds__year + , subq_22.listing__ds__extract_year + , subq_22.listing__ds__extract_quarter + , subq_22.listing__ds__extract_month + , subq_22.listing__ds__extract_day + , subq_22.listing__ds__extract_dow + , subq_22.listing__ds__extract_doy + , subq_22.listing__created_at__day + , subq_22.listing__created_at__week + , subq_22.listing__created_at__month + , subq_22.listing__created_at__quarter + , subq_22.listing__created_at__year + , subq_22.listing__created_at__extract_year + , subq_22.listing__created_at__extract_quarter + , subq_22.listing__created_at__extract_month + , subq_22.listing__created_at__extract_day + , subq_22.listing__created_at__extract_dow + , subq_22.listing__created_at__extract_doy + , subq_22.ds__day AS metric_time__day + , subq_22.ds__week AS metric_time__week + , subq_22.ds__month AS metric_time__month + , subq_22.ds__quarter AS metric_time__quarter + , subq_22.ds__year AS metric_time__year + , subq_22.ds__extract_year AS metric_time__extract_year + , subq_22.ds__extract_quarter AS metric_time__extract_quarter + , subq_22.ds__extract_month AS metric_time__extract_month + , subq_22.ds__extract_day AS metric_time__extract_day + , subq_22.ds__extract_dow AS metric_time__extract_dow + , subq_22.ds__extract_doy AS metric_time__extract_doy + , subq_22.listing + , subq_22.user + , subq_22.listing__user + , subq_22.country_latest + , subq_22.is_lux_latest + , subq_22.capacity_latest + , subq_22.listing__country_latest + , subq_22.listing__is_lux_latest + , subq_22.listing__capacity_latest + , subq_22.listings + , subq_22.largest_listing + , subq_22.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -379,326 +482,429 @@ FROM ( , listings_latest_src_28000.user_id AS user , listings_latest_src_28000.user_id AS listing__user FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_3 - ) subq_4 - ) subq_5 + ) subq_22 + ) subq_23 + ) subq_24 ON - subq_2.listing = subq_5.listing - ) subq_6 - ) subq_7 + subq_21.listing = subq_24.listing + ) subq_25 + ) subq_26 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_8 - ) subq_9 - ) subq_10 - ) subq_11 + ) subq_27 + ) subq_28 + ) subq_29 + ) subq_30 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_22.bookings + subq_42.bookings FROM ( -- Aggregate Measures SELECT - SUM(subq_21.bookings) AS bookings + SUM(subq_41.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings',] SELECT - subq_20.bookings + subq_40.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_19.booking__is_instant - , subq_19.listing__is_lux_latest - , subq_19.bookings + subq_39.booking__is_instant + , subq_39.listing__is_lux_latest + , subq_39.bookings FROM ( -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_18.booking__is_instant - , subq_18.listing__is_lux_latest - , subq_18.bookings + subq_38.booking__is_instant + , subq_38.listing__is_lux_latest + , subq_38.bookings FROM ( -- Join Standard Outputs SELECT - subq_14.listing AS listing - , subq_14.booking__is_instant AS booking__is_instant - , subq_17.is_lux_latest AS listing__is_lux_latest - , subq_14.bookings AS bookings + subq_34.listing AS listing + , subq_34.booking__is_instant AS booking__is_instant + , subq_37.is_lux_latest AS listing__is_lux_latest + , subq_34.bookings AS bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - subq_13.listing - , subq_13.booking__is_instant - , subq_13.bookings + subq_33.listing + , subq_33.booking__is_instant + , subq_33.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_12.ds__day - , subq_12.ds__week - , subq_12.ds__month - , subq_12.ds__quarter - , subq_12.ds__year - , subq_12.ds__extract_year - , subq_12.ds__extract_quarter - , subq_12.ds__extract_month - , subq_12.ds__extract_day - , subq_12.ds__extract_dow - , subq_12.ds__extract_doy - , subq_12.ds_partitioned__day - , subq_12.ds_partitioned__week - , subq_12.ds_partitioned__month - , subq_12.ds_partitioned__quarter - , subq_12.ds_partitioned__year - , subq_12.ds_partitioned__extract_year - , subq_12.ds_partitioned__extract_quarter - , subq_12.ds_partitioned__extract_month - , subq_12.ds_partitioned__extract_day - , subq_12.ds_partitioned__extract_dow - , subq_12.ds_partitioned__extract_doy - , subq_12.paid_at__day - , subq_12.paid_at__week - , subq_12.paid_at__month - , subq_12.paid_at__quarter - , subq_12.paid_at__year - , subq_12.paid_at__extract_year - , subq_12.paid_at__extract_quarter - , subq_12.paid_at__extract_month - , subq_12.paid_at__extract_day - , subq_12.paid_at__extract_dow - , subq_12.paid_at__extract_doy - , subq_12.booking__ds__day - , subq_12.booking__ds__week - , subq_12.booking__ds__month - , subq_12.booking__ds__quarter - , subq_12.booking__ds__year - , subq_12.booking__ds__extract_year - , subq_12.booking__ds__extract_quarter - , subq_12.booking__ds__extract_month - , subq_12.booking__ds__extract_day - , subq_12.booking__ds__extract_dow - , subq_12.booking__ds__extract_doy - , subq_12.booking__ds_partitioned__day - , subq_12.booking__ds_partitioned__week - , subq_12.booking__ds_partitioned__month - , subq_12.booking__ds_partitioned__quarter - , subq_12.booking__ds_partitioned__year - , subq_12.booking__ds_partitioned__extract_year - , subq_12.booking__ds_partitioned__extract_quarter - , subq_12.booking__ds_partitioned__extract_month - , subq_12.booking__ds_partitioned__extract_day - , subq_12.booking__ds_partitioned__extract_dow - , subq_12.booking__ds_partitioned__extract_doy - , subq_12.booking__paid_at__day - , subq_12.booking__paid_at__week - , subq_12.booking__paid_at__month - , subq_12.booking__paid_at__quarter - , subq_12.booking__paid_at__year - , subq_12.booking__paid_at__extract_year - , subq_12.booking__paid_at__extract_quarter - , subq_12.booking__paid_at__extract_month - , subq_12.booking__paid_at__extract_day - , subq_12.booking__paid_at__extract_dow - , subq_12.booking__paid_at__extract_doy - , subq_12.ds__day AS metric_time__day - , subq_12.ds__week AS metric_time__week - , subq_12.ds__month AS metric_time__month - , subq_12.ds__quarter AS metric_time__quarter - , subq_12.ds__year AS metric_time__year - , subq_12.ds__extract_year AS metric_time__extract_year - , subq_12.ds__extract_quarter AS metric_time__extract_quarter - , subq_12.ds__extract_month AS metric_time__extract_month - , subq_12.ds__extract_day AS metric_time__extract_day - , subq_12.ds__extract_dow AS metric_time__extract_dow - , subq_12.ds__extract_doy AS metric_time__extract_doy - , subq_12.listing - , subq_12.guest - , subq_12.host - , subq_12.booking__listing - , subq_12.booking__guest - , subq_12.booking__host - , subq_12.is_instant - , subq_12.booking__is_instant - , subq_12.bookings - , subq_12.instant_bookings - , subq_12.booking_value - , subq_12.max_booking_value - , subq_12.min_booking_value - , subq_12.bookers - , subq_12.average_booking_value - , subq_12.referred_bookings - , subq_12.median_booking_value - , subq_12.booking_value_p99 - , subq_12.discrete_booking_value_p99 - , subq_12.approximate_continuous_booking_value_p99 - , subq_12.approximate_discrete_booking_value_p99 + subq_32.ds__day + , subq_32.ds__week + , subq_32.ds__month + , subq_32.ds__quarter + , subq_32.ds__year + , subq_32.ds__extract_year + , subq_32.ds__extract_quarter + , subq_32.ds__extract_month + , subq_32.ds__extract_day + , subq_32.ds__extract_dow + , subq_32.ds__extract_doy + , subq_32.ds_partitioned__day + , subq_32.ds_partitioned__week + , subq_32.ds_partitioned__month + , subq_32.ds_partitioned__quarter + , subq_32.ds_partitioned__year + , subq_32.ds_partitioned__extract_year + , subq_32.ds_partitioned__extract_quarter + , subq_32.ds_partitioned__extract_month + , subq_32.ds_partitioned__extract_day + , subq_32.ds_partitioned__extract_dow + , subq_32.ds_partitioned__extract_doy + , subq_32.paid_at__day + , subq_32.paid_at__week + , subq_32.paid_at__month + , subq_32.paid_at__quarter + , subq_32.paid_at__year + , subq_32.paid_at__extract_year + , subq_32.paid_at__extract_quarter + , subq_32.paid_at__extract_month + , subq_32.paid_at__extract_day + , subq_32.paid_at__extract_dow + , subq_32.paid_at__extract_doy + , subq_32.booking__ds__day + , subq_32.booking__ds__week + , subq_32.booking__ds__month + , subq_32.booking__ds__quarter + , subq_32.booking__ds__year + , subq_32.booking__ds__extract_year + , subq_32.booking__ds__extract_quarter + , subq_32.booking__ds__extract_month + , subq_32.booking__ds__extract_day + , subq_32.booking__ds__extract_dow + , subq_32.booking__ds__extract_doy + , subq_32.booking__ds_partitioned__day + , subq_32.booking__ds_partitioned__week + , subq_32.booking__ds_partitioned__month + , subq_32.booking__ds_partitioned__quarter + , subq_32.booking__ds_partitioned__year + , subq_32.booking__ds_partitioned__extract_year + , subq_32.booking__ds_partitioned__extract_quarter + , subq_32.booking__ds_partitioned__extract_month + , subq_32.booking__ds_partitioned__extract_day + , subq_32.booking__ds_partitioned__extract_dow + , subq_32.booking__ds_partitioned__extract_doy + , subq_32.booking__paid_at__day + , subq_32.booking__paid_at__week + , subq_32.booking__paid_at__month + , subq_32.booking__paid_at__quarter + , subq_32.booking__paid_at__year + , subq_32.booking__paid_at__extract_year + , subq_32.booking__paid_at__extract_quarter + , subq_32.booking__paid_at__extract_month + , subq_32.booking__paid_at__extract_day + , subq_32.booking__paid_at__extract_dow + , subq_32.booking__paid_at__extract_doy + , subq_32.metric_time__day + , subq_32.metric_time__week + , subq_32.metric_time__month + , subq_32.metric_time__quarter + , subq_32.metric_time__year + , subq_32.metric_time__extract_year + , subq_32.metric_time__extract_quarter + , subq_32.metric_time__extract_month + , subq_32.metric_time__extract_day + , subq_32.metric_time__extract_dow + , subq_32.metric_time__extract_doy + , subq_32.listing + , subq_32.guest + , subq_32.host + , subq_32.booking__listing + , subq_32.booking__guest + , subq_32.booking__host + , subq_32.is_instant + , subq_32.booking__is_instant + , subq_32.bookings + , subq_32.instant_bookings + , subq_32.booking_value + , subq_32.max_booking_value + , subq_32.min_booking_value + , subq_32.bookers + , subq_32.average_booking_value + , subq_32.referred_bookings + , subq_32.median_booking_value + , subq_32.booking_value_p99 + , subq_32.discrete_booking_value_p99 + , subq_32.approximate_continuous_booking_value_p99 + , subq_32.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_12 - ) subq_13 - ) subq_14 + subq_31.ds__day + , subq_31.ds__week + , subq_31.ds__month + , subq_31.ds__quarter + , subq_31.ds__year + , subq_31.ds__extract_year + , subq_31.ds__extract_quarter + , subq_31.ds__extract_month + , subq_31.ds__extract_day + , subq_31.ds__extract_dow + , subq_31.ds__extract_doy + , subq_31.ds_partitioned__day + , subq_31.ds_partitioned__week + , subq_31.ds_partitioned__month + , subq_31.ds_partitioned__quarter + , subq_31.ds_partitioned__year + , subq_31.ds_partitioned__extract_year + , subq_31.ds_partitioned__extract_quarter + , subq_31.ds_partitioned__extract_month + , subq_31.ds_partitioned__extract_day + , subq_31.ds_partitioned__extract_dow + , subq_31.ds_partitioned__extract_doy + , subq_31.paid_at__day + , subq_31.paid_at__week + , subq_31.paid_at__month + , subq_31.paid_at__quarter + , subq_31.paid_at__year + , subq_31.paid_at__extract_year + , subq_31.paid_at__extract_quarter + , subq_31.paid_at__extract_month + , subq_31.paid_at__extract_day + , subq_31.paid_at__extract_dow + , subq_31.paid_at__extract_doy + , subq_31.booking__ds__day + , subq_31.booking__ds__week + , subq_31.booking__ds__month + , subq_31.booking__ds__quarter + , subq_31.booking__ds__year + , subq_31.booking__ds__extract_year + , subq_31.booking__ds__extract_quarter + , subq_31.booking__ds__extract_month + , subq_31.booking__ds__extract_day + , subq_31.booking__ds__extract_dow + , subq_31.booking__ds__extract_doy + , subq_31.booking__ds_partitioned__day + , subq_31.booking__ds_partitioned__week + , subq_31.booking__ds_partitioned__month + , subq_31.booking__ds_partitioned__quarter + , subq_31.booking__ds_partitioned__year + , subq_31.booking__ds_partitioned__extract_year + , subq_31.booking__ds_partitioned__extract_quarter + , subq_31.booking__ds_partitioned__extract_month + , subq_31.booking__ds_partitioned__extract_day + , subq_31.booking__ds_partitioned__extract_dow + , subq_31.booking__ds_partitioned__extract_doy + , subq_31.booking__paid_at__day + , subq_31.booking__paid_at__week + , subq_31.booking__paid_at__month + , subq_31.booking__paid_at__quarter + , subq_31.booking__paid_at__year + , subq_31.booking__paid_at__extract_year + , subq_31.booking__paid_at__extract_quarter + , subq_31.booking__paid_at__extract_month + , subq_31.booking__paid_at__extract_day + , subq_31.booking__paid_at__extract_dow + , subq_31.booking__paid_at__extract_doy + , subq_31.ds__day AS metric_time__day + , subq_31.ds__week AS metric_time__week + , subq_31.ds__month AS metric_time__month + , subq_31.ds__quarter AS metric_time__quarter + , subq_31.ds__year AS metric_time__year + , subq_31.ds__extract_year AS metric_time__extract_year + , subq_31.ds__extract_quarter AS metric_time__extract_quarter + , subq_31.ds__extract_month AS metric_time__extract_month + , subq_31.ds__extract_day AS metric_time__extract_day + , subq_31.ds__extract_dow AS metric_time__extract_dow + , subq_31.ds__extract_doy AS metric_time__extract_doy + , subq_31.listing + , subq_31.guest + , subq_31.host + , subq_31.booking__listing + , subq_31.booking__guest + , subq_31.booking__host + , subq_31.is_instant + , subq_31.booking__is_instant + , subq_31.bookings + , subq_31.instant_bookings + , subq_31.booking_value + , subq_31.max_booking_value + , subq_31.min_booking_value + , subq_31.bookers + , subq_31.average_booking_value + , subq_31.referred_bookings + , subq_31.median_booking_value + , subq_31.booking_value_p99 + , subq_31.discrete_booking_value_p99 + , subq_31.approximate_continuous_booking_value_p99 + , subq_31.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_31 + ) subq_32 + WHERE booking__is_instant + ) subq_33 + ) subq_34 LEFT OUTER JOIN ( -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_16.listing - , subq_16.is_lux_latest + subq_36.listing + , subq_36.is_lux_latest FROM ( -- Metric Time Dimension 'ds' SELECT - subq_15.ds__day - , subq_15.ds__week - , subq_15.ds__month - , subq_15.ds__quarter - , subq_15.ds__year - , subq_15.ds__extract_year - , subq_15.ds__extract_quarter - , subq_15.ds__extract_month - , subq_15.ds__extract_day - , subq_15.ds__extract_dow - , subq_15.ds__extract_doy - , subq_15.created_at__day - , subq_15.created_at__week - , subq_15.created_at__month - , subq_15.created_at__quarter - , subq_15.created_at__year - , subq_15.created_at__extract_year - , subq_15.created_at__extract_quarter - , subq_15.created_at__extract_month - , subq_15.created_at__extract_day - , subq_15.created_at__extract_dow - , subq_15.created_at__extract_doy - , subq_15.listing__ds__day - , subq_15.listing__ds__week - , subq_15.listing__ds__month - , subq_15.listing__ds__quarter - , subq_15.listing__ds__year - , subq_15.listing__ds__extract_year - , subq_15.listing__ds__extract_quarter - , subq_15.listing__ds__extract_month - , subq_15.listing__ds__extract_day - , subq_15.listing__ds__extract_dow - , subq_15.listing__ds__extract_doy - , subq_15.listing__created_at__day - , subq_15.listing__created_at__week - , subq_15.listing__created_at__month - , subq_15.listing__created_at__quarter - , subq_15.listing__created_at__year - , subq_15.listing__created_at__extract_year - , subq_15.listing__created_at__extract_quarter - , subq_15.listing__created_at__extract_month - , subq_15.listing__created_at__extract_day - , subq_15.listing__created_at__extract_dow - , subq_15.listing__created_at__extract_doy - , subq_15.ds__day AS metric_time__day - , subq_15.ds__week AS metric_time__week - , subq_15.ds__month AS metric_time__month - , subq_15.ds__quarter AS metric_time__quarter - , subq_15.ds__year AS metric_time__year - , subq_15.ds__extract_year AS metric_time__extract_year - , subq_15.ds__extract_quarter AS metric_time__extract_quarter - , subq_15.ds__extract_month AS metric_time__extract_month - , subq_15.ds__extract_day AS metric_time__extract_day - , subq_15.ds__extract_dow AS metric_time__extract_dow - , subq_15.ds__extract_doy AS metric_time__extract_doy - , subq_15.listing - , subq_15.user - , subq_15.listing__user - , subq_15.country_latest - , subq_15.is_lux_latest - , subq_15.capacity_latest - , subq_15.listing__country_latest - , subq_15.listing__is_lux_latest - , subq_15.listing__capacity_latest - , subq_15.listings - , subq_15.largest_listing - , subq_15.smallest_listing + subq_35.ds__day + , subq_35.ds__week + , subq_35.ds__month + , subq_35.ds__quarter + , subq_35.ds__year + , subq_35.ds__extract_year + , subq_35.ds__extract_quarter + , subq_35.ds__extract_month + , subq_35.ds__extract_day + , subq_35.ds__extract_dow + , subq_35.ds__extract_doy + , subq_35.created_at__day + , subq_35.created_at__week + , subq_35.created_at__month + , subq_35.created_at__quarter + , subq_35.created_at__year + , subq_35.created_at__extract_year + , subq_35.created_at__extract_quarter + , subq_35.created_at__extract_month + , subq_35.created_at__extract_day + , subq_35.created_at__extract_dow + , subq_35.created_at__extract_doy + , subq_35.listing__ds__day + , subq_35.listing__ds__week + , subq_35.listing__ds__month + , subq_35.listing__ds__quarter + , subq_35.listing__ds__year + , subq_35.listing__ds__extract_year + , subq_35.listing__ds__extract_quarter + , subq_35.listing__ds__extract_month + , subq_35.listing__ds__extract_day + , subq_35.listing__ds__extract_dow + , subq_35.listing__ds__extract_doy + , subq_35.listing__created_at__day + , subq_35.listing__created_at__week + , subq_35.listing__created_at__month + , subq_35.listing__created_at__quarter + , subq_35.listing__created_at__year + , subq_35.listing__created_at__extract_year + , subq_35.listing__created_at__extract_quarter + , subq_35.listing__created_at__extract_month + , subq_35.listing__created_at__extract_day + , subq_35.listing__created_at__extract_dow + , subq_35.listing__created_at__extract_doy + , subq_35.ds__day AS metric_time__day + , subq_35.ds__week AS metric_time__week + , subq_35.ds__month AS metric_time__month + , subq_35.ds__quarter AS metric_time__quarter + , subq_35.ds__year AS metric_time__year + , subq_35.ds__extract_year AS metric_time__extract_year + , subq_35.ds__extract_quarter AS metric_time__extract_quarter + , subq_35.ds__extract_month AS metric_time__extract_month + , subq_35.ds__extract_day AS metric_time__extract_day + , subq_35.ds__extract_dow AS metric_time__extract_dow + , subq_35.ds__extract_doy AS metric_time__extract_doy + , subq_35.listing + , subq_35.user + , subq_35.listing__user + , subq_35.country_latest + , subq_35.is_lux_latest + , subq_35.capacity_latest + , subq_35.listing__country_latest + , subq_35.listing__is_lux_latest + , subq_35.listing__capacity_latest + , subq_35.listings + , subq_35.largest_listing + , subq_35.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -759,240 +965,343 @@ FROM ( , listings_latest_src_28000.user_id AS user , listings_latest_src_28000.user_id AS listing__user FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_15 - ) subq_16 - ) subq_17 + ) subq_35 + ) subq_36 + ) subq_37 ON - subq_14.listing = subq_17.listing - ) subq_18 - ) subq_19 + subq_34.listing = subq_37.listing + ) subq_38 + ) subq_39 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_20 - ) subq_21 - ) subq_22 - ) subq_23 + ) subq_40 + ) subq_41 + ) subq_42 + ) subq_43 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_29.booking_value + subq_50.booking_value FROM ( -- Aggregate Measures SELECT - SUM(subq_28.booking_value) AS booking_value + SUM(subq_49.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value',] SELECT - subq_27.booking_value + subq_48.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_26.booking__is_instant - , subq_26.booking_value + subq_47.booking__is_instant + , subq_47.booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__is_instant'] SELECT - subq_25.booking__is_instant - , subq_25.booking_value + subq_46.booking__is_instant + , subq_46.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_24.ds__day - , subq_24.ds__week - , subq_24.ds__month - , subq_24.ds__quarter - , subq_24.ds__year - , subq_24.ds__extract_year - , subq_24.ds__extract_quarter - , subq_24.ds__extract_month - , subq_24.ds__extract_day - , subq_24.ds__extract_dow - , subq_24.ds__extract_doy - , subq_24.ds_partitioned__day - , subq_24.ds_partitioned__week - , subq_24.ds_partitioned__month - , subq_24.ds_partitioned__quarter - , subq_24.ds_partitioned__year - , subq_24.ds_partitioned__extract_year - , subq_24.ds_partitioned__extract_quarter - , subq_24.ds_partitioned__extract_month - , subq_24.ds_partitioned__extract_day - , subq_24.ds_partitioned__extract_dow - , subq_24.ds_partitioned__extract_doy - , subq_24.paid_at__day - , subq_24.paid_at__week - , subq_24.paid_at__month - , subq_24.paid_at__quarter - , subq_24.paid_at__year - , subq_24.paid_at__extract_year - , subq_24.paid_at__extract_quarter - , subq_24.paid_at__extract_month - , subq_24.paid_at__extract_day - , subq_24.paid_at__extract_dow - , subq_24.paid_at__extract_doy - , subq_24.booking__ds__day - , subq_24.booking__ds__week - , subq_24.booking__ds__month - , subq_24.booking__ds__quarter - , subq_24.booking__ds__year - , subq_24.booking__ds__extract_year - , subq_24.booking__ds__extract_quarter - , subq_24.booking__ds__extract_month - , subq_24.booking__ds__extract_day - , subq_24.booking__ds__extract_dow - , subq_24.booking__ds__extract_doy - , subq_24.booking__ds_partitioned__day - , subq_24.booking__ds_partitioned__week - , subq_24.booking__ds_partitioned__month - , subq_24.booking__ds_partitioned__quarter - , subq_24.booking__ds_partitioned__year - , subq_24.booking__ds_partitioned__extract_year - , subq_24.booking__ds_partitioned__extract_quarter - , subq_24.booking__ds_partitioned__extract_month - , subq_24.booking__ds_partitioned__extract_day - , subq_24.booking__ds_partitioned__extract_dow - , subq_24.booking__ds_partitioned__extract_doy - , subq_24.booking__paid_at__day - , subq_24.booking__paid_at__week - , subq_24.booking__paid_at__month - , subq_24.booking__paid_at__quarter - , subq_24.booking__paid_at__year - , subq_24.booking__paid_at__extract_year - , subq_24.booking__paid_at__extract_quarter - , subq_24.booking__paid_at__extract_month - , subq_24.booking__paid_at__extract_day - , subq_24.booking__paid_at__extract_dow - , subq_24.booking__paid_at__extract_doy - , subq_24.ds__day AS metric_time__day - , subq_24.ds__week AS metric_time__week - , subq_24.ds__month AS metric_time__month - , subq_24.ds__quarter AS metric_time__quarter - , subq_24.ds__year AS metric_time__year - , subq_24.ds__extract_year AS metric_time__extract_year - , subq_24.ds__extract_quarter AS metric_time__extract_quarter - , subq_24.ds__extract_month AS metric_time__extract_month - , subq_24.ds__extract_day AS metric_time__extract_day - , subq_24.ds__extract_dow AS metric_time__extract_dow - , subq_24.ds__extract_doy AS metric_time__extract_doy - , subq_24.listing - , subq_24.guest - , subq_24.host - , subq_24.booking__listing - , subq_24.booking__guest - , subq_24.booking__host - , subq_24.is_instant - , subq_24.booking__is_instant - , subq_24.bookings - , subq_24.instant_bookings - , subq_24.booking_value - , subq_24.max_booking_value - , subq_24.min_booking_value - , subq_24.bookers - , subq_24.average_booking_value - , subq_24.referred_bookings - , subq_24.median_booking_value - , subq_24.booking_value_p99 - , subq_24.discrete_booking_value_p99 - , subq_24.approximate_continuous_booking_value_p99 - , subq_24.approximate_discrete_booking_value_p99 + subq_45.ds__day + , subq_45.ds__week + , subq_45.ds__month + , subq_45.ds__quarter + , subq_45.ds__year + , subq_45.ds__extract_year + , subq_45.ds__extract_quarter + , subq_45.ds__extract_month + , subq_45.ds__extract_day + , subq_45.ds__extract_dow + , subq_45.ds__extract_doy + , subq_45.ds_partitioned__day + , subq_45.ds_partitioned__week + , subq_45.ds_partitioned__month + , subq_45.ds_partitioned__quarter + , subq_45.ds_partitioned__year + , subq_45.ds_partitioned__extract_year + , subq_45.ds_partitioned__extract_quarter + , subq_45.ds_partitioned__extract_month + , subq_45.ds_partitioned__extract_day + , subq_45.ds_partitioned__extract_dow + , subq_45.ds_partitioned__extract_doy + , subq_45.paid_at__day + , subq_45.paid_at__week + , subq_45.paid_at__month + , subq_45.paid_at__quarter + , subq_45.paid_at__year + , subq_45.paid_at__extract_year + , subq_45.paid_at__extract_quarter + , subq_45.paid_at__extract_month + , subq_45.paid_at__extract_day + , subq_45.paid_at__extract_dow + , subq_45.paid_at__extract_doy + , subq_45.booking__ds__day + , subq_45.booking__ds__week + , subq_45.booking__ds__month + , subq_45.booking__ds__quarter + , subq_45.booking__ds__year + , subq_45.booking__ds__extract_year + , subq_45.booking__ds__extract_quarter + , subq_45.booking__ds__extract_month + , subq_45.booking__ds__extract_day + , subq_45.booking__ds__extract_dow + , subq_45.booking__ds__extract_doy + , subq_45.booking__ds_partitioned__day + , subq_45.booking__ds_partitioned__week + , subq_45.booking__ds_partitioned__month + , subq_45.booking__ds_partitioned__quarter + , subq_45.booking__ds_partitioned__year + , subq_45.booking__ds_partitioned__extract_year + , subq_45.booking__ds_partitioned__extract_quarter + , subq_45.booking__ds_partitioned__extract_month + , subq_45.booking__ds_partitioned__extract_day + , subq_45.booking__ds_partitioned__extract_dow + , subq_45.booking__ds_partitioned__extract_doy + , subq_45.booking__paid_at__day + , subq_45.booking__paid_at__week + , subq_45.booking__paid_at__month + , subq_45.booking__paid_at__quarter + , subq_45.booking__paid_at__year + , subq_45.booking__paid_at__extract_year + , subq_45.booking__paid_at__extract_quarter + , subq_45.booking__paid_at__extract_month + , subq_45.booking__paid_at__extract_day + , subq_45.booking__paid_at__extract_dow + , subq_45.booking__paid_at__extract_doy + , subq_45.metric_time__day + , subq_45.metric_time__week + , subq_45.metric_time__month + , subq_45.metric_time__quarter + , subq_45.metric_time__year + , subq_45.metric_time__extract_year + , subq_45.metric_time__extract_quarter + , subq_45.metric_time__extract_month + , subq_45.metric_time__extract_day + , subq_45.metric_time__extract_dow + , subq_45.metric_time__extract_doy + , subq_45.listing + , subq_45.guest + , subq_45.host + , subq_45.booking__listing + , subq_45.booking__guest + , subq_45.booking__host + , subq_45.is_instant + , subq_45.booking__is_instant + , subq_45.bookings + , subq_45.instant_bookings + , subq_45.booking_value + , subq_45.max_booking_value + , subq_45.min_booking_value + , subq_45.bookers + , subq_45.average_booking_value + , subq_45.referred_bookings + , subq_45.median_booking_value + , subq_45.booking_value_p99 + , subq_45.discrete_booking_value_p99 + , subq_45.approximate_continuous_booking_value_p99 + , subq_45.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_24 - ) subq_25 - ) subq_26 + subq_44.ds__day + , subq_44.ds__week + , subq_44.ds__month + , subq_44.ds__quarter + , subq_44.ds__year + , subq_44.ds__extract_year + , subq_44.ds__extract_quarter + , subq_44.ds__extract_month + , subq_44.ds__extract_day + , subq_44.ds__extract_dow + , subq_44.ds__extract_doy + , subq_44.ds_partitioned__day + , subq_44.ds_partitioned__week + , subq_44.ds_partitioned__month + , subq_44.ds_partitioned__quarter + , subq_44.ds_partitioned__year + , subq_44.ds_partitioned__extract_year + , subq_44.ds_partitioned__extract_quarter + , subq_44.ds_partitioned__extract_month + , subq_44.ds_partitioned__extract_day + , subq_44.ds_partitioned__extract_dow + , subq_44.ds_partitioned__extract_doy + , subq_44.paid_at__day + , subq_44.paid_at__week + , subq_44.paid_at__month + , subq_44.paid_at__quarter + , subq_44.paid_at__year + , subq_44.paid_at__extract_year + , subq_44.paid_at__extract_quarter + , subq_44.paid_at__extract_month + , subq_44.paid_at__extract_day + , subq_44.paid_at__extract_dow + , subq_44.paid_at__extract_doy + , subq_44.booking__ds__day + , subq_44.booking__ds__week + , subq_44.booking__ds__month + , subq_44.booking__ds__quarter + , subq_44.booking__ds__year + , subq_44.booking__ds__extract_year + , subq_44.booking__ds__extract_quarter + , subq_44.booking__ds__extract_month + , subq_44.booking__ds__extract_day + , subq_44.booking__ds__extract_dow + , subq_44.booking__ds__extract_doy + , subq_44.booking__ds_partitioned__day + , subq_44.booking__ds_partitioned__week + , subq_44.booking__ds_partitioned__month + , subq_44.booking__ds_partitioned__quarter + , subq_44.booking__ds_partitioned__year + , subq_44.booking__ds_partitioned__extract_year + , subq_44.booking__ds_partitioned__extract_quarter + , subq_44.booking__ds_partitioned__extract_month + , subq_44.booking__ds_partitioned__extract_day + , subq_44.booking__ds_partitioned__extract_dow + , subq_44.booking__ds_partitioned__extract_doy + , subq_44.booking__paid_at__day + , subq_44.booking__paid_at__week + , subq_44.booking__paid_at__month + , subq_44.booking__paid_at__quarter + , subq_44.booking__paid_at__year + , subq_44.booking__paid_at__extract_year + , subq_44.booking__paid_at__extract_quarter + , subq_44.booking__paid_at__extract_month + , subq_44.booking__paid_at__extract_day + , subq_44.booking__paid_at__extract_dow + , subq_44.booking__paid_at__extract_doy + , subq_44.ds__day AS metric_time__day + , subq_44.ds__week AS metric_time__week + , subq_44.ds__month AS metric_time__month + , subq_44.ds__quarter AS metric_time__quarter + , subq_44.ds__year AS metric_time__year + , subq_44.ds__extract_year AS metric_time__extract_year + , subq_44.ds__extract_quarter AS metric_time__extract_quarter + , subq_44.ds__extract_month AS metric_time__extract_month + , subq_44.ds__extract_day AS metric_time__extract_day + , subq_44.ds__extract_dow AS metric_time__extract_dow + , subq_44.ds__extract_doy AS metric_time__extract_doy + , subq_44.listing + , subq_44.guest + , subq_44.host + , subq_44.booking__listing + , subq_44.booking__guest + , subq_44.booking__host + , subq_44.is_instant + , subq_44.booking__is_instant + , subq_44.bookings + , subq_44.instant_bookings + , subq_44.booking_value + , subq_44.max_booking_value + , subq_44.min_booking_value + , subq_44.bookers + , subq_44.average_booking_value + , subq_44.referred_bookings + , subq_44.median_booking_value + , subq_44.booking_value_p99 + , subq_44.discrete_booking_value_p99 + , subq_44.approximate_continuous_booking_value_p99 + , subq_44.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_44 + ) subq_45 + WHERE booking__is_instant + ) subq_46 + ) subq_47 WHERE booking__is_instant - ) subq_27 - ) subq_28 - ) subq_29 - ) subq_30 - ) subq_31 -) subq_32 + ) subq_48 + ) subq_49 + ) subq_50 + ) subq_51 + ) subq_52 +) subq_53 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_filters__plan0_optimized.sql index a73bfea928..a0fdc735bd 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_filters__plan0_optimized.sql @@ -8,9 +8,9 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_44.average_booking_value) AS average_booking_value - , MAX(subq_56.bookings) AS bookings - , MAX(subq_63.booking_value) AS booking_value + MAX(subq_66.average_booking_value) AS average_booking_value + , MAX(subq_79.bookings) AS bookings + , MAX(subq_87.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['average_booking_value',] @@ -22,17 +22,34 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - bookings_source_src_28000.is_instant AS booking__is_instant + subq_57.booking__is_instant AS booking__is_instant , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , bookings_source_src_28000.booking_value AS average_booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 + , subq_57.average_booking_value AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] + SELECT + listing + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_55 + WHERE booking__is_instant + ) subq_57 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - bookings_source_src_28000.listing_id = listings_latest_src_28000.listing_id - ) subq_40 + subq_57.listing = listings_latest_src_28000.listing_id + ) subq_62 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_44 + ) subq_66 CROSS JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings',] @@ -44,26 +61,34 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_47.booking__is_instant AS booking__is_instant + subq_70.booking__is_instant AS booking__is_instant , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , subq_47.bookings AS bookings + , subq_70.bookings AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - listing_id AS listing - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_47 + listing + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_68 + WHERE booking__is_instant + ) subq_70 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_47.listing = listings_latest_src_28000.listing_id - ) subq_52 + subq_70.listing = listings_latest_src_28000.listing_id + ) subq_75 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_56 + ) subq_79 CROSS JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value',] @@ -72,15 +97,22 @@ FROM ( SELECT SUM(booking_value) AS booking_value FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'booking__is_instant'] SELECT - is_instant AS booking__is_instant + booking__is_instant , booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_59 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_81 + WHERE booking__is_instant + ) subq_83 WHERE booking__is_instant - ) subq_63 - ) subq_64 -) subq_65 + ) subq_87 + ) subq_88 +) subq_89 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_filters__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_filters__plan0.sql index 9edb0371c0..d6ea5d1211 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_filters__plan0.sql @@ -8,317 +8,420 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_11.average_booking_value) AS average_booking_value - , MAX(subq_23.bookings) AS bookings - , MAX(subq_30.booking_value) AS booking_value + MAX(subq_30.average_booking_value) AS average_booking_value + , MAX(subq_43.bookings) AS bookings + , MAX(subq_51.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_10.average_booking_value + subq_29.average_booking_value FROM ( -- Aggregate Measures SELECT - AVG(subq_9.average_booking_value) AS average_booking_value + AVG(subq_28.average_booking_value) AS average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value',] SELECT - subq_8.average_booking_value + subq_27.average_booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_7.booking__is_instant - , subq_7.listing__is_lux_latest - , subq_7.average_booking_value + subq_26.booking__is_instant + , subq_26.listing__is_lux_latest + , subq_26.average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_6.booking__is_instant - , subq_6.listing__is_lux_latest - , subq_6.average_booking_value + subq_25.booking__is_instant + , subq_25.listing__is_lux_latest + , subq_25.average_booking_value FROM ( -- Join Standard Outputs SELECT - subq_2.listing AS listing - , subq_2.booking__is_instant AS booking__is_instant - , subq_5.is_lux_latest AS listing__is_lux_latest - , subq_2.average_booking_value AS average_booking_value + subq_21.listing AS listing + , subq_21.booking__is_instant AS booking__is_instant + , subq_24.is_lux_latest AS listing__is_lux_latest + , subq_21.average_booking_value AS average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] SELECT - subq_1.listing - , subq_1.booking__is_instant - , subq_1.average_booking_value + subq_20.listing + , subq_20.booking__is_instant + , subq_20.average_booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE 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.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.booking__paid_at__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.listing - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_19.ds__day + , subq_19.ds__week + , subq_19.ds__month + , subq_19.ds__quarter + , subq_19.ds__year + , subq_19.ds__extract_year + , subq_19.ds__extract_quarter + , subq_19.ds__extract_month + , subq_19.ds__extract_day + , subq_19.ds__extract_dow + , subq_19.ds__extract_doy + , subq_19.ds_partitioned__day + , subq_19.ds_partitioned__week + , subq_19.ds_partitioned__month + , subq_19.ds_partitioned__quarter + , subq_19.ds_partitioned__year + , subq_19.ds_partitioned__extract_year + , subq_19.ds_partitioned__extract_quarter + , subq_19.ds_partitioned__extract_month + , subq_19.ds_partitioned__extract_day + , subq_19.ds_partitioned__extract_dow + , subq_19.ds_partitioned__extract_doy + , subq_19.paid_at__day + , subq_19.paid_at__week + , subq_19.paid_at__month + , subq_19.paid_at__quarter + , subq_19.paid_at__year + , subq_19.paid_at__extract_year + , subq_19.paid_at__extract_quarter + , subq_19.paid_at__extract_month + , subq_19.paid_at__extract_day + , subq_19.paid_at__extract_dow + , subq_19.paid_at__extract_doy + , subq_19.booking__ds__day + , subq_19.booking__ds__week + , subq_19.booking__ds__month + , subq_19.booking__ds__quarter + , subq_19.booking__ds__year + , subq_19.booking__ds__extract_year + , subq_19.booking__ds__extract_quarter + , subq_19.booking__ds__extract_month + , subq_19.booking__ds__extract_day + , subq_19.booking__ds__extract_dow + , subq_19.booking__ds__extract_doy + , subq_19.booking__ds_partitioned__day + , subq_19.booking__ds_partitioned__week + , subq_19.booking__ds_partitioned__month + , subq_19.booking__ds_partitioned__quarter + , subq_19.booking__ds_partitioned__year + , subq_19.booking__ds_partitioned__extract_year + , subq_19.booking__ds_partitioned__extract_quarter + , subq_19.booking__ds_partitioned__extract_month + , subq_19.booking__ds_partitioned__extract_day + , subq_19.booking__ds_partitioned__extract_dow + , subq_19.booking__ds_partitioned__extract_doy + , subq_19.booking__paid_at__day + , subq_19.booking__paid_at__week + , subq_19.booking__paid_at__month + , subq_19.booking__paid_at__quarter + , subq_19.booking__paid_at__year + , subq_19.booking__paid_at__extract_year + , subq_19.booking__paid_at__extract_quarter + , subq_19.booking__paid_at__extract_month + , subq_19.booking__paid_at__extract_day + , subq_19.booking__paid_at__extract_dow + , subq_19.booking__paid_at__extract_doy + , subq_19.metric_time__day + , subq_19.metric_time__week + , subq_19.metric_time__month + , subq_19.metric_time__quarter + , subq_19.metric_time__year + , subq_19.metric_time__extract_year + , subq_19.metric_time__extract_quarter + , subq_19.metric_time__extract_month + , subq_19.metric_time__extract_day + , subq_19.metric_time__extract_dow + , subq_19.metric_time__extract_doy + , subq_19.listing + , subq_19.guest + , subq_19.host + , subq_19.booking__listing + , subq_19.booking__guest + , subq_19.booking__host + , subq_19.is_instant + , subq_19.booking__is_instant + , subq_19.bookings + , subq_19.instant_bookings + , subq_19.booking_value + , subq_19.max_booking_value + , subq_19.min_booking_value + , subq_19.bookers + , subq_19.average_booking_value + , subq_19.referred_bookings + , subq_19.median_booking_value + , subq_19.booking_value_p99 + , subq_19.discrete_booking_value_p99 + , subq_19.approximate_continuous_booking_value_p99 + , subq_19.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + subq_18.ds__day + , subq_18.ds__week + , subq_18.ds__month + , subq_18.ds__quarter + , subq_18.ds__year + , subq_18.ds__extract_year + , subq_18.ds__extract_quarter + , subq_18.ds__extract_month + , subq_18.ds__extract_day + , subq_18.ds__extract_dow + , subq_18.ds__extract_doy + , subq_18.ds_partitioned__day + , subq_18.ds_partitioned__week + , subq_18.ds_partitioned__month + , subq_18.ds_partitioned__quarter + , subq_18.ds_partitioned__year + , subq_18.ds_partitioned__extract_year + , subq_18.ds_partitioned__extract_quarter + , subq_18.ds_partitioned__extract_month + , subq_18.ds_partitioned__extract_day + , subq_18.ds_partitioned__extract_dow + , subq_18.ds_partitioned__extract_doy + , subq_18.paid_at__day + , subq_18.paid_at__week + , subq_18.paid_at__month + , subq_18.paid_at__quarter + , subq_18.paid_at__year + , subq_18.paid_at__extract_year + , subq_18.paid_at__extract_quarter + , subq_18.paid_at__extract_month + , subq_18.paid_at__extract_day + , subq_18.paid_at__extract_dow + , subq_18.paid_at__extract_doy + , subq_18.booking__ds__day + , subq_18.booking__ds__week + , subq_18.booking__ds__month + , subq_18.booking__ds__quarter + , subq_18.booking__ds__year + , subq_18.booking__ds__extract_year + , subq_18.booking__ds__extract_quarter + , subq_18.booking__ds__extract_month + , subq_18.booking__ds__extract_day + , subq_18.booking__ds__extract_dow + , subq_18.booking__ds__extract_doy + , subq_18.booking__ds_partitioned__day + , subq_18.booking__ds_partitioned__week + , subq_18.booking__ds_partitioned__month + , subq_18.booking__ds_partitioned__quarter + , subq_18.booking__ds_partitioned__year + , subq_18.booking__ds_partitioned__extract_year + , subq_18.booking__ds_partitioned__extract_quarter + , subq_18.booking__ds_partitioned__extract_month + , subq_18.booking__ds_partitioned__extract_day + , subq_18.booking__ds_partitioned__extract_dow + , subq_18.booking__ds_partitioned__extract_doy + , subq_18.booking__paid_at__day + , subq_18.booking__paid_at__week + , subq_18.booking__paid_at__month + , subq_18.booking__paid_at__quarter + , subq_18.booking__paid_at__year + , subq_18.booking__paid_at__extract_year + , subq_18.booking__paid_at__extract_quarter + , subq_18.booking__paid_at__extract_month + , subq_18.booking__paid_at__extract_day + , subq_18.booking__paid_at__extract_dow + , subq_18.booking__paid_at__extract_doy + , subq_18.ds__day AS metric_time__day + , subq_18.ds__week AS metric_time__week + , subq_18.ds__month AS metric_time__month + , subq_18.ds__quarter AS metric_time__quarter + , subq_18.ds__year AS metric_time__year + , subq_18.ds__extract_year AS metric_time__extract_year + , subq_18.ds__extract_quarter AS metric_time__extract_quarter + , subq_18.ds__extract_month AS metric_time__extract_month + , subq_18.ds__extract_day AS metric_time__extract_day + , subq_18.ds__extract_dow AS metric_time__extract_dow + , subq_18.ds__extract_doy AS metric_time__extract_doy + , subq_18.listing + , subq_18.guest + , subq_18.host + , subq_18.booking__listing + , subq_18.booking__guest + , subq_18.booking__host + , subq_18.is_instant + , subq_18.booking__is_instant + , subq_18.bookings + , subq_18.instant_bookings + , subq_18.booking_value + , subq_18.max_booking_value + , subq_18.min_booking_value + , subq_18.bookers + , subq_18.average_booking_value + , subq_18.referred_bookings + , subq_18.median_booking_value + , subq_18.booking_value_p99 + , subq_18.discrete_booking_value_p99 + , subq_18.approximate_continuous_booking_value_p99 + , subq_18.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_18 + ) subq_19 + WHERE booking__is_instant + ) subq_20 + ) subq_21 LEFT OUTER JOIN ( -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_4.listing - , subq_4.is_lux_latest + subq_23.listing + , subq_23.is_lux_latest FROM ( -- Metric Time Dimension 'ds' SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing + subq_22.ds__day + , subq_22.ds__week + , subq_22.ds__month + , subq_22.ds__quarter + , subq_22.ds__year + , subq_22.ds__extract_year + , subq_22.ds__extract_quarter + , subq_22.ds__extract_month + , subq_22.ds__extract_day + , subq_22.ds__extract_dow + , subq_22.ds__extract_doy + , subq_22.created_at__day + , subq_22.created_at__week + , subq_22.created_at__month + , subq_22.created_at__quarter + , subq_22.created_at__year + , subq_22.created_at__extract_year + , subq_22.created_at__extract_quarter + , subq_22.created_at__extract_month + , subq_22.created_at__extract_day + , subq_22.created_at__extract_dow + , subq_22.created_at__extract_doy + , subq_22.listing__ds__day + , subq_22.listing__ds__week + , subq_22.listing__ds__month + , subq_22.listing__ds__quarter + , subq_22.listing__ds__year + , subq_22.listing__ds__extract_year + , subq_22.listing__ds__extract_quarter + , subq_22.listing__ds__extract_month + , subq_22.listing__ds__extract_day + , subq_22.listing__ds__extract_dow + , subq_22.listing__ds__extract_doy + , subq_22.listing__created_at__day + , subq_22.listing__created_at__week + , subq_22.listing__created_at__month + , subq_22.listing__created_at__quarter + , subq_22.listing__created_at__year + , subq_22.listing__created_at__extract_year + , subq_22.listing__created_at__extract_quarter + , subq_22.listing__created_at__extract_month + , subq_22.listing__created_at__extract_day + , subq_22.listing__created_at__extract_dow + , subq_22.listing__created_at__extract_doy + , subq_22.ds__day AS metric_time__day + , subq_22.ds__week AS metric_time__week + , subq_22.ds__month AS metric_time__month + , subq_22.ds__quarter AS metric_time__quarter + , subq_22.ds__year AS metric_time__year + , subq_22.ds__extract_year AS metric_time__extract_year + , subq_22.ds__extract_quarter AS metric_time__extract_quarter + , subq_22.ds__extract_month AS metric_time__extract_month + , subq_22.ds__extract_day AS metric_time__extract_day + , subq_22.ds__extract_dow AS metric_time__extract_dow + , subq_22.ds__extract_doy AS metric_time__extract_doy + , subq_22.listing + , subq_22.user + , subq_22.listing__user + , subq_22.country_latest + , subq_22.is_lux_latest + , subq_22.capacity_latest + , subq_22.listing__country_latest + , subq_22.listing__is_lux_latest + , subq_22.listing__capacity_latest + , subq_22.listings + , subq_22.largest_listing + , subq_22.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -379,326 +482,429 @@ FROM ( , listings_latest_src_28000.user_id AS user , listings_latest_src_28000.user_id AS listing__user FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_3 - ) subq_4 - ) subq_5 + ) subq_22 + ) subq_23 + ) subq_24 ON - subq_2.listing = subq_5.listing - ) subq_6 - ) subq_7 + subq_21.listing = subq_24.listing + ) subq_25 + ) subq_26 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_8 - ) subq_9 - ) subq_10 - ) subq_11 + ) subq_27 + ) subq_28 + ) subq_29 + ) subq_30 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_22.bookings + subq_42.bookings FROM ( -- Aggregate Measures SELECT - SUM(subq_21.bookings) AS bookings + SUM(subq_41.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings',] SELECT - subq_20.bookings + subq_40.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_19.booking__is_instant - , subq_19.listing__is_lux_latest - , subq_19.bookings + subq_39.booking__is_instant + , subq_39.listing__is_lux_latest + , subq_39.bookings FROM ( -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_18.booking__is_instant - , subq_18.listing__is_lux_latest - , subq_18.bookings + subq_38.booking__is_instant + , subq_38.listing__is_lux_latest + , subq_38.bookings FROM ( -- Join Standard Outputs SELECT - subq_14.listing AS listing - , subq_14.booking__is_instant AS booking__is_instant - , subq_17.is_lux_latest AS listing__is_lux_latest - , subq_14.bookings AS bookings + subq_34.listing AS listing + , subq_34.booking__is_instant AS booking__is_instant + , subq_37.is_lux_latest AS listing__is_lux_latest + , subq_34.bookings AS bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - subq_13.listing - , subq_13.booking__is_instant - , subq_13.bookings + subq_33.listing + , subq_33.booking__is_instant + , subq_33.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_12.ds__day - , subq_12.ds__week - , subq_12.ds__month - , subq_12.ds__quarter - , subq_12.ds__year - , subq_12.ds__extract_year - , subq_12.ds__extract_quarter - , subq_12.ds__extract_month - , subq_12.ds__extract_day - , subq_12.ds__extract_dow - , subq_12.ds__extract_doy - , subq_12.ds_partitioned__day - , subq_12.ds_partitioned__week - , subq_12.ds_partitioned__month - , subq_12.ds_partitioned__quarter - , subq_12.ds_partitioned__year - , subq_12.ds_partitioned__extract_year - , subq_12.ds_partitioned__extract_quarter - , subq_12.ds_partitioned__extract_month - , subq_12.ds_partitioned__extract_day - , subq_12.ds_partitioned__extract_dow - , subq_12.ds_partitioned__extract_doy - , subq_12.paid_at__day - , subq_12.paid_at__week - , subq_12.paid_at__month - , subq_12.paid_at__quarter - , subq_12.paid_at__year - , subq_12.paid_at__extract_year - , subq_12.paid_at__extract_quarter - , subq_12.paid_at__extract_month - , subq_12.paid_at__extract_day - , subq_12.paid_at__extract_dow - , subq_12.paid_at__extract_doy - , subq_12.booking__ds__day - , subq_12.booking__ds__week - , subq_12.booking__ds__month - , subq_12.booking__ds__quarter - , subq_12.booking__ds__year - , subq_12.booking__ds__extract_year - , subq_12.booking__ds__extract_quarter - , subq_12.booking__ds__extract_month - , subq_12.booking__ds__extract_day - , subq_12.booking__ds__extract_dow - , subq_12.booking__ds__extract_doy - , subq_12.booking__ds_partitioned__day - , subq_12.booking__ds_partitioned__week - , subq_12.booking__ds_partitioned__month - , subq_12.booking__ds_partitioned__quarter - , subq_12.booking__ds_partitioned__year - , subq_12.booking__ds_partitioned__extract_year - , subq_12.booking__ds_partitioned__extract_quarter - , subq_12.booking__ds_partitioned__extract_month - , subq_12.booking__ds_partitioned__extract_day - , subq_12.booking__ds_partitioned__extract_dow - , subq_12.booking__ds_partitioned__extract_doy - , subq_12.booking__paid_at__day - , subq_12.booking__paid_at__week - , subq_12.booking__paid_at__month - , subq_12.booking__paid_at__quarter - , subq_12.booking__paid_at__year - , subq_12.booking__paid_at__extract_year - , subq_12.booking__paid_at__extract_quarter - , subq_12.booking__paid_at__extract_month - , subq_12.booking__paid_at__extract_day - , subq_12.booking__paid_at__extract_dow - , subq_12.booking__paid_at__extract_doy - , subq_12.ds__day AS metric_time__day - , subq_12.ds__week AS metric_time__week - , subq_12.ds__month AS metric_time__month - , subq_12.ds__quarter AS metric_time__quarter - , subq_12.ds__year AS metric_time__year - , subq_12.ds__extract_year AS metric_time__extract_year - , subq_12.ds__extract_quarter AS metric_time__extract_quarter - , subq_12.ds__extract_month AS metric_time__extract_month - , subq_12.ds__extract_day AS metric_time__extract_day - , subq_12.ds__extract_dow AS metric_time__extract_dow - , subq_12.ds__extract_doy AS metric_time__extract_doy - , subq_12.listing - , subq_12.guest - , subq_12.host - , subq_12.booking__listing - , subq_12.booking__guest - , subq_12.booking__host - , subq_12.is_instant - , subq_12.booking__is_instant - , subq_12.bookings - , subq_12.instant_bookings - , subq_12.booking_value - , subq_12.max_booking_value - , subq_12.min_booking_value - , subq_12.bookers - , subq_12.average_booking_value - , subq_12.referred_bookings - , subq_12.median_booking_value - , subq_12.booking_value_p99 - , subq_12.discrete_booking_value_p99 - , subq_12.approximate_continuous_booking_value_p99 - , subq_12.approximate_discrete_booking_value_p99 + subq_32.ds__day + , subq_32.ds__week + , subq_32.ds__month + , subq_32.ds__quarter + , subq_32.ds__year + , subq_32.ds__extract_year + , subq_32.ds__extract_quarter + , subq_32.ds__extract_month + , subq_32.ds__extract_day + , subq_32.ds__extract_dow + , subq_32.ds__extract_doy + , subq_32.ds_partitioned__day + , subq_32.ds_partitioned__week + , subq_32.ds_partitioned__month + , subq_32.ds_partitioned__quarter + , subq_32.ds_partitioned__year + , subq_32.ds_partitioned__extract_year + , subq_32.ds_partitioned__extract_quarter + , subq_32.ds_partitioned__extract_month + , subq_32.ds_partitioned__extract_day + , subq_32.ds_partitioned__extract_dow + , subq_32.ds_partitioned__extract_doy + , subq_32.paid_at__day + , subq_32.paid_at__week + , subq_32.paid_at__month + , subq_32.paid_at__quarter + , subq_32.paid_at__year + , subq_32.paid_at__extract_year + , subq_32.paid_at__extract_quarter + , subq_32.paid_at__extract_month + , subq_32.paid_at__extract_day + , subq_32.paid_at__extract_dow + , subq_32.paid_at__extract_doy + , subq_32.booking__ds__day + , subq_32.booking__ds__week + , subq_32.booking__ds__month + , subq_32.booking__ds__quarter + , subq_32.booking__ds__year + , subq_32.booking__ds__extract_year + , subq_32.booking__ds__extract_quarter + , subq_32.booking__ds__extract_month + , subq_32.booking__ds__extract_day + , subq_32.booking__ds__extract_dow + , subq_32.booking__ds__extract_doy + , subq_32.booking__ds_partitioned__day + , subq_32.booking__ds_partitioned__week + , subq_32.booking__ds_partitioned__month + , subq_32.booking__ds_partitioned__quarter + , subq_32.booking__ds_partitioned__year + , subq_32.booking__ds_partitioned__extract_year + , subq_32.booking__ds_partitioned__extract_quarter + , subq_32.booking__ds_partitioned__extract_month + , subq_32.booking__ds_partitioned__extract_day + , subq_32.booking__ds_partitioned__extract_dow + , subq_32.booking__ds_partitioned__extract_doy + , subq_32.booking__paid_at__day + , subq_32.booking__paid_at__week + , subq_32.booking__paid_at__month + , subq_32.booking__paid_at__quarter + , subq_32.booking__paid_at__year + , subq_32.booking__paid_at__extract_year + , subq_32.booking__paid_at__extract_quarter + , subq_32.booking__paid_at__extract_month + , subq_32.booking__paid_at__extract_day + , subq_32.booking__paid_at__extract_dow + , subq_32.booking__paid_at__extract_doy + , subq_32.metric_time__day + , subq_32.metric_time__week + , subq_32.metric_time__month + , subq_32.metric_time__quarter + , subq_32.metric_time__year + , subq_32.metric_time__extract_year + , subq_32.metric_time__extract_quarter + , subq_32.metric_time__extract_month + , subq_32.metric_time__extract_day + , subq_32.metric_time__extract_dow + , subq_32.metric_time__extract_doy + , subq_32.listing + , subq_32.guest + , subq_32.host + , subq_32.booking__listing + , subq_32.booking__guest + , subq_32.booking__host + , subq_32.is_instant + , subq_32.booking__is_instant + , subq_32.bookings + , subq_32.instant_bookings + , subq_32.booking_value + , subq_32.max_booking_value + , subq_32.min_booking_value + , subq_32.bookers + , subq_32.average_booking_value + , subq_32.referred_bookings + , subq_32.median_booking_value + , subq_32.booking_value_p99 + , subq_32.discrete_booking_value_p99 + , subq_32.approximate_continuous_booking_value_p99 + , subq_32.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_12 - ) subq_13 - ) subq_14 + subq_31.ds__day + , subq_31.ds__week + , subq_31.ds__month + , subq_31.ds__quarter + , subq_31.ds__year + , subq_31.ds__extract_year + , subq_31.ds__extract_quarter + , subq_31.ds__extract_month + , subq_31.ds__extract_day + , subq_31.ds__extract_dow + , subq_31.ds__extract_doy + , subq_31.ds_partitioned__day + , subq_31.ds_partitioned__week + , subq_31.ds_partitioned__month + , subq_31.ds_partitioned__quarter + , subq_31.ds_partitioned__year + , subq_31.ds_partitioned__extract_year + , subq_31.ds_partitioned__extract_quarter + , subq_31.ds_partitioned__extract_month + , subq_31.ds_partitioned__extract_day + , subq_31.ds_partitioned__extract_dow + , subq_31.ds_partitioned__extract_doy + , subq_31.paid_at__day + , subq_31.paid_at__week + , subq_31.paid_at__month + , subq_31.paid_at__quarter + , subq_31.paid_at__year + , subq_31.paid_at__extract_year + , subq_31.paid_at__extract_quarter + , subq_31.paid_at__extract_month + , subq_31.paid_at__extract_day + , subq_31.paid_at__extract_dow + , subq_31.paid_at__extract_doy + , subq_31.booking__ds__day + , subq_31.booking__ds__week + , subq_31.booking__ds__month + , subq_31.booking__ds__quarter + , subq_31.booking__ds__year + , subq_31.booking__ds__extract_year + , subq_31.booking__ds__extract_quarter + , subq_31.booking__ds__extract_month + , subq_31.booking__ds__extract_day + , subq_31.booking__ds__extract_dow + , subq_31.booking__ds__extract_doy + , subq_31.booking__ds_partitioned__day + , subq_31.booking__ds_partitioned__week + , subq_31.booking__ds_partitioned__month + , subq_31.booking__ds_partitioned__quarter + , subq_31.booking__ds_partitioned__year + , subq_31.booking__ds_partitioned__extract_year + , subq_31.booking__ds_partitioned__extract_quarter + , subq_31.booking__ds_partitioned__extract_month + , subq_31.booking__ds_partitioned__extract_day + , subq_31.booking__ds_partitioned__extract_dow + , subq_31.booking__ds_partitioned__extract_doy + , subq_31.booking__paid_at__day + , subq_31.booking__paid_at__week + , subq_31.booking__paid_at__month + , subq_31.booking__paid_at__quarter + , subq_31.booking__paid_at__year + , subq_31.booking__paid_at__extract_year + , subq_31.booking__paid_at__extract_quarter + , subq_31.booking__paid_at__extract_month + , subq_31.booking__paid_at__extract_day + , subq_31.booking__paid_at__extract_dow + , subq_31.booking__paid_at__extract_doy + , subq_31.ds__day AS metric_time__day + , subq_31.ds__week AS metric_time__week + , subq_31.ds__month AS metric_time__month + , subq_31.ds__quarter AS metric_time__quarter + , subq_31.ds__year AS metric_time__year + , subq_31.ds__extract_year AS metric_time__extract_year + , subq_31.ds__extract_quarter AS metric_time__extract_quarter + , subq_31.ds__extract_month AS metric_time__extract_month + , subq_31.ds__extract_day AS metric_time__extract_day + , subq_31.ds__extract_dow AS metric_time__extract_dow + , subq_31.ds__extract_doy AS metric_time__extract_doy + , subq_31.listing + , subq_31.guest + , subq_31.host + , subq_31.booking__listing + , subq_31.booking__guest + , subq_31.booking__host + , subq_31.is_instant + , subq_31.booking__is_instant + , subq_31.bookings + , subq_31.instant_bookings + , subq_31.booking_value + , subq_31.max_booking_value + , subq_31.min_booking_value + , subq_31.bookers + , subq_31.average_booking_value + , subq_31.referred_bookings + , subq_31.median_booking_value + , subq_31.booking_value_p99 + , subq_31.discrete_booking_value_p99 + , subq_31.approximate_continuous_booking_value_p99 + , subq_31.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_31 + ) subq_32 + WHERE booking__is_instant + ) subq_33 + ) subq_34 LEFT OUTER JOIN ( -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_16.listing - , subq_16.is_lux_latest + subq_36.listing + , subq_36.is_lux_latest FROM ( -- Metric Time Dimension 'ds' SELECT - subq_15.ds__day - , subq_15.ds__week - , subq_15.ds__month - , subq_15.ds__quarter - , subq_15.ds__year - , subq_15.ds__extract_year - , subq_15.ds__extract_quarter - , subq_15.ds__extract_month - , subq_15.ds__extract_day - , subq_15.ds__extract_dow - , subq_15.ds__extract_doy - , subq_15.created_at__day - , subq_15.created_at__week - , subq_15.created_at__month - , subq_15.created_at__quarter - , subq_15.created_at__year - , subq_15.created_at__extract_year - , subq_15.created_at__extract_quarter - , subq_15.created_at__extract_month - , subq_15.created_at__extract_day - , subq_15.created_at__extract_dow - , subq_15.created_at__extract_doy - , subq_15.listing__ds__day - , subq_15.listing__ds__week - , subq_15.listing__ds__month - , subq_15.listing__ds__quarter - , subq_15.listing__ds__year - , subq_15.listing__ds__extract_year - , subq_15.listing__ds__extract_quarter - , subq_15.listing__ds__extract_month - , subq_15.listing__ds__extract_day - , subq_15.listing__ds__extract_dow - , subq_15.listing__ds__extract_doy - , subq_15.listing__created_at__day - , subq_15.listing__created_at__week - , subq_15.listing__created_at__month - , subq_15.listing__created_at__quarter - , subq_15.listing__created_at__year - , subq_15.listing__created_at__extract_year - , subq_15.listing__created_at__extract_quarter - , subq_15.listing__created_at__extract_month - , subq_15.listing__created_at__extract_day - , subq_15.listing__created_at__extract_dow - , subq_15.listing__created_at__extract_doy - , subq_15.ds__day AS metric_time__day - , subq_15.ds__week AS metric_time__week - , subq_15.ds__month AS metric_time__month - , subq_15.ds__quarter AS metric_time__quarter - , subq_15.ds__year AS metric_time__year - , subq_15.ds__extract_year AS metric_time__extract_year - , subq_15.ds__extract_quarter AS metric_time__extract_quarter - , subq_15.ds__extract_month AS metric_time__extract_month - , subq_15.ds__extract_day AS metric_time__extract_day - , subq_15.ds__extract_dow AS metric_time__extract_dow - , subq_15.ds__extract_doy AS metric_time__extract_doy - , subq_15.listing - , subq_15.user - , subq_15.listing__user - , subq_15.country_latest - , subq_15.is_lux_latest - , subq_15.capacity_latest - , subq_15.listing__country_latest - , subq_15.listing__is_lux_latest - , subq_15.listing__capacity_latest - , subq_15.listings - , subq_15.largest_listing - , subq_15.smallest_listing + subq_35.ds__day + , subq_35.ds__week + , subq_35.ds__month + , subq_35.ds__quarter + , subq_35.ds__year + , subq_35.ds__extract_year + , subq_35.ds__extract_quarter + , subq_35.ds__extract_month + , subq_35.ds__extract_day + , subq_35.ds__extract_dow + , subq_35.ds__extract_doy + , subq_35.created_at__day + , subq_35.created_at__week + , subq_35.created_at__month + , subq_35.created_at__quarter + , subq_35.created_at__year + , subq_35.created_at__extract_year + , subq_35.created_at__extract_quarter + , subq_35.created_at__extract_month + , subq_35.created_at__extract_day + , subq_35.created_at__extract_dow + , subq_35.created_at__extract_doy + , subq_35.listing__ds__day + , subq_35.listing__ds__week + , subq_35.listing__ds__month + , subq_35.listing__ds__quarter + , subq_35.listing__ds__year + , subq_35.listing__ds__extract_year + , subq_35.listing__ds__extract_quarter + , subq_35.listing__ds__extract_month + , subq_35.listing__ds__extract_day + , subq_35.listing__ds__extract_dow + , subq_35.listing__ds__extract_doy + , subq_35.listing__created_at__day + , subq_35.listing__created_at__week + , subq_35.listing__created_at__month + , subq_35.listing__created_at__quarter + , subq_35.listing__created_at__year + , subq_35.listing__created_at__extract_year + , subq_35.listing__created_at__extract_quarter + , subq_35.listing__created_at__extract_month + , subq_35.listing__created_at__extract_day + , subq_35.listing__created_at__extract_dow + , subq_35.listing__created_at__extract_doy + , subq_35.ds__day AS metric_time__day + , subq_35.ds__week AS metric_time__week + , subq_35.ds__month AS metric_time__month + , subq_35.ds__quarter AS metric_time__quarter + , subq_35.ds__year AS metric_time__year + , subq_35.ds__extract_year AS metric_time__extract_year + , subq_35.ds__extract_quarter AS metric_time__extract_quarter + , subq_35.ds__extract_month AS metric_time__extract_month + , subq_35.ds__extract_day AS metric_time__extract_day + , subq_35.ds__extract_dow AS metric_time__extract_dow + , subq_35.ds__extract_doy AS metric_time__extract_doy + , subq_35.listing + , subq_35.user + , subq_35.listing__user + , subq_35.country_latest + , subq_35.is_lux_latest + , subq_35.capacity_latest + , subq_35.listing__country_latest + , subq_35.listing__is_lux_latest + , subq_35.listing__capacity_latest + , subq_35.listings + , subq_35.largest_listing + , subq_35.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -759,240 +965,343 @@ FROM ( , listings_latest_src_28000.user_id AS user , listings_latest_src_28000.user_id AS listing__user FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_15 - ) subq_16 - ) subq_17 + ) subq_35 + ) subq_36 + ) subq_37 ON - subq_14.listing = subq_17.listing - ) subq_18 - ) subq_19 + subq_34.listing = subq_37.listing + ) subq_38 + ) subq_39 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_20 - ) subq_21 - ) subq_22 - ) subq_23 + ) subq_40 + ) subq_41 + ) subq_42 + ) subq_43 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_29.booking_value + subq_50.booking_value FROM ( -- Aggregate Measures SELECT - SUM(subq_28.booking_value) AS booking_value + SUM(subq_49.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value',] SELECT - subq_27.booking_value + subq_48.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_26.booking__is_instant - , subq_26.booking_value + subq_47.booking__is_instant + , subq_47.booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__is_instant'] SELECT - subq_25.booking__is_instant - , subq_25.booking_value + subq_46.booking__is_instant + , subq_46.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_24.ds__day - , subq_24.ds__week - , subq_24.ds__month - , subq_24.ds__quarter - , subq_24.ds__year - , subq_24.ds__extract_year - , subq_24.ds__extract_quarter - , subq_24.ds__extract_month - , subq_24.ds__extract_day - , subq_24.ds__extract_dow - , subq_24.ds__extract_doy - , subq_24.ds_partitioned__day - , subq_24.ds_partitioned__week - , subq_24.ds_partitioned__month - , subq_24.ds_partitioned__quarter - , subq_24.ds_partitioned__year - , subq_24.ds_partitioned__extract_year - , subq_24.ds_partitioned__extract_quarter - , subq_24.ds_partitioned__extract_month - , subq_24.ds_partitioned__extract_day - , subq_24.ds_partitioned__extract_dow - , subq_24.ds_partitioned__extract_doy - , subq_24.paid_at__day - , subq_24.paid_at__week - , subq_24.paid_at__month - , subq_24.paid_at__quarter - , subq_24.paid_at__year - , subq_24.paid_at__extract_year - , subq_24.paid_at__extract_quarter - , subq_24.paid_at__extract_month - , subq_24.paid_at__extract_day - , subq_24.paid_at__extract_dow - , subq_24.paid_at__extract_doy - , subq_24.booking__ds__day - , subq_24.booking__ds__week - , subq_24.booking__ds__month - , subq_24.booking__ds__quarter - , subq_24.booking__ds__year - , subq_24.booking__ds__extract_year - , subq_24.booking__ds__extract_quarter - , subq_24.booking__ds__extract_month - , subq_24.booking__ds__extract_day - , subq_24.booking__ds__extract_dow - , subq_24.booking__ds__extract_doy - , subq_24.booking__ds_partitioned__day - , subq_24.booking__ds_partitioned__week - , subq_24.booking__ds_partitioned__month - , subq_24.booking__ds_partitioned__quarter - , subq_24.booking__ds_partitioned__year - , subq_24.booking__ds_partitioned__extract_year - , subq_24.booking__ds_partitioned__extract_quarter - , subq_24.booking__ds_partitioned__extract_month - , subq_24.booking__ds_partitioned__extract_day - , subq_24.booking__ds_partitioned__extract_dow - , subq_24.booking__ds_partitioned__extract_doy - , subq_24.booking__paid_at__day - , subq_24.booking__paid_at__week - , subq_24.booking__paid_at__month - , subq_24.booking__paid_at__quarter - , subq_24.booking__paid_at__year - , subq_24.booking__paid_at__extract_year - , subq_24.booking__paid_at__extract_quarter - , subq_24.booking__paid_at__extract_month - , subq_24.booking__paid_at__extract_day - , subq_24.booking__paid_at__extract_dow - , subq_24.booking__paid_at__extract_doy - , subq_24.ds__day AS metric_time__day - , subq_24.ds__week AS metric_time__week - , subq_24.ds__month AS metric_time__month - , subq_24.ds__quarter AS metric_time__quarter - , subq_24.ds__year AS metric_time__year - , subq_24.ds__extract_year AS metric_time__extract_year - , subq_24.ds__extract_quarter AS metric_time__extract_quarter - , subq_24.ds__extract_month AS metric_time__extract_month - , subq_24.ds__extract_day AS metric_time__extract_day - , subq_24.ds__extract_dow AS metric_time__extract_dow - , subq_24.ds__extract_doy AS metric_time__extract_doy - , subq_24.listing - , subq_24.guest - , subq_24.host - , subq_24.booking__listing - , subq_24.booking__guest - , subq_24.booking__host - , subq_24.is_instant - , subq_24.booking__is_instant - , subq_24.bookings - , subq_24.instant_bookings - , subq_24.booking_value - , subq_24.max_booking_value - , subq_24.min_booking_value - , subq_24.bookers - , subq_24.average_booking_value - , subq_24.referred_bookings - , subq_24.median_booking_value - , subq_24.booking_value_p99 - , subq_24.discrete_booking_value_p99 - , subq_24.approximate_continuous_booking_value_p99 - , subq_24.approximate_discrete_booking_value_p99 + subq_45.ds__day + , subq_45.ds__week + , subq_45.ds__month + , subq_45.ds__quarter + , subq_45.ds__year + , subq_45.ds__extract_year + , subq_45.ds__extract_quarter + , subq_45.ds__extract_month + , subq_45.ds__extract_day + , subq_45.ds__extract_dow + , subq_45.ds__extract_doy + , subq_45.ds_partitioned__day + , subq_45.ds_partitioned__week + , subq_45.ds_partitioned__month + , subq_45.ds_partitioned__quarter + , subq_45.ds_partitioned__year + , subq_45.ds_partitioned__extract_year + , subq_45.ds_partitioned__extract_quarter + , subq_45.ds_partitioned__extract_month + , subq_45.ds_partitioned__extract_day + , subq_45.ds_partitioned__extract_dow + , subq_45.ds_partitioned__extract_doy + , subq_45.paid_at__day + , subq_45.paid_at__week + , subq_45.paid_at__month + , subq_45.paid_at__quarter + , subq_45.paid_at__year + , subq_45.paid_at__extract_year + , subq_45.paid_at__extract_quarter + , subq_45.paid_at__extract_month + , subq_45.paid_at__extract_day + , subq_45.paid_at__extract_dow + , subq_45.paid_at__extract_doy + , subq_45.booking__ds__day + , subq_45.booking__ds__week + , subq_45.booking__ds__month + , subq_45.booking__ds__quarter + , subq_45.booking__ds__year + , subq_45.booking__ds__extract_year + , subq_45.booking__ds__extract_quarter + , subq_45.booking__ds__extract_month + , subq_45.booking__ds__extract_day + , subq_45.booking__ds__extract_dow + , subq_45.booking__ds__extract_doy + , subq_45.booking__ds_partitioned__day + , subq_45.booking__ds_partitioned__week + , subq_45.booking__ds_partitioned__month + , subq_45.booking__ds_partitioned__quarter + , subq_45.booking__ds_partitioned__year + , subq_45.booking__ds_partitioned__extract_year + , subq_45.booking__ds_partitioned__extract_quarter + , subq_45.booking__ds_partitioned__extract_month + , subq_45.booking__ds_partitioned__extract_day + , subq_45.booking__ds_partitioned__extract_dow + , subq_45.booking__ds_partitioned__extract_doy + , subq_45.booking__paid_at__day + , subq_45.booking__paid_at__week + , subq_45.booking__paid_at__month + , subq_45.booking__paid_at__quarter + , subq_45.booking__paid_at__year + , subq_45.booking__paid_at__extract_year + , subq_45.booking__paid_at__extract_quarter + , subq_45.booking__paid_at__extract_month + , subq_45.booking__paid_at__extract_day + , subq_45.booking__paid_at__extract_dow + , subq_45.booking__paid_at__extract_doy + , subq_45.metric_time__day + , subq_45.metric_time__week + , subq_45.metric_time__month + , subq_45.metric_time__quarter + , subq_45.metric_time__year + , subq_45.metric_time__extract_year + , subq_45.metric_time__extract_quarter + , subq_45.metric_time__extract_month + , subq_45.metric_time__extract_day + , subq_45.metric_time__extract_dow + , subq_45.metric_time__extract_doy + , subq_45.listing + , subq_45.guest + , subq_45.host + , subq_45.booking__listing + , subq_45.booking__guest + , subq_45.booking__host + , subq_45.is_instant + , subq_45.booking__is_instant + , subq_45.bookings + , subq_45.instant_bookings + , subq_45.booking_value + , subq_45.max_booking_value + , subq_45.min_booking_value + , subq_45.bookers + , subq_45.average_booking_value + , subq_45.referred_bookings + , subq_45.median_booking_value + , subq_45.booking_value_p99 + , subq_45.discrete_booking_value_p99 + , subq_45.approximate_continuous_booking_value_p99 + , subq_45.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_24 - ) subq_25 - ) subq_26 + subq_44.ds__day + , subq_44.ds__week + , subq_44.ds__month + , subq_44.ds__quarter + , subq_44.ds__year + , subq_44.ds__extract_year + , subq_44.ds__extract_quarter + , subq_44.ds__extract_month + , subq_44.ds__extract_day + , subq_44.ds__extract_dow + , subq_44.ds__extract_doy + , subq_44.ds_partitioned__day + , subq_44.ds_partitioned__week + , subq_44.ds_partitioned__month + , subq_44.ds_partitioned__quarter + , subq_44.ds_partitioned__year + , subq_44.ds_partitioned__extract_year + , subq_44.ds_partitioned__extract_quarter + , subq_44.ds_partitioned__extract_month + , subq_44.ds_partitioned__extract_day + , subq_44.ds_partitioned__extract_dow + , subq_44.ds_partitioned__extract_doy + , subq_44.paid_at__day + , subq_44.paid_at__week + , subq_44.paid_at__month + , subq_44.paid_at__quarter + , subq_44.paid_at__year + , subq_44.paid_at__extract_year + , subq_44.paid_at__extract_quarter + , subq_44.paid_at__extract_month + , subq_44.paid_at__extract_day + , subq_44.paid_at__extract_dow + , subq_44.paid_at__extract_doy + , subq_44.booking__ds__day + , subq_44.booking__ds__week + , subq_44.booking__ds__month + , subq_44.booking__ds__quarter + , subq_44.booking__ds__year + , subq_44.booking__ds__extract_year + , subq_44.booking__ds__extract_quarter + , subq_44.booking__ds__extract_month + , subq_44.booking__ds__extract_day + , subq_44.booking__ds__extract_dow + , subq_44.booking__ds__extract_doy + , subq_44.booking__ds_partitioned__day + , subq_44.booking__ds_partitioned__week + , subq_44.booking__ds_partitioned__month + , subq_44.booking__ds_partitioned__quarter + , subq_44.booking__ds_partitioned__year + , subq_44.booking__ds_partitioned__extract_year + , subq_44.booking__ds_partitioned__extract_quarter + , subq_44.booking__ds_partitioned__extract_month + , subq_44.booking__ds_partitioned__extract_day + , subq_44.booking__ds_partitioned__extract_dow + , subq_44.booking__ds_partitioned__extract_doy + , subq_44.booking__paid_at__day + , subq_44.booking__paid_at__week + , subq_44.booking__paid_at__month + , subq_44.booking__paid_at__quarter + , subq_44.booking__paid_at__year + , subq_44.booking__paid_at__extract_year + , subq_44.booking__paid_at__extract_quarter + , subq_44.booking__paid_at__extract_month + , subq_44.booking__paid_at__extract_day + , subq_44.booking__paid_at__extract_dow + , subq_44.booking__paid_at__extract_doy + , subq_44.ds__day AS metric_time__day + , subq_44.ds__week AS metric_time__week + , subq_44.ds__month AS metric_time__month + , subq_44.ds__quarter AS metric_time__quarter + , subq_44.ds__year AS metric_time__year + , subq_44.ds__extract_year AS metric_time__extract_year + , subq_44.ds__extract_quarter AS metric_time__extract_quarter + , subq_44.ds__extract_month AS metric_time__extract_month + , subq_44.ds__extract_day AS metric_time__extract_day + , subq_44.ds__extract_dow AS metric_time__extract_dow + , subq_44.ds__extract_doy AS metric_time__extract_doy + , subq_44.listing + , subq_44.guest + , subq_44.host + , subq_44.booking__listing + , subq_44.booking__guest + , subq_44.booking__host + , subq_44.is_instant + , subq_44.booking__is_instant + , subq_44.bookings + , subq_44.instant_bookings + , subq_44.booking_value + , subq_44.max_booking_value + , subq_44.min_booking_value + , subq_44.bookers + , subq_44.average_booking_value + , subq_44.referred_bookings + , subq_44.median_booking_value + , subq_44.booking_value_p99 + , subq_44.discrete_booking_value_p99 + , subq_44.approximate_continuous_booking_value_p99 + , subq_44.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_44 + ) subq_45 + WHERE booking__is_instant + ) subq_46 + ) subq_47 WHERE booking__is_instant - ) subq_27 - ) subq_28 - ) subq_29 - ) subq_30 - ) subq_31 -) subq_32 + ) subq_48 + ) subq_49 + ) subq_50 + ) subq_51 + ) subq_52 +) subq_53 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_filters__plan0_optimized.sql index a73bfea928..a0fdc735bd 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_filters__plan0_optimized.sql @@ -8,9 +8,9 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_44.average_booking_value) AS average_booking_value - , MAX(subq_56.bookings) AS bookings - , MAX(subq_63.booking_value) AS booking_value + MAX(subq_66.average_booking_value) AS average_booking_value + , MAX(subq_79.bookings) AS bookings + , MAX(subq_87.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['average_booking_value',] @@ -22,17 +22,34 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - bookings_source_src_28000.is_instant AS booking__is_instant + subq_57.booking__is_instant AS booking__is_instant , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , bookings_source_src_28000.booking_value AS average_booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 + , subq_57.average_booking_value AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] + SELECT + listing + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_55 + WHERE booking__is_instant + ) subq_57 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - bookings_source_src_28000.listing_id = listings_latest_src_28000.listing_id - ) subq_40 + subq_57.listing = listings_latest_src_28000.listing_id + ) subq_62 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_44 + ) subq_66 CROSS JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings',] @@ -44,26 +61,34 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_47.booking__is_instant AS booking__is_instant + subq_70.booking__is_instant AS booking__is_instant , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , subq_47.bookings AS bookings + , subq_70.bookings AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - listing_id AS listing - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_47 + listing + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_68 + WHERE booking__is_instant + ) subq_70 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_47.listing = listings_latest_src_28000.listing_id - ) subq_52 + subq_70.listing = listings_latest_src_28000.listing_id + ) subq_75 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_56 + ) subq_79 CROSS JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value',] @@ -72,15 +97,22 @@ FROM ( SELECT SUM(booking_value) AS booking_value FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'booking__is_instant'] SELECT - is_instant AS booking__is_instant + booking__is_instant , booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_59 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_81 + WHERE booking__is_instant + ) subq_83 WHERE booking__is_instant - ) subq_63 - ) subq_64 -) subq_65 + ) subq_87 + ) subq_88 +) subq_89 diff --git a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimension_values_with_a_join_and_a_filter__plan0.sql b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimension_values_with_a_join_and_a_filter__plan0.sql index 0c1597746c..b76cec7e4c 100644 --- a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimension_values_with_a_join_and_a_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimension_values_with_a_join_and_a_filter__plan0.sql @@ -1,127 +1,127 @@ -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest'] SELECT - subq_4.listing__is_lux_latest - , subq_4.user__home_state_latest + subq_7.listing__is_lux_latest + , subq_7.user__home_state_latest FROM ( -- Constrain Output with WHERE SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.user__home_state_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing + 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.created_at__day + , subq_6.created_at__week + , subq_6.created_at__month + , subq_6.created_at__quarter + , subq_6.created_at__year + , subq_6.created_at__extract_year + , subq_6.created_at__extract_quarter + , subq_6.created_at__extract_month + , subq_6.created_at__extract_day + , subq_6.created_at__extract_dow + , subq_6.created_at__extract_doy + , subq_6.listing__ds__day + , subq_6.listing__ds__week + , subq_6.listing__ds__month + , subq_6.listing__ds__quarter + , subq_6.listing__ds__year + , subq_6.listing__ds__extract_year + , subq_6.listing__ds__extract_quarter + , subq_6.listing__ds__extract_month + , subq_6.listing__ds__extract_day + , subq_6.listing__ds__extract_dow + , subq_6.listing__ds__extract_doy + , subq_6.listing__created_at__day + , subq_6.listing__created_at__week + , subq_6.listing__created_at__month + , subq_6.listing__created_at__quarter + , subq_6.listing__created_at__year + , subq_6.listing__created_at__extract_year + , subq_6.listing__created_at__extract_quarter + , subq_6.listing__created_at__extract_month + , subq_6.listing__created_at__extract_day + , subq_6.listing__created_at__extract_dow + , subq_6.listing__created_at__extract_doy + , subq_6.listing + , subq_6.user + , subq_6.listing__user + , subq_6.country_latest + , subq_6.is_lux_latest + , subq_6.capacity_latest + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.user__home_state_latest + , subq_6.listings + , subq_6.largest_listing + , subq_6.smallest_listing FROM ( -- Join Standard Outputs SELECT - subq_0.ds__day AS ds__day - , subq_0.ds__week AS ds__week - , subq_0.ds__month AS ds__month - , subq_0.ds__quarter AS ds__quarter - , subq_0.ds__year AS ds__year - , subq_0.ds__extract_year AS ds__extract_year - , subq_0.ds__extract_quarter AS ds__extract_quarter - , subq_0.ds__extract_month AS ds__extract_month - , subq_0.ds__extract_day AS ds__extract_day - , subq_0.ds__extract_dow AS ds__extract_dow - , subq_0.ds__extract_doy AS ds__extract_doy - , subq_0.created_at__day AS created_at__day - , subq_0.created_at__week AS created_at__week - , subq_0.created_at__month AS created_at__month - , subq_0.created_at__quarter AS created_at__quarter - , subq_0.created_at__year AS created_at__year - , subq_0.created_at__extract_year AS created_at__extract_year - , subq_0.created_at__extract_quarter AS created_at__extract_quarter - , subq_0.created_at__extract_month AS created_at__extract_month - , subq_0.created_at__extract_day AS created_at__extract_day - , subq_0.created_at__extract_dow AS created_at__extract_dow - , subq_0.created_at__extract_doy AS created_at__extract_doy - , subq_0.listing__ds__day AS listing__ds__day - , subq_0.listing__ds__week AS listing__ds__week - , subq_0.listing__ds__month AS listing__ds__month - , subq_0.listing__ds__quarter AS listing__ds__quarter - , subq_0.listing__ds__year AS listing__ds__year - , subq_0.listing__ds__extract_year AS listing__ds__extract_year - , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter - , subq_0.listing__ds__extract_month AS listing__ds__extract_month - , subq_0.listing__ds__extract_day AS listing__ds__extract_day - , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow - , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy - , subq_0.listing__created_at__day AS listing__created_at__day - , subq_0.listing__created_at__week AS listing__created_at__week - , subq_0.listing__created_at__month AS listing__created_at__month - , subq_0.listing__created_at__quarter AS listing__created_at__quarter - , subq_0.listing__created_at__year AS listing__created_at__year - , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month - , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow - , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy - , subq_0.listing AS listing - , subq_0.user AS user - , subq_0.listing__user AS listing__user - , subq_0.country_latest AS country_latest - , subq_0.is_lux_latest AS is_lux_latest - , subq_0.capacity_latest AS capacity_latest - , subq_0.listing__country_latest AS listing__country_latest - , subq_0.listing__is_lux_latest AS listing__is_lux_latest - , subq_0.listing__capacity_latest AS listing__capacity_latest - , subq_2.home_state_latest AS user__home_state_latest - , subq_0.listings AS listings - , subq_0.largest_listing AS largest_listing - , subq_0.smallest_listing AS smallest_listing + subq_2.ds__day AS ds__day + , subq_2.ds__week AS ds__week + , subq_2.ds__month AS ds__month + , subq_2.ds__quarter AS ds__quarter + , subq_2.ds__year AS ds__year + , subq_2.ds__extract_year AS ds__extract_year + , subq_2.ds__extract_quarter AS ds__extract_quarter + , subq_2.ds__extract_month AS ds__extract_month + , subq_2.ds__extract_day AS ds__extract_day + , subq_2.ds__extract_dow AS ds__extract_dow + , subq_2.ds__extract_doy AS ds__extract_doy + , subq_2.created_at__day AS created_at__day + , subq_2.created_at__week AS created_at__week + , subq_2.created_at__month AS created_at__month + , subq_2.created_at__quarter AS created_at__quarter + , subq_2.created_at__year AS created_at__year + , subq_2.created_at__extract_year AS created_at__extract_year + , subq_2.created_at__extract_quarter AS created_at__extract_quarter + , subq_2.created_at__extract_month AS created_at__extract_month + , subq_2.created_at__extract_day AS created_at__extract_day + , subq_2.created_at__extract_dow AS created_at__extract_dow + , subq_2.created_at__extract_doy AS created_at__extract_doy + , subq_2.listing__ds__day AS listing__ds__day + , subq_2.listing__ds__week AS listing__ds__week + , subq_2.listing__ds__month AS listing__ds__month + , subq_2.listing__ds__quarter AS listing__ds__quarter + , subq_2.listing__ds__year AS listing__ds__year + , subq_2.listing__ds__extract_year AS listing__ds__extract_year + , subq_2.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_2.listing__ds__extract_month AS listing__ds__extract_month + , subq_2.listing__ds__extract_day AS listing__ds__extract_day + , subq_2.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_2.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_2.listing__created_at__day AS listing__created_at__day + , subq_2.listing__created_at__week AS listing__created_at__week + , subq_2.listing__created_at__month AS listing__created_at__month + , subq_2.listing__created_at__quarter AS listing__created_at__quarter + , subq_2.listing__created_at__year AS listing__created_at__year + , subq_2.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_2.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_2.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_2.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_2.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_2.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_2.listing AS listing + , subq_2.user AS user + , subq_2.listing__user AS listing__user + , subq_2.country_latest AS country_latest + , subq_2.is_lux_latest AS is_lux_latest + , subq_2.capacity_latest AS capacity_latest + , subq_2.listing__country_latest AS listing__country_latest + , subq_2.listing__is_lux_latest AS listing__is_lux_latest + , subq_2.listing__capacity_latest AS listing__capacity_latest + , subq_5.home_state_latest AS user__home_state_latest + , subq_2.listings AS listings + , subq_2.largest_listing AS largest_listing + , subq_2.smallest_listing AS smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -182,48 +182,78 @@ FROM ( , listings_latest_src_28000.user_id AS user , listings_latest_src_28000.user_id AS listing__user FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_0 + ) subq_2 FULL OUTER JOIN ( -- Pass Only Elements: ['home_state_latest', 'user'] SELECT - subq_1.user - , subq_1.home_state_latest + subq_4.user + , subq_4.home_state_latest FROM ( - -- Read Elements From Semantic Model 'users_latest' + -- Constrain Output with WHERE SELECT - DATE_TRUNC(users_latest_src_28000.ds, day) AS ds_latest__day - , DATE_TRUNC(users_latest_src_28000.ds, isoweek) AS ds_latest__week - , DATE_TRUNC(users_latest_src_28000.ds, month) AS ds_latest__month - , DATE_TRUNC(users_latest_src_28000.ds, quarter) AS ds_latest__quarter - , DATE_TRUNC(users_latest_src_28000.ds, year) AS ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day - , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS ds_latest__extract_dow - , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS ds_latest__extract_doy - , users_latest_src_28000.home_state_latest - , DATE_TRUNC(users_latest_src_28000.ds, day) AS user__ds_latest__day - , DATE_TRUNC(users_latest_src_28000.ds, isoweek) AS user__ds_latest__week - , DATE_TRUNC(users_latest_src_28000.ds, month) AS user__ds_latest__month - , DATE_TRUNC(users_latest_src_28000.ds, quarter) AS user__ds_latest__quarter - , DATE_TRUNC(users_latest_src_28000.ds, year) AS user__ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day - , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS user__ds_latest__extract_dow - , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy - , users_latest_src_28000.home_state_latest AS user__home_state_latest - , users_latest_src_28000.user_id AS user - FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_1 - ) subq_2 + subq_3.ds_latest__day + , subq_3.ds_latest__week + , subq_3.ds_latest__month + , subq_3.ds_latest__quarter + , subq_3.ds_latest__year + , subq_3.ds_latest__extract_year + , subq_3.ds_latest__extract_quarter + , subq_3.ds_latest__extract_month + , subq_3.ds_latest__extract_day + , subq_3.ds_latest__extract_dow + , subq_3.ds_latest__extract_doy + , subq_3.user__ds_latest__day + , subq_3.user__ds_latest__week + , subq_3.user__ds_latest__month + , subq_3.user__ds_latest__quarter + , subq_3.user__ds_latest__year + , subq_3.user__ds_latest__extract_year + , subq_3.user__ds_latest__extract_quarter + , subq_3.user__ds_latest__extract_month + , subq_3.user__ds_latest__extract_day + , subq_3.user__ds_latest__extract_dow + , subq_3.user__ds_latest__extract_doy + , subq_3.user + , subq_3.home_state_latest + , subq_3.user__home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC(users_latest_src_28000.ds, day) AS ds_latest__day + , DATE_TRUNC(users_latest_src_28000.ds, isoweek) AS ds_latest__week + , DATE_TRUNC(users_latest_src_28000.ds, month) AS ds_latest__month + , DATE_TRUNC(users_latest_src_28000.ds, quarter) AS ds_latest__quarter + , DATE_TRUNC(users_latest_src_28000.ds, year) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS ds_latest__extract_dow + , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC(users_latest_src_28000.ds, day) AS user__ds_latest__day + , DATE_TRUNC(users_latest_src_28000.ds, isoweek) AS user__ds_latest__week + , DATE_TRUNC(users_latest_src_28000.ds, month) AS user__ds_latest__month + , DATE_TRUNC(users_latest_src_28000.ds, quarter) AS user__ds_latest__quarter + , DATE_TRUNC(users_latest_src_28000.ds, year) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS user__ds_latest__extract_dow + , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + WHERE user__home_state_latest = 'us' + ) subq_4 + ) subq_5 ON - subq_0.user = subq_2.user - ) subq_3 + subq_2.user = subq_5.user + ) subq_6 WHERE user__home_state_latest = 'us' -) subq_4 +) subq_7 GROUP BY listing__is_lux_latest , user__home_state_latest diff --git a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql index e54eaffeb6..c77b46c217 100644 --- a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql @@ -7,13 +7,27 @@ FROM ( -- Join Standard Outputs SELECT listings_latest_src_28000.is_lux AS listing__is_lux_latest - , users_latest_src_28000.home_state_latest AS user__home_state_latest + , subq_11.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 - FULL OUTER JOIN - ***************************.dim_users_latest users_latest_src_28000 + FULL OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_9.user + , home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + home_state_latest + , home_state_latest AS user__home_state_latest + , user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_9 + WHERE user__home_state_latest = 'us' + ) subq_11 ON - listings_latest_src_28000.user_id = users_latest_src_28000.user_id -) subq_8 + listings_latest_src_28000.user_id = subq_11.user +) subq_12 WHERE user__home_state_latest = 'us' GROUP BY listing__is_lux_latest diff --git a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimension_values_with_a_join_and_a_filter__plan0.sql b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimension_values_with_a_join_and_a_filter__plan0.sql index 90b66576dd..88bb3740a1 100644 --- a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimension_values_with_a_join_and_a_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimension_values_with_a_join_and_a_filter__plan0.sql @@ -1,127 +1,127 @@ -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest'] SELECT - subq_4.listing__is_lux_latest - , subq_4.user__home_state_latest + subq_7.listing__is_lux_latest + , subq_7.user__home_state_latest FROM ( -- Constrain Output with WHERE SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.user__home_state_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing + 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.created_at__day + , subq_6.created_at__week + , subq_6.created_at__month + , subq_6.created_at__quarter + , subq_6.created_at__year + , subq_6.created_at__extract_year + , subq_6.created_at__extract_quarter + , subq_6.created_at__extract_month + , subq_6.created_at__extract_day + , subq_6.created_at__extract_dow + , subq_6.created_at__extract_doy + , subq_6.listing__ds__day + , subq_6.listing__ds__week + , subq_6.listing__ds__month + , subq_6.listing__ds__quarter + , subq_6.listing__ds__year + , subq_6.listing__ds__extract_year + , subq_6.listing__ds__extract_quarter + , subq_6.listing__ds__extract_month + , subq_6.listing__ds__extract_day + , subq_6.listing__ds__extract_dow + , subq_6.listing__ds__extract_doy + , subq_6.listing__created_at__day + , subq_6.listing__created_at__week + , subq_6.listing__created_at__month + , subq_6.listing__created_at__quarter + , subq_6.listing__created_at__year + , subq_6.listing__created_at__extract_year + , subq_6.listing__created_at__extract_quarter + , subq_6.listing__created_at__extract_month + , subq_6.listing__created_at__extract_day + , subq_6.listing__created_at__extract_dow + , subq_6.listing__created_at__extract_doy + , subq_6.listing + , subq_6.user + , subq_6.listing__user + , subq_6.country_latest + , subq_6.is_lux_latest + , subq_6.capacity_latest + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.user__home_state_latest + , subq_6.listings + , subq_6.largest_listing + , subq_6.smallest_listing FROM ( -- Join Standard Outputs SELECT - subq_0.ds__day AS ds__day - , subq_0.ds__week AS ds__week - , subq_0.ds__month AS ds__month - , subq_0.ds__quarter AS ds__quarter - , subq_0.ds__year AS ds__year - , subq_0.ds__extract_year AS ds__extract_year - , subq_0.ds__extract_quarter AS ds__extract_quarter - , subq_0.ds__extract_month AS ds__extract_month - , subq_0.ds__extract_day AS ds__extract_day - , subq_0.ds__extract_dow AS ds__extract_dow - , subq_0.ds__extract_doy AS ds__extract_doy - , subq_0.created_at__day AS created_at__day - , subq_0.created_at__week AS created_at__week - , subq_0.created_at__month AS created_at__month - , subq_0.created_at__quarter AS created_at__quarter - , subq_0.created_at__year AS created_at__year - , subq_0.created_at__extract_year AS created_at__extract_year - , subq_0.created_at__extract_quarter AS created_at__extract_quarter - , subq_0.created_at__extract_month AS created_at__extract_month - , subq_0.created_at__extract_day AS created_at__extract_day - , subq_0.created_at__extract_dow AS created_at__extract_dow - , subq_0.created_at__extract_doy AS created_at__extract_doy - , subq_0.listing__ds__day AS listing__ds__day - , subq_0.listing__ds__week AS listing__ds__week - , subq_0.listing__ds__month AS listing__ds__month - , subq_0.listing__ds__quarter AS listing__ds__quarter - , subq_0.listing__ds__year AS listing__ds__year - , subq_0.listing__ds__extract_year AS listing__ds__extract_year - , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter - , subq_0.listing__ds__extract_month AS listing__ds__extract_month - , subq_0.listing__ds__extract_day AS listing__ds__extract_day - , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow - , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy - , subq_0.listing__created_at__day AS listing__created_at__day - , subq_0.listing__created_at__week AS listing__created_at__week - , subq_0.listing__created_at__month AS listing__created_at__month - , subq_0.listing__created_at__quarter AS listing__created_at__quarter - , subq_0.listing__created_at__year AS listing__created_at__year - , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month - , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow - , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy - , subq_0.listing AS listing - , subq_0.user AS user - , subq_0.listing__user AS listing__user - , subq_0.country_latest AS country_latest - , subq_0.is_lux_latest AS is_lux_latest - , subq_0.capacity_latest AS capacity_latest - , subq_0.listing__country_latest AS listing__country_latest - , subq_0.listing__is_lux_latest AS listing__is_lux_latest - , subq_0.listing__capacity_latest AS listing__capacity_latest - , subq_2.home_state_latest AS user__home_state_latest - , subq_0.listings AS listings - , subq_0.largest_listing AS largest_listing - , subq_0.smallest_listing AS smallest_listing + subq_2.ds__day AS ds__day + , subq_2.ds__week AS ds__week + , subq_2.ds__month AS ds__month + , subq_2.ds__quarter AS ds__quarter + , subq_2.ds__year AS ds__year + , subq_2.ds__extract_year AS ds__extract_year + , subq_2.ds__extract_quarter AS ds__extract_quarter + , subq_2.ds__extract_month AS ds__extract_month + , subq_2.ds__extract_day AS ds__extract_day + , subq_2.ds__extract_dow AS ds__extract_dow + , subq_2.ds__extract_doy AS ds__extract_doy + , subq_2.created_at__day AS created_at__day + , subq_2.created_at__week AS created_at__week + , subq_2.created_at__month AS created_at__month + , subq_2.created_at__quarter AS created_at__quarter + , subq_2.created_at__year AS created_at__year + , subq_2.created_at__extract_year AS created_at__extract_year + , subq_2.created_at__extract_quarter AS created_at__extract_quarter + , subq_2.created_at__extract_month AS created_at__extract_month + , subq_2.created_at__extract_day AS created_at__extract_day + , subq_2.created_at__extract_dow AS created_at__extract_dow + , subq_2.created_at__extract_doy AS created_at__extract_doy + , subq_2.listing__ds__day AS listing__ds__day + , subq_2.listing__ds__week AS listing__ds__week + , subq_2.listing__ds__month AS listing__ds__month + , subq_2.listing__ds__quarter AS listing__ds__quarter + , subq_2.listing__ds__year AS listing__ds__year + , subq_2.listing__ds__extract_year AS listing__ds__extract_year + , subq_2.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_2.listing__ds__extract_month AS listing__ds__extract_month + , subq_2.listing__ds__extract_day AS listing__ds__extract_day + , subq_2.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_2.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_2.listing__created_at__day AS listing__created_at__day + , subq_2.listing__created_at__week AS listing__created_at__week + , subq_2.listing__created_at__month AS listing__created_at__month + , subq_2.listing__created_at__quarter AS listing__created_at__quarter + , subq_2.listing__created_at__year AS listing__created_at__year + , subq_2.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_2.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_2.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_2.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_2.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_2.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_2.listing AS listing + , subq_2.user AS user + , subq_2.listing__user AS listing__user + , subq_2.country_latest AS country_latest + , subq_2.is_lux_latest AS is_lux_latest + , subq_2.capacity_latest AS capacity_latest + , subq_2.listing__country_latest AS listing__country_latest + , subq_2.listing__is_lux_latest AS listing__is_lux_latest + , subq_2.listing__capacity_latest AS listing__capacity_latest + , subq_5.home_state_latest AS user__home_state_latest + , subq_2.listings AS listings + , subq_2.largest_listing AS largest_listing + , subq_2.smallest_listing AS smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -182,48 +182,78 @@ FROM ( , listings_latest_src_28000.user_id AS user , listings_latest_src_28000.user_id AS listing__user FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_0 + ) subq_2 FULL OUTER JOIN ( -- Pass Only Elements: ['home_state_latest', 'user'] SELECT - subq_1.user - , subq_1.home_state_latest + subq_4.user + , subq_4.home_state_latest FROM ( - -- Read Elements From Semantic Model 'users_latest' + -- Constrain Output with WHERE SELECT - DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy - , users_latest_src_28000.home_state_latest - , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy - , users_latest_src_28000.home_state_latest AS user__home_state_latest - , users_latest_src_28000.user_id AS user - FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_1 - ) subq_2 + subq_3.ds_latest__day + , subq_3.ds_latest__week + , subq_3.ds_latest__month + , subq_3.ds_latest__quarter + , subq_3.ds_latest__year + , subq_3.ds_latest__extract_year + , subq_3.ds_latest__extract_quarter + , subq_3.ds_latest__extract_month + , subq_3.ds_latest__extract_day + , subq_3.ds_latest__extract_dow + , subq_3.ds_latest__extract_doy + , subq_3.user__ds_latest__day + , subq_3.user__ds_latest__week + , subq_3.user__ds_latest__month + , subq_3.user__ds_latest__quarter + , subq_3.user__ds_latest__year + , subq_3.user__ds_latest__extract_year + , subq_3.user__ds_latest__extract_quarter + , subq_3.user__ds_latest__extract_month + , subq_3.user__ds_latest__extract_day + , subq_3.user__ds_latest__extract_dow + , subq_3.user__ds_latest__extract_doy + , subq_3.user + , subq_3.home_state_latest + , subq_3.user__home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + WHERE user__home_state_latest = 'us' + ) subq_4 + ) subq_5 ON - subq_0.user = subq_2.user - ) subq_3 + subq_2.user = subq_5.user + ) subq_6 WHERE user__home_state_latest = 'us' -) subq_4 +) subq_7 GROUP BY - subq_4.listing__is_lux_latest - , subq_4.user__home_state_latest + subq_7.listing__is_lux_latest + , subq_7.user__home_state_latest diff --git a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql index e54eaffeb6..c77b46c217 100644 --- a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql @@ -7,13 +7,27 @@ FROM ( -- Join Standard Outputs SELECT listings_latest_src_28000.is_lux AS listing__is_lux_latest - , users_latest_src_28000.home_state_latest AS user__home_state_latest + , subq_11.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 - FULL OUTER JOIN - ***************************.dim_users_latest users_latest_src_28000 + FULL OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_9.user + , home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + home_state_latest + , home_state_latest AS user__home_state_latest + , user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_9 + WHERE user__home_state_latest = 'us' + ) subq_11 ON - listings_latest_src_28000.user_id = users_latest_src_28000.user_id -) subq_8 + listings_latest_src_28000.user_id = subq_11.user +) subq_12 WHERE user__home_state_latest = 'us' GROUP BY listing__is_lux_latest diff --git a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimension_values_with_a_join_and_a_filter__plan0.sql b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimension_values_with_a_join_and_a_filter__plan0.sql index d736ad0d03..77721d6e67 100644 --- a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimension_values_with_a_join_and_a_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimension_values_with_a_join_and_a_filter__plan0.sql @@ -1,127 +1,127 @@ -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest'] SELECT - subq_4.listing__is_lux_latest - , subq_4.user__home_state_latest + subq_7.listing__is_lux_latest + , subq_7.user__home_state_latest FROM ( -- Constrain Output with WHERE SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.user__home_state_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing + 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.created_at__day + , subq_6.created_at__week + , subq_6.created_at__month + , subq_6.created_at__quarter + , subq_6.created_at__year + , subq_6.created_at__extract_year + , subq_6.created_at__extract_quarter + , subq_6.created_at__extract_month + , subq_6.created_at__extract_day + , subq_6.created_at__extract_dow + , subq_6.created_at__extract_doy + , subq_6.listing__ds__day + , subq_6.listing__ds__week + , subq_6.listing__ds__month + , subq_6.listing__ds__quarter + , subq_6.listing__ds__year + , subq_6.listing__ds__extract_year + , subq_6.listing__ds__extract_quarter + , subq_6.listing__ds__extract_month + , subq_6.listing__ds__extract_day + , subq_6.listing__ds__extract_dow + , subq_6.listing__ds__extract_doy + , subq_6.listing__created_at__day + , subq_6.listing__created_at__week + , subq_6.listing__created_at__month + , subq_6.listing__created_at__quarter + , subq_6.listing__created_at__year + , subq_6.listing__created_at__extract_year + , subq_6.listing__created_at__extract_quarter + , subq_6.listing__created_at__extract_month + , subq_6.listing__created_at__extract_day + , subq_6.listing__created_at__extract_dow + , subq_6.listing__created_at__extract_doy + , subq_6.listing + , subq_6.user + , subq_6.listing__user + , subq_6.country_latest + , subq_6.is_lux_latest + , subq_6.capacity_latest + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.user__home_state_latest + , subq_6.listings + , subq_6.largest_listing + , subq_6.smallest_listing FROM ( -- Join Standard Outputs SELECT - subq_0.ds__day AS ds__day - , subq_0.ds__week AS ds__week - , subq_0.ds__month AS ds__month - , subq_0.ds__quarter AS ds__quarter - , subq_0.ds__year AS ds__year - , subq_0.ds__extract_year AS ds__extract_year - , subq_0.ds__extract_quarter AS ds__extract_quarter - , subq_0.ds__extract_month AS ds__extract_month - , subq_0.ds__extract_day AS ds__extract_day - , subq_0.ds__extract_dow AS ds__extract_dow - , subq_0.ds__extract_doy AS ds__extract_doy - , subq_0.created_at__day AS created_at__day - , subq_0.created_at__week AS created_at__week - , subq_0.created_at__month AS created_at__month - , subq_0.created_at__quarter AS created_at__quarter - , subq_0.created_at__year AS created_at__year - , subq_0.created_at__extract_year AS created_at__extract_year - , subq_0.created_at__extract_quarter AS created_at__extract_quarter - , subq_0.created_at__extract_month AS created_at__extract_month - , subq_0.created_at__extract_day AS created_at__extract_day - , subq_0.created_at__extract_dow AS created_at__extract_dow - , subq_0.created_at__extract_doy AS created_at__extract_doy - , subq_0.listing__ds__day AS listing__ds__day - , subq_0.listing__ds__week AS listing__ds__week - , subq_0.listing__ds__month AS listing__ds__month - , subq_0.listing__ds__quarter AS listing__ds__quarter - , subq_0.listing__ds__year AS listing__ds__year - , subq_0.listing__ds__extract_year AS listing__ds__extract_year - , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter - , subq_0.listing__ds__extract_month AS listing__ds__extract_month - , subq_0.listing__ds__extract_day AS listing__ds__extract_day - , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow - , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy - , subq_0.listing__created_at__day AS listing__created_at__day - , subq_0.listing__created_at__week AS listing__created_at__week - , subq_0.listing__created_at__month AS listing__created_at__month - , subq_0.listing__created_at__quarter AS listing__created_at__quarter - , subq_0.listing__created_at__year AS listing__created_at__year - , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month - , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow - , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy - , subq_0.listing AS listing - , subq_0.user AS user - , subq_0.listing__user AS listing__user - , subq_0.country_latest AS country_latest - , subq_0.is_lux_latest AS is_lux_latest - , subq_0.capacity_latest AS capacity_latest - , subq_0.listing__country_latest AS listing__country_latest - , subq_0.listing__is_lux_latest AS listing__is_lux_latest - , subq_0.listing__capacity_latest AS listing__capacity_latest - , subq_2.home_state_latest AS user__home_state_latest - , subq_0.listings AS listings - , subq_0.largest_listing AS largest_listing - , subq_0.smallest_listing AS smallest_listing + subq_2.ds__day AS ds__day + , subq_2.ds__week AS ds__week + , subq_2.ds__month AS ds__month + , subq_2.ds__quarter AS ds__quarter + , subq_2.ds__year AS ds__year + , subq_2.ds__extract_year AS ds__extract_year + , subq_2.ds__extract_quarter AS ds__extract_quarter + , subq_2.ds__extract_month AS ds__extract_month + , subq_2.ds__extract_day AS ds__extract_day + , subq_2.ds__extract_dow AS ds__extract_dow + , subq_2.ds__extract_doy AS ds__extract_doy + , subq_2.created_at__day AS created_at__day + , subq_2.created_at__week AS created_at__week + , subq_2.created_at__month AS created_at__month + , subq_2.created_at__quarter AS created_at__quarter + , subq_2.created_at__year AS created_at__year + , subq_2.created_at__extract_year AS created_at__extract_year + , subq_2.created_at__extract_quarter AS created_at__extract_quarter + , subq_2.created_at__extract_month AS created_at__extract_month + , subq_2.created_at__extract_day AS created_at__extract_day + , subq_2.created_at__extract_dow AS created_at__extract_dow + , subq_2.created_at__extract_doy AS created_at__extract_doy + , subq_2.listing__ds__day AS listing__ds__day + , subq_2.listing__ds__week AS listing__ds__week + , subq_2.listing__ds__month AS listing__ds__month + , subq_2.listing__ds__quarter AS listing__ds__quarter + , subq_2.listing__ds__year AS listing__ds__year + , subq_2.listing__ds__extract_year AS listing__ds__extract_year + , subq_2.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_2.listing__ds__extract_month AS listing__ds__extract_month + , subq_2.listing__ds__extract_day AS listing__ds__extract_day + , subq_2.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_2.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_2.listing__created_at__day AS listing__created_at__day + , subq_2.listing__created_at__week AS listing__created_at__week + , subq_2.listing__created_at__month AS listing__created_at__month + , subq_2.listing__created_at__quarter AS listing__created_at__quarter + , subq_2.listing__created_at__year AS listing__created_at__year + , subq_2.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_2.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_2.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_2.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_2.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_2.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_2.listing AS listing + , subq_2.user AS user + , subq_2.listing__user AS listing__user + , subq_2.country_latest AS country_latest + , subq_2.is_lux_latest AS is_lux_latest + , subq_2.capacity_latest AS capacity_latest + , subq_2.listing__country_latest AS listing__country_latest + , subq_2.listing__is_lux_latest AS listing__is_lux_latest + , subq_2.listing__capacity_latest AS listing__capacity_latest + , subq_5.home_state_latest AS user__home_state_latest + , subq_2.listings AS listings + , subq_2.largest_listing AS largest_listing + , subq_2.smallest_listing AS smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -182,48 +182,78 @@ FROM ( , listings_latest_src_28000.user_id AS user , listings_latest_src_28000.user_id AS listing__user FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_0 + ) subq_2 FULL OUTER JOIN ( -- Pass Only Elements: ['home_state_latest', 'user'] SELECT - subq_1.user - , subq_1.home_state_latest + subq_4.user + , subq_4.home_state_latest FROM ( - -- Read Elements From Semantic Model 'users_latest' + -- Constrain Output with WHERE SELECT - DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day - , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy - , users_latest_src_28000.home_state_latest - , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day - , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy - , users_latest_src_28000.home_state_latest AS user__home_state_latest - , users_latest_src_28000.user_id AS user - FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_1 - ) subq_2 + subq_3.ds_latest__day + , subq_3.ds_latest__week + , subq_3.ds_latest__month + , subq_3.ds_latest__quarter + , subq_3.ds_latest__year + , subq_3.ds_latest__extract_year + , subq_3.ds_latest__extract_quarter + , subq_3.ds_latest__extract_month + , subq_3.ds_latest__extract_day + , subq_3.ds_latest__extract_dow + , subq_3.ds_latest__extract_doy + , subq_3.user__ds_latest__day + , subq_3.user__ds_latest__week + , subq_3.user__ds_latest__month + , subq_3.user__ds_latest__quarter + , subq_3.user__ds_latest__year + , subq_3.user__ds_latest__extract_year + , subq_3.user__ds_latest__extract_quarter + , subq_3.user__ds_latest__extract_month + , subq_3.user__ds_latest__extract_day + , subq_3.user__ds_latest__extract_dow + , subq_3.user__ds_latest__extract_doy + , subq_3.user + , subq_3.home_state_latest + , subq_3.user__home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + WHERE user__home_state_latest = 'us' + ) subq_4 + ) subq_5 ON - subq_0.user = subq_2.user - ) subq_3 + subq_2.user = subq_5.user + ) subq_6 WHERE user__home_state_latest = 'us' -) subq_4 +) subq_7 GROUP BY - subq_4.listing__is_lux_latest - , subq_4.user__home_state_latest + subq_7.listing__is_lux_latest + , subq_7.user__home_state_latest diff --git a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql index e54eaffeb6..c77b46c217 100644 --- a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql @@ -7,13 +7,27 @@ FROM ( -- Join Standard Outputs SELECT listings_latest_src_28000.is_lux AS listing__is_lux_latest - , users_latest_src_28000.home_state_latest AS user__home_state_latest + , subq_11.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 - FULL OUTER JOIN - ***************************.dim_users_latest users_latest_src_28000 + FULL OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_9.user + , home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + home_state_latest + , home_state_latest AS user__home_state_latest + , user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_9 + WHERE user__home_state_latest = 'us' + ) subq_11 ON - listings_latest_src_28000.user_id = users_latest_src_28000.user_id -) subq_8 + listings_latest_src_28000.user_id = subq_11.user +) subq_12 WHERE user__home_state_latest = 'us' GROUP BY listing__is_lux_latest diff --git a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimension_values_with_a_join_and_a_filter__plan0.sql b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimension_values_with_a_join_and_a_filter__plan0.sql index 2444ef1956..78cd0f7b4d 100644 --- a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimension_values_with_a_join_and_a_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimension_values_with_a_join_and_a_filter__plan0.sql @@ -1,127 +1,127 @@ -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest'] SELECT - subq_4.listing__is_lux_latest - , subq_4.user__home_state_latest + subq_7.listing__is_lux_latest + , subq_7.user__home_state_latest FROM ( -- Constrain Output with WHERE SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.user__home_state_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing + 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.created_at__day + , subq_6.created_at__week + , subq_6.created_at__month + , subq_6.created_at__quarter + , subq_6.created_at__year + , subq_6.created_at__extract_year + , subq_6.created_at__extract_quarter + , subq_6.created_at__extract_month + , subq_6.created_at__extract_day + , subq_6.created_at__extract_dow + , subq_6.created_at__extract_doy + , subq_6.listing__ds__day + , subq_6.listing__ds__week + , subq_6.listing__ds__month + , subq_6.listing__ds__quarter + , subq_6.listing__ds__year + , subq_6.listing__ds__extract_year + , subq_6.listing__ds__extract_quarter + , subq_6.listing__ds__extract_month + , subq_6.listing__ds__extract_day + , subq_6.listing__ds__extract_dow + , subq_6.listing__ds__extract_doy + , subq_6.listing__created_at__day + , subq_6.listing__created_at__week + , subq_6.listing__created_at__month + , subq_6.listing__created_at__quarter + , subq_6.listing__created_at__year + , subq_6.listing__created_at__extract_year + , subq_6.listing__created_at__extract_quarter + , subq_6.listing__created_at__extract_month + , subq_6.listing__created_at__extract_day + , subq_6.listing__created_at__extract_dow + , subq_6.listing__created_at__extract_doy + , subq_6.listing + , subq_6.user + , subq_6.listing__user + , subq_6.country_latest + , subq_6.is_lux_latest + , subq_6.capacity_latest + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.user__home_state_latest + , subq_6.listings + , subq_6.largest_listing + , subq_6.smallest_listing FROM ( -- Join Standard Outputs SELECT - subq_0.ds__day AS ds__day - , subq_0.ds__week AS ds__week - , subq_0.ds__month AS ds__month - , subq_0.ds__quarter AS ds__quarter - , subq_0.ds__year AS ds__year - , subq_0.ds__extract_year AS ds__extract_year - , subq_0.ds__extract_quarter AS ds__extract_quarter - , subq_0.ds__extract_month AS ds__extract_month - , subq_0.ds__extract_day AS ds__extract_day - , subq_0.ds__extract_dow AS ds__extract_dow - , subq_0.ds__extract_doy AS ds__extract_doy - , subq_0.created_at__day AS created_at__day - , subq_0.created_at__week AS created_at__week - , subq_0.created_at__month AS created_at__month - , subq_0.created_at__quarter AS created_at__quarter - , subq_0.created_at__year AS created_at__year - , subq_0.created_at__extract_year AS created_at__extract_year - , subq_0.created_at__extract_quarter AS created_at__extract_quarter - , subq_0.created_at__extract_month AS created_at__extract_month - , subq_0.created_at__extract_day AS created_at__extract_day - , subq_0.created_at__extract_dow AS created_at__extract_dow - , subq_0.created_at__extract_doy AS created_at__extract_doy - , subq_0.listing__ds__day AS listing__ds__day - , subq_0.listing__ds__week AS listing__ds__week - , subq_0.listing__ds__month AS listing__ds__month - , subq_0.listing__ds__quarter AS listing__ds__quarter - , subq_0.listing__ds__year AS listing__ds__year - , subq_0.listing__ds__extract_year AS listing__ds__extract_year - , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter - , subq_0.listing__ds__extract_month AS listing__ds__extract_month - , subq_0.listing__ds__extract_day AS listing__ds__extract_day - , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow - , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy - , subq_0.listing__created_at__day AS listing__created_at__day - , subq_0.listing__created_at__week AS listing__created_at__week - , subq_0.listing__created_at__month AS listing__created_at__month - , subq_0.listing__created_at__quarter AS listing__created_at__quarter - , subq_0.listing__created_at__year AS listing__created_at__year - , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month - , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow - , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy - , subq_0.listing AS listing - , subq_0.user AS user - , subq_0.listing__user AS listing__user - , subq_0.country_latest AS country_latest - , subq_0.is_lux_latest AS is_lux_latest - , subq_0.capacity_latest AS capacity_latest - , subq_0.listing__country_latest AS listing__country_latest - , subq_0.listing__is_lux_latest AS listing__is_lux_latest - , subq_0.listing__capacity_latest AS listing__capacity_latest - , subq_2.home_state_latest AS user__home_state_latest - , subq_0.listings AS listings - , subq_0.largest_listing AS largest_listing - , subq_0.smallest_listing AS smallest_listing + subq_2.ds__day AS ds__day + , subq_2.ds__week AS ds__week + , subq_2.ds__month AS ds__month + , subq_2.ds__quarter AS ds__quarter + , subq_2.ds__year AS ds__year + , subq_2.ds__extract_year AS ds__extract_year + , subq_2.ds__extract_quarter AS ds__extract_quarter + , subq_2.ds__extract_month AS ds__extract_month + , subq_2.ds__extract_day AS ds__extract_day + , subq_2.ds__extract_dow AS ds__extract_dow + , subq_2.ds__extract_doy AS ds__extract_doy + , subq_2.created_at__day AS created_at__day + , subq_2.created_at__week AS created_at__week + , subq_2.created_at__month AS created_at__month + , subq_2.created_at__quarter AS created_at__quarter + , subq_2.created_at__year AS created_at__year + , subq_2.created_at__extract_year AS created_at__extract_year + , subq_2.created_at__extract_quarter AS created_at__extract_quarter + , subq_2.created_at__extract_month AS created_at__extract_month + , subq_2.created_at__extract_day AS created_at__extract_day + , subq_2.created_at__extract_dow AS created_at__extract_dow + , subq_2.created_at__extract_doy AS created_at__extract_doy + , subq_2.listing__ds__day AS listing__ds__day + , subq_2.listing__ds__week AS listing__ds__week + , subq_2.listing__ds__month AS listing__ds__month + , subq_2.listing__ds__quarter AS listing__ds__quarter + , subq_2.listing__ds__year AS listing__ds__year + , subq_2.listing__ds__extract_year AS listing__ds__extract_year + , subq_2.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_2.listing__ds__extract_month AS listing__ds__extract_month + , subq_2.listing__ds__extract_day AS listing__ds__extract_day + , subq_2.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_2.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_2.listing__created_at__day AS listing__created_at__day + , subq_2.listing__created_at__week AS listing__created_at__week + , subq_2.listing__created_at__month AS listing__created_at__month + , subq_2.listing__created_at__quarter AS listing__created_at__quarter + , subq_2.listing__created_at__year AS listing__created_at__year + , subq_2.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_2.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_2.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_2.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_2.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_2.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_2.listing AS listing + , subq_2.user AS user + , subq_2.listing__user AS listing__user + , subq_2.country_latest AS country_latest + , subq_2.is_lux_latest AS is_lux_latest + , subq_2.capacity_latest AS capacity_latest + , subq_2.listing__country_latest AS listing__country_latest + , subq_2.listing__is_lux_latest AS listing__is_lux_latest + , subq_2.listing__capacity_latest AS listing__capacity_latest + , subq_5.home_state_latest AS user__home_state_latest + , subq_2.listings AS listings + , subq_2.largest_listing AS largest_listing + , subq_2.smallest_listing AS smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -182,48 +182,78 @@ FROM ( , listings_latest_src_28000.user_id AS user , listings_latest_src_28000.user_id AS listing__user FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_0 + ) subq_2 FULL OUTER JOIN ( -- Pass Only Elements: ['home_state_latest', 'user'] SELECT - subq_1.user - , subq_1.home_state_latest + subq_4.user + , subq_4.home_state_latest FROM ( - -- Read Elements From Semantic Model 'users_latest' + -- Constrain Output with WHERE SELECT - DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day - , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy - , users_latest_src_28000.home_state_latest - , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day - , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS user__ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy - , users_latest_src_28000.home_state_latest AS user__home_state_latest - , users_latest_src_28000.user_id AS user - FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_1 - ) subq_2 + subq_3.ds_latest__day + , subq_3.ds_latest__week + , subq_3.ds_latest__month + , subq_3.ds_latest__quarter + , subq_3.ds_latest__year + , subq_3.ds_latest__extract_year + , subq_3.ds_latest__extract_quarter + , subq_3.ds_latest__extract_month + , subq_3.ds_latest__extract_day + , subq_3.ds_latest__extract_dow + , subq_3.ds_latest__extract_doy + , subq_3.user__ds_latest__day + , subq_3.user__ds_latest__week + , subq_3.user__ds_latest__month + , subq_3.user__ds_latest__quarter + , subq_3.user__ds_latest__year + , subq_3.user__ds_latest__extract_year + , subq_3.user__ds_latest__extract_quarter + , subq_3.user__ds_latest__extract_month + , subq_3.user__ds_latest__extract_day + , subq_3.user__ds_latest__extract_dow + , subq_3.user__ds_latest__extract_doy + , subq_3.user + , subq_3.home_state_latest + , subq_3.user__home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + WHERE user__home_state_latest = 'us' + ) subq_4 + ) subq_5 ON - subq_0.user = subq_2.user - ) subq_3 + subq_2.user = subq_5.user + ) subq_6 WHERE user__home_state_latest = 'us' -) subq_4 +) subq_7 GROUP BY - subq_4.listing__is_lux_latest - , subq_4.user__home_state_latest + subq_7.listing__is_lux_latest + , subq_7.user__home_state_latest diff --git a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql index e54eaffeb6..c77b46c217 100644 --- a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql @@ -7,13 +7,27 @@ FROM ( -- Join Standard Outputs SELECT listings_latest_src_28000.is_lux AS listing__is_lux_latest - , users_latest_src_28000.home_state_latest AS user__home_state_latest + , subq_11.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 - FULL OUTER JOIN - ***************************.dim_users_latest users_latest_src_28000 + FULL OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_9.user + , home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + home_state_latest + , home_state_latest AS user__home_state_latest + , user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_9 + WHERE user__home_state_latest = 'us' + ) subq_11 ON - listings_latest_src_28000.user_id = users_latest_src_28000.user_id -) subq_8 + listings_latest_src_28000.user_id = subq_11.user +) subq_12 WHERE user__home_state_latest = 'us' GROUP BY listing__is_lux_latest diff --git a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimension_values_with_a_join_and_a_filter__plan0.sql b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimension_values_with_a_join_and_a_filter__plan0.sql index fe092394e6..4d8a81ae07 100644 --- a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimension_values_with_a_join_and_a_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimension_values_with_a_join_and_a_filter__plan0.sql @@ -1,127 +1,127 @@ -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest'] SELECT - subq_4.listing__is_lux_latest - , subq_4.user__home_state_latest + subq_7.listing__is_lux_latest + , subq_7.user__home_state_latest FROM ( -- Constrain Output with WHERE SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.user__home_state_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing + 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.created_at__day + , subq_6.created_at__week + , subq_6.created_at__month + , subq_6.created_at__quarter + , subq_6.created_at__year + , subq_6.created_at__extract_year + , subq_6.created_at__extract_quarter + , subq_6.created_at__extract_month + , subq_6.created_at__extract_day + , subq_6.created_at__extract_dow + , subq_6.created_at__extract_doy + , subq_6.listing__ds__day + , subq_6.listing__ds__week + , subq_6.listing__ds__month + , subq_6.listing__ds__quarter + , subq_6.listing__ds__year + , subq_6.listing__ds__extract_year + , subq_6.listing__ds__extract_quarter + , subq_6.listing__ds__extract_month + , subq_6.listing__ds__extract_day + , subq_6.listing__ds__extract_dow + , subq_6.listing__ds__extract_doy + , subq_6.listing__created_at__day + , subq_6.listing__created_at__week + , subq_6.listing__created_at__month + , subq_6.listing__created_at__quarter + , subq_6.listing__created_at__year + , subq_6.listing__created_at__extract_year + , subq_6.listing__created_at__extract_quarter + , subq_6.listing__created_at__extract_month + , subq_6.listing__created_at__extract_day + , subq_6.listing__created_at__extract_dow + , subq_6.listing__created_at__extract_doy + , subq_6.listing + , subq_6.user + , subq_6.listing__user + , subq_6.country_latest + , subq_6.is_lux_latest + , subq_6.capacity_latest + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.user__home_state_latest + , subq_6.listings + , subq_6.largest_listing + , subq_6.smallest_listing FROM ( -- Join Standard Outputs SELECT - subq_0.ds__day AS ds__day - , subq_0.ds__week AS ds__week - , subq_0.ds__month AS ds__month - , subq_0.ds__quarter AS ds__quarter - , subq_0.ds__year AS ds__year - , subq_0.ds__extract_year AS ds__extract_year - , subq_0.ds__extract_quarter AS ds__extract_quarter - , subq_0.ds__extract_month AS ds__extract_month - , subq_0.ds__extract_day AS ds__extract_day - , subq_0.ds__extract_dow AS ds__extract_dow - , subq_0.ds__extract_doy AS ds__extract_doy - , subq_0.created_at__day AS created_at__day - , subq_0.created_at__week AS created_at__week - , subq_0.created_at__month AS created_at__month - , subq_0.created_at__quarter AS created_at__quarter - , subq_0.created_at__year AS created_at__year - , subq_0.created_at__extract_year AS created_at__extract_year - , subq_0.created_at__extract_quarter AS created_at__extract_quarter - , subq_0.created_at__extract_month AS created_at__extract_month - , subq_0.created_at__extract_day AS created_at__extract_day - , subq_0.created_at__extract_dow AS created_at__extract_dow - , subq_0.created_at__extract_doy AS created_at__extract_doy - , subq_0.listing__ds__day AS listing__ds__day - , subq_0.listing__ds__week AS listing__ds__week - , subq_0.listing__ds__month AS listing__ds__month - , subq_0.listing__ds__quarter AS listing__ds__quarter - , subq_0.listing__ds__year AS listing__ds__year - , subq_0.listing__ds__extract_year AS listing__ds__extract_year - , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter - , subq_0.listing__ds__extract_month AS listing__ds__extract_month - , subq_0.listing__ds__extract_day AS listing__ds__extract_day - , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow - , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy - , subq_0.listing__created_at__day AS listing__created_at__day - , subq_0.listing__created_at__week AS listing__created_at__week - , subq_0.listing__created_at__month AS listing__created_at__month - , subq_0.listing__created_at__quarter AS listing__created_at__quarter - , subq_0.listing__created_at__year AS listing__created_at__year - , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month - , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow - , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy - , subq_0.listing AS listing - , subq_0.user AS user - , subq_0.listing__user AS listing__user - , subq_0.country_latest AS country_latest - , subq_0.is_lux_latest AS is_lux_latest - , subq_0.capacity_latest AS capacity_latest - , subq_0.listing__country_latest AS listing__country_latest - , subq_0.listing__is_lux_latest AS listing__is_lux_latest - , subq_0.listing__capacity_latest AS listing__capacity_latest - , subq_2.home_state_latest AS user__home_state_latest - , subq_0.listings AS listings - , subq_0.largest_listing AS largest_listing - , subq_0.smallest_listing AS smallest_listing + subq_2.ds__day AS ds__day + , subq_2.ds__week AS ds__week + , subq_2.ds__month AS ds__month + , subq_2.ds__quarter AS ds__quarter + , subq_2.ds__year AS ds__year + , subq_2.ds__extract_year AS ds__extract_year + , subq_2.ds__extract_quarter AS ds__extract_quarter + , subq_2.ds__extract_month AS ds__extract_month + , subq_2.ds__extract_day AS ds__extract_day + , subq_2.ds__extract_dow AS ds__extract_dow + , subq_2.ds__extract_doy AS ds__extract_doy + , subq_2.created_at__day AS created_at__day + , subq_2.created_at__week AS created_at__week + , subq_2.created_at__month AS created_at__month + , subq_2.created_at__quarter AS created_at__quarter + , subq_2.created_at__year AS created_at__year + , subq_2.created_at__extract_year AS created_at__extract_year + , subq_2.created_at__extract_quarter AS created_at__extract_quarter + , subq_2.created_at__extract_month AS created_at__extract_month + , subq_2.created_at__extract_day AS created_at__extract_day + , subq_2.created_at__extract_dow AS created_at__extract_dow + , subq_2.created_at__extract_doy AS created_at__extract_doy + , subq_2.listing__ds__day AS listing__ds__day + , subq_2.listing__ds__week AS listing__ds__week + , subq_2.listing__ds__month AS listing__ds__month + , subq_2.listing__ds__quarter AS listing__ds__quarter + , subq_2.listing__ds__year AS listing__ds__year + , subq_2.listing__ds__extract_year AS listing__ds__extract_year + , subq_2.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_2.listing__ds__extract_month AS listing__ds__extract_month + , subq_2.listing__ds__extract_day AS listing__ds__extract_day + , subq_2.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_2.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_2.listing__created_at__day AS listing__created_at__day + , subq_2.listing__created_at__week AS listing__created_at__week + , subq_2.listing__created_at__month AS listing__created_at__month + , subq_2.listing__created_at__quarter AS listing__created_at__quarter + , subq_2.listing__created_at__year AS listing__created_at__year + , subq_2.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_2.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_2.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_2.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_2.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_2.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_2.listing AS listing + , subq_2.user AS user + , subq_2.listing__user AS listing__user + , subq_2.country_latest AS country_latest + , subq_2.is_lux_latest AS is_lux_latest + , subq_2.capacity_latest AS capacity_latest + , subq_2.listing__country_latest AS listing__country_latest + , subq_2.listing__is_lux_latest AS listing__is_lux_latest + , subq_2.listing__capacity_latest AS listing__capacity_latest + , subq_5.home_state_latest AS user__home_state_latest + , subq_2.listings AS listings + , subq_2.largest_listing AS largest_listing + , subq_2.smallest_listing AS smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -182,48 +182,78 @@ FROM ( , listings_latest_src_28000.user_id AS user , listings_latest_src_28000.user_id AS listing__user FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_0 + ) subq_2 FULL OUTER JOIN ( -- Pass Only Elements: ['home_state_latest', 'user'] SELECT - subq_1.user - , subq_1.home_state_latest + subq_4.user + , subq_4.home_state_latest FROM ( - -- Read Elements From Semantic Model 'users_latest' + -- Constrain Output with WHERE SELECT - DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day - , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy - , users_latest_src_28000.home_state_latest - , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day - , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy - , users_latest_src_28000.home_state_latest AS user__home_state_latest - , users_latest_src_28000.user_id AS user - FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_1 - ) subq_2 + subq_3.ds_latest__day + , subq_3.ds_latest__week + , subq_3.ds_latest__month + , subq_3.ds_latest__quarter + , subq_3.ds_latest__year + , subq_3.ds_latest__extract_year + , subq_3.ds_latest__extract_quarter + , subq_3.ds_latest__extract_month + , subq_3.ds_latest__extract_day + , subq_3.ds_latest__extract_dow + , subq_3.ds_latest__extract_doy + , subq_3.user__ds_latest__day + , subq_3.user__ds_latest__week + , subq_3.user__ds_latest__month + , subq_3.user__ds_latest__quarter + , subq_3.user__ds_latest__year + , subq_3.user__ds_latest__extract_year + , subq_3.user__ds_latest__extract_quarter + , subq_3.user__ds_latest__extract_month + , subq_3.user__ds_latest__extract_day + , subq_3.user__ds_latest__extract_dow + , subq_3.user__ds_latest__extract_doy + , subq_3.user + , subq_3.home_state_latest + , subq_3.user__home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + WHERE user__home_state_latest = 'us' + ) subq_4 + ) subq_5 ON - subq_0.user = subq_2.user - ) subq_3 + subq_2.user = subq_5.user + ) subq_6 WHERE user__home_state_latest = 'us' -) subq_4 +) subq_7 GROUP BY - subq_4.listing__is_lux_latest - , subq_4.user__home_state_latest + subq_7.listing__is_lux_latest + , subq_7.user__home_state_latest diff --git a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql index e54eaffeb6..c77b46c217 100644 --- a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql @@ -7,13 +7,27 @@ FROM ( -- Join Standard Outputs SELECT listings_latest_src_28000.is_lux AS listing__is_lux_latest - , users_latest_src_28000.home_state_latest AS user__home_state_latest + , subq_11.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 - FULL OUTER JOIN - ***************************.dim_users_latest users_latest_src_28000 + FULL OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_9.user + , home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + home_state_latest + , home_state_latest AS user__home_state_latest + , user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_9 + WHERE user__home_state_latest = 'us' + ) subq_11 ON - listings_latest_src_28000.user_id = users_latest_src_28000.user_id -) subq_8 + listings_latest_src_28000.user_id = subq_11.user +) subq_12 WHERE user__home_state_latest = 'us' GROUP BY listing__is_lux_latest diff --git a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimension_values_with_a_join_and_a_filter__plan0.sql b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimension_values_with_a_join_and_a_filter__plan0.sql index 478b5d81be..4f779da15b 100644 --- a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimension_values_with_a_join_and_a_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimension_values_with_a_join_and_a_filter__plan0.sql @@ -1,127 +1,127 @@ -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest'] SELECT - subq_4.listing__is_lux_latest - , subq_4.user__home_state_latest + subq_7.listing__is_lux_latest + , subq_7.user__home_state_latest FROM ( -- Constrain Output with WHERE SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.user__home_state_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing + 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.created_at__day + , subq_6.created_at__week + , subq_6.created_at__month + , subq_6.created_at__quarter + , subq_6.created_at__year + , subq_6.created_at__extract_year + , subq_6.created_at__extract_quarter + , subq_6.created_at__extract_month + , subq_6.created_at__extract_day + , subq_6.created_at__extract_dow + , subq_6.created_at__extract_doy + , subq_6.listing__ds__day + , subq_6.listing__ds__week + , subq_6.listing__ds__month + , subq_6.listing__ds__quarter + , subq_6.listing__ds__year + , subq_6.listing__ds__extract_year + , subq_6.listing__ds__extract_quarter + , subq_6.listing__ds__extract_month + , subq_6.listing__ds__extract_day + , subq_6.listing__ds__extract_dow + , subq_6.listing__ds__extract_doy + , subq_6.listing__created_at__day + , subq_6.listing__created_at__week + , subq_6.listing__created_at__month + , subq_6.listing__created_at__quarter + , subq_6.listing__created_at__year + , subq_6.listing__created_at__extract_year + , subq_6.listing__created_at__extract_quarter + , subq_6.listing__created_at__extract_month + , subq_6.listing__created_at__extract_day + , subq_6.listing__created_at__extract_dow + , subq_6.listing__created_at__extract_doy + , subq_6.listing + , subq_6.user + , subq_6.listing__user + , subq_6.country_latest + , subq_6.is_lux_latest + , subq_6.capacity_latest + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.user__home_state_latest + , subq_6.listings + , subq_6.largest_listing + , subq_6.smallest_listing FROM ( -- Join Standard Outputs SELECT - subq_0.ds__day AS ds__day - , subq_0.ds__week AS ds__week - , subq_0.ds__month AS ds__month - , subq_0.ds__quarter AS ds__quarter - , subq_0.ds__year AS ds__year - , subq_0.ds__extract_year AS ds__extract_year - , subq_0.ds__extract_quarter AS ds__extract_quarter - , subq_0.ds__extract_month AS ds__extract_month - , subq_0.ds__extract_day AS ds__extract_day - , subq_0.ds__extract_dow AS ds__extract_dow - , subq_0.ds__extract_doy AS ds__extract_doy - , subq_0.created_at__day AS created_at__day - , subq_0.created_at__week AS created_at__week - , subq_0.created_at__month AS created_at__month - , subq_0.created_at__quarter AS created_at__quarter - , subq_0.created_at__year AS created_at__year - , subq_0.created_at__extract_year AS created_at__extract_year - , subq_0.created_at__extract_quarter AS created_at__extract_quarter - , subq_0.created_at__extract_month AS created_at__extract_month - , subq_0.created_at__extract_day AS created_at__extract_day - , subq_0.created_at__extract_dow AS created_at__extract_dow - , subq_0.created_at__extract_doy AS created_at__extract_doy - , subq_0.listing__ds__day AS listing__ds__day - , subq_0.listing__ds__week AS listing__ds__week - , subq_0.listing__ds__month AS listing__ds__month - , subq_0.listing__ds__quarter AS listing__ds__quarter - , subq_0.listing__ds__year AS listing__ds__year - , subq_0.listing__ds__extract_year AS listing__ds__extract_year - , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter - , subq_0.listing__ds__extract_month AS listing__ds__extract_month - , subq_0.listing__ds__extract_day AS listing__ds__extract_day - , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow - , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy - , subq_0.listing__created_at__day AS listing__created_at__day - , subq_0.listing__created_at__week AS listing__created_at__week - , subq_0.listing__created_at__month AS listing__created_at__month - , subq_0.listing__created_at__quarter AS listing__created_at__quarter - , subq_0.listing__created_at__year AS listing__created_at__year - , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month - , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow - , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy - , subq_0.listing AS listing - , subq_0.user AS user - , subq_0.listing__user AS listing__user - , subq_0.country_latest AS country_latest - , subq_0.is_lux_latest AS is_lux_latest - , subq_0.capacity_latest AS capacity_latest - , subq_0.listing__country_latest AS listing__country_latest - , subq_0.listing__is_lux_latest AS listing__is_lux_latest - , subq_0.listing__capacity_latest AS listing__capacity_latest - , subq_2.home_state_latest AS user__home_state_latest - , subq_0.listings AS listings - , subq_0.largest_listing AS largest_listing - , subq_0.smallest_listing AS smallest_listing + subq_2.ds__day AS ds__day + , subq_2.ds__week AS ds__week + , subq_2.ds__month AS ds__month + , subq_2.ds__quarter AS ds__quarter + , subq_2.ds__year AS ds__year + , subq_2.ds__extract_year AS ds__extract_year + , subq_2.ds__extract_quarter AS ds__extract_quarter + , subq_2.ds__extract_month AS ds__extract_month + , subq_2.ds__extract_day AS ds__extract_day + , subq_2.ds__extract_dow AS ds__extract_dow + , subq_2.ds__extract_doy AS ds__extract_doy + , subq_2.created_at__day AS created_at__day + , subq_2.created_at__week AS created_at__week + , subq_2.created_at__month AS created_at__month + , subq_2.created_at__quarter AS created_at__quarter + , subq_2.created_at__year AS created_at__year + , subq_2.created_at__extract_year AS created_at__extract_year + , subq_2.created_at__extract_quarter AS created_at__extract_quarter + , subq_2.created_at__extract_month AS created_at__extract_month + , subq_2.created_at__extract_day AS created_at__extract_day + , subq_2.created_at__extract_dow AS created_at__extract_dow + , subq_2.created_at__extract_doy AS created_at__extract_doy + , subq_2.listing__ds__day AS listing__ds__day + , subq_2.listing__ds__week AS listing__ds__week + , subq_2.listing__ds__month AS listing__ds__month + , subq_2.listing__ds__quarter AS listing__ds__quarter + , subq_2.listing__ds__year AS listing__ds__year + , subq_2.listing__ds__extract_year AS listing__ds__extract_year + , subq_2.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_2.listing__ds__extract_month AS listing__ds__extract_month + , subq_2.listing__ds__extract_day AS listing__ds__extract_day + , subq_2.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_2.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_2.listing__created_at__day AS listing__created_at__day + , subq_2.listing__created_at__week AS listing__created_at__week + , subq_2.listing__created_at__month AS listing__created_at__month + , subq_2.listing__created_at__quarter AS listing__created_at__quarter + , subq_2.listing__created_at__year AS listing__created_at__year + , subq_2.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_2.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_2.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_2.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_2.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_2.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_2.listing AS listing + , subq_2.user AS user + , subq_2.listing__user AS listing__user + , subq_2.country_latest AS country_latest + , subq_2.is_lux_latest AS is_lux_latest + , subq_2.capacity_latest AS capacity_latest + , subq_2.listing__country_latest AS listing__country_latest + , subq_2.listing__is_lux_latest AS listing__is_lux_latest + , subq_2.listing__capacity_latest AS listing__capacity_latest + , subq_5.home_state_latest AS user__home_state_latest + , subq_2.listings AS listings + , subq_2.largest_listing AS largest_listing + , subq_2.smallest_listing AS smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -182,48 +182,78 @@ FROM ( , listings_latest_src_28000.user_id AS user , listings_latest_src_28000.user_id AS listing__user FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_0 + ) subq_2 FULL OUTER JOIN ( -- Pass Only Elements: ['home_state_latest', 'user'] SELECT - subq_1.user - , subq_1.home_state_latest + subq_4.user + , subq_4.home_state_latest FROM ( - -- Read Elements From Semantic Model 'users_latest' + -- Constrain Output with WHERE SELECT - DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day - , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy - , users_latest_src_28000.home_state_latest - , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day - , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy - , users_latest_src_28000.home_state_latest AS user__home_state_latest - , users_latest_src_28000.user_id AS user - FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_1 - ) subq_2 + subq_3.ds_latest__day + , subq_3.ds_latest__week + , subq_3.ds_latest__month + , subq_3.ds_latest__quarter + , subq_3.ds_latest__year + , subq_3.ds_latest__extract_year + , subq_3.ds_latest__extract_quarter + , subq_3.ds_latest__extract_month + , subq_3.ds_latest__extract_day + , subq_3.ds_latest__extract_dow + , subq_3.ds_latest__extract_doy + , subq_3.user__ds_latest__day + , subq_3.user__ds_latest__week + , subq_3.user__ds_latest__month + , subq_3.user__ds_latest__quarter + , subq_3.user__ds_latest__year + , subq_3.user__ds_latest__extract_year + , subq_3.user__ds_latest__extract_quarter + , subq_3.user__ds_latest__extract_month + , subq_3.user__ds_latest__extract_day + , subq_3.user__ds_latest__extract_dow + , subq_3.user__ds_latest__extract_doy + , subq_3.user + , subq_3.home_state_latest + , subq_3.user__home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + WHERE user__home_state_latest = 'us' + ) subq_4 + ) subq_5 ON - subq_0.user = subq_2.user - ) subq_3 + subq_2.user = subq_5.user + ) subq_6 WHERE user__home_state_latest = 'us' -) subq_4 +) subq_7 GROUP BY - subq_4.listing__is_lux_latest - , subq_4.user__home_state_latest + subq_7.listing__is_lux_latest + , subq_7.user__home_state_latest diff --git a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql index e54eaffeb6..c77b46c217 100644 --- a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql @@ -7,13 +7,27 @@ FROM ( -- Join Standard Outputs SELECT listings_latest_src_28000.is_lux AS listing__is_lux_latest - , users_latest_src_28000.home_state_latest AS user__home_state_latest + , subq_11.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 - FULL OUTER JOIN - ***************************.dim_users_latest users_latest_src_28000 + FULL OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_9.user + , home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + home_state_latest + , home_state_latest AS user__home_state_latest + , user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_9 + WHERE user__home_state_latest = 'us' + ) subq_11 ON - listings_latest_src_28000.user_id = users_latest_src_28000.user_id -) subq_8 + listings_latest_src_28000.user_id = subq_11.user +) subq_12 WHERE user__home_state_latest = 'us' GROUP BY listing__is_lux_latest diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/BigQuery/test_inner_query_single_hop__plan0.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/BigQuery/test_inner_query_single_hop__plan0.sql index 153ad50485..eb8439edeb 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/BigQuery/test_inner_query_single_hop__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/BigQuery/test_inner_query_single_hop__plan0.sql @@ -1,76 +1,76 @@ -- Compute Metrics via Expressions SELECT - subq_21.third_hop_count + subq_27.third_hop_count FROM ( -- Aggregate Measures SELECT - COUNT(DISTINCT subq_20.third_hop_count) AS third_hop_count + COUNT(DISTINCT subq_26.third_hop_count) AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count',] SELECT - subq_19.third_hop_count + subq_25.third_hop_count FROM ( -- Constrain Output with WHERE SELECT - subq_18.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_18.third_hop_count + subq_24.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_24.third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_17.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_17.third_hop_count + subq_23.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_23.third_hop_count FROM ( -- Join Standard Outputs SELECT - subq_8.customer_third_hop_id AS customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_8.third_hop_count AS third_hop_count + subq_13.customer_third_hop_id AS customer_third_hop_id + , subq_22.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id + , subq_22.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_13.third_hop_count AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id'] SELECT - subq_7.customer_third_hop_id - , subq_7.third_hop_count + subq_12.customer_third_hop_id + , subq_12.third_hop_count FROM ( -- Metric Time Dimension 'third_hop_ds' SELECT - subq_6.third_hop_ds__day - , subq_6.third_hop_ds__week - , subq_6.third_hop_ds__month - , subq_6.third_hop_ds__quarter - , subq_6.third_hop_ds__year - , subq_6.third_hop_ds__extract_year - , subq_6.third_hop_ds__extract_quarter - , subq_6.third_hop_ds__extract_month - , subq_6.third_hop_ds__extract_day - , subq_6.third_hop_ds__extract_dow - , subq_6.third_hop_ds__extract_doy - , subq_6.customer_third_hop_id__third_hop_ds__day - , subq_6.customer_third_hop_id__third_hop_ds__week - , subq_6.customer_third_hop_id__third_hop_ds__month - , subq_6.customer_third_hop_id__third_hop_ds__quarter - , subq_6.customer_third_hop_id__third_hop_ds__year - , subq_6.customer_third_hop_id__third_hop_ds__extract_year - , subq_6.customer_third_hop_id__third_hop_ds__extract_quarter - , subq_6.customer_third_hop_id__third_hop_ds__extract_month - , subq_6.customer_third_hop_id__third_hop_ds__extract_day - , subq_6.customer_third_hop_id__third_hop_ds__extract_dow - , subq_6.customer_third_hop_id__third_hop_ds__extract_doy - , subq_6.third_hop_ds__day AS metric_time__day - , subq_6.third_hop_ds__week AS metric_time__week - , subq_6.third_hop_ds__month AS metric_time__month - , subq_6.third_hop_ds__quarter AS metric_time__quarter - , subq_6.third_hop_ds__year AS metric_time__year - , subq_6.third_hop_ds__extract_year AS metric_time__extract_year - , subq_6.third_hop_ds__extract_quarter AS metric_time__extract_quarter - , subq_6.third_hop_ds__extract_month AS metric_time__extract_month - , subq_6.third_hop_ds__extract_day AS metric_time__extract_day - , subq_6.third_hop_ds__extract_dow AS metric_time__extract_dow - , subq_6.third_hop_ds__extract_doy AS metric_time__extract_doy - , subq_6.customer_third_hop_id - , subq_6.value - , subq_6.customer_third_hop_id__value - , subq_6.third_hop_count + subq_11.third_hop_ds__day + , subq_11.third_hop_ds__week + , subq_11.third_hop_ds__month + , subq_11.third_hop_ds__quarter + , subq_11.third_hop_ds__year + , subq_11.third_hop_ds__extract_year + , subq_11.third_hop_ds__extract_quarter + , subq_11.third_hop_ds__extract_month + , subq_11.third_hop_ds__extract_day + , subq_11.third_hop_ds__extract_dow + , subq_11.third_hop_ds__extract_doy + , subq_11.customer_third_hop_id__third_hop_ds__day + , subq_11.customer_third_hop_id__third_hop_ds__week + , subq_11.customer_third_hop_id__third_hop_ds__month + , subq_11.customer_third_hop_id__third_hop_ds__quarter + , subq_11.customer_third_hop_id__third_hop_ds__year + , subq_11.customer_third_hop_id__third_hop_ds__extract_year + , subq_11.customer_third_hop_id__third_hop_ds__extract_quarter + , subq_11.customer_third_hop_id__third_hop_ds__extract_month + , subq_11.customer_third_hop_id__third_hop_ds__extract_day + , subq_11.customer_third_hop_id__third_hop_ds__extract_dow + , subq_11.customer_third_hop_id__third_hop_ds__extract_doy + , subq_11.third_hop_ds__day AS metric_time__day + , subq_11.third_hop_ds__week AS metric_time__week + , subq_11.third_hop_ds__month AS metric_time__month + , subq_11.third_hop_ds__quarter AS metric_time__quarter + , subq_11.third_hop_ds__year AS metric_time__year + , subq_11.third_hop_ds__extract_year AS metric_time__extract_year + , subq_11.third_hop_ds__extract_quarter AS metric_time__extract_quarter + , subq_11.third_hop_ds__extract_month AS metric_time__extract_month + , subq_11.third_hop_ds__extract_day AS metric_time__extract_day + , subq_11.third_hop_ds__extract_dow AS metric_time__extract_dow + , subq_11.third_hop_ds__extract_doy AS metric_time__extract_doy + , subq_11.customer_third_hop_id + , subq_11.value + , subq_11.customer_third_hop_id__value + , subq_11.third_hop_count FROM ( -- Read Elements From Semantic Model 'third_hop_table' SELECT @@ -101,157 +101,214 @@ FROM ( , EXTRACT(dayofyear FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_doy , third_hop_table_src_22000.customer_third_hop_id FROM ***************************.third_hop_table third_hop_table_src_22000 - ) subq_6 - ) subq_7 - ) subq_8 + ) subq_11 + ) subq_12 + ) subq_13 LEFT OUTER JOIN ( -- Pass Only Elements: ['customer_id__customer_third_hop_id', 'customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_15.customer_id__customer_third_hop_id - , subq_15.customer_id__customer_third_hop_id__paraguayan_customers + subq_21.customer_id__customer_third_hop_id + , subq_21.customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Compute Metrics via Expressions SELECT - subq_14.customer_id__customer_third_hop_id - , subq_14.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers + subq_20.customer_id__customer_third_hop_id + , subq_20.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Aggregate Measures SELECT - subq_13.customer_id__customer_third_hop_id - , SUM(subq_13.customers_with_other_data) AS customers_with_other_data + subq_19.customer_id__customer_third_hop_id + , SUM(subq_19.customers_with_other_data) AS customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__customer_third_hop_id'] SELECT - subq_12.customer_id__customer_third_hop_id - , subq_12.customers_with_other_data + subq_18.customer_id__customer_third_hop_id + , subq_18.customers_with_other_data FROM ( -- Constrain Output with WHERE SELECT - subq_11.customer_id__customer_third_hop_id - , subq_11.customer_id__country - , subq_11.customers_with_other_data + subq_17.customer_id__customer_third_hop_id + , subq_17.customer_id__country + , subq_17.customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - subq_10.customer_id__customer_third_hop_id - , subq_10.customer_id__country - , subq_10.customers_with_other_data + subq_16.customer_id__customer_third_hop_id + , subq_16.customer_id__country + , subq_16.customers_with_other_data FROM ( - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE SELECT - subq_9.acquired_ds__day - , subq_9.acquired_ds__week - , subq_9.acquired_ds__month - , subq_9.acquired_ds__quarter - , subq_9.acquired_ds__year - , subq_9.acquired_ds__extract_year - , subq_9.acquired_ds__extract_quarter - , subq_9.acquired_ds__extract_month - , subq_9.acquired_ds__extract_day - , subq_9.acquired_ds__extract_dow - , subq_9.acquired_ds__extract_doy - , subq_9.customer_id__acquired_ds__day - , subq_9.customer_id__acquired_ds__week - , subq_9.customer_id__acquired_ds__month - , subq_9.customer_id__acquired_ds__quarter - , subq_9.customer_id__acquired_ds__year - , subq_9.customer_id__acquired_ds__extract_year - , subq_9.customer_id__acquired_ds__extract_quarter - , subq_9.customer_id__acquired_ds__extract_month - , subq_9.customer_id__acquired_ds__extract_day - , subq_9.customer_id__acquired_ds__extract_dow - , subq_9.customer_id__acquired_ds__extract_doy - , subq_9.customer_third_hop_id__acquired_ds__day - , subq_9.customer_third_hop_id__acquired_ds__week - , subq_9.customer_third_hop_id__acquired_ds__month - , subq_9.customer_third_hop_id__acquired_ds__quarter - , subq_9.customer_third_hop_id__acquired_ds__year - , subq_9.customer_third_hop_id__acquired_ds__extract_year - , subq_9.customer_third_hop_id__acquired_ds__extract_quarter - , subq_9.customer_third_hop_id__acquired_ds__extract_month - , subq_9.customer_third_hop_id__acquired_ds__extract_day - , subq_9.customer_third_hop_id__acquired_ds__extract_dow - , subq_9.customer_third_hop_id__acquired_ds__extract_doy - , subq_9.acquired_ds__day AS metric_time__day - , subq_9.acquired_ds__week AS metric_time__week - , subq_9.acquired_ds__month AS metric_time__month - , subq_9.acquired_ds__quarter AS metric_time__quarter - , subq_9.acquired_ds__year AS metric_time__year - , subq_9.acquired_ds__extract_year AS metric_time__extract_year - , subq_9.acquired_ds__extract_quarter AS metric_time__extract_quarter - , subq_9.acquired_ds__extract_month AS metric_time__extract_month - , subq_9.acquired_ds__extract_day AS metric_time__extract_day - , subq_9.acquired_ds__extract_dow AS metric_time__extract_dow - , subq_9.acquired_ds__extract_doy AS metric_time__extract_doy - , subq_9.customer_id - , subq_9.customer_third_hop_id - , subq_9.customer_id__customer_third_hop_id - , subq_9.customer_third_hop_id__customer_id - , subq_9.country - , subq_9.customer_id__country - , subq_9.customer_third_hop_id__country - , subq_9.customers_with_other_data + subq_15.acquired_ds__day + , subq_15.acquired_ds__week + , subq_15.acquired_ds__month + , subq_15.acquired_ds__quarter + , subq_15.acquired_ds__year + , subq_15.acquired_ds__extract_year + , subq_15.acquired_ds__extract_quarter + , subq_15.acquired_ds__extract_month + , subq_15.acquired_ds__extract_day + , subq_15.acquired_ds__extract_dow + , subq_15.acquired_ds__extract_doy + , subq_15.customer_id__acquired_ds__day + , subq_15.customer_id__acquired_ds__week + , subq_15.customer_id__acquired_ds__month + , subq_15.customer_id__acquired_ds__quarter + , subq_15.customer_id__acquired_ds__year + , subq_15.customer_id__acquired_ds__extract_year + , subq_15.customer_id__acquired_ds__extract_quarter + , subq_15.customer_id__acquired_ds__extract_month + , subq_15.customer_id__acquired_ds__extract_day + , subq_15.customer_id__acquired_ds__extract_dow + , subq_15.customer_id__acquired_ds__extract_doy + , subq_15.customer_third_hop_id__acquired_ds__day + , subq_15.customer_third_hop_id__acquired_ds__week + , subq_15.customer_third_hop_id__acquired_ds__month + , subq_15.customer_third_hop_id__acquired_ds__quarter + , subq_15.customer_third_hop_id__acquired_ds__year + , subq_15.customer_third_hop_id__acquired_ds__extract_year + , subq_15.customer_third_hop_id__acquired_ds__extract_quarter + , subq_15.customer_third_hop_id__acquired_ds__extract_month + , subq_15.customer_third_hop_id__acquired_ds__extract_day + , subq_15.customer_third_hop_id__acquired_ds__extract_dow + , subq_15.customer_third_hop_id__acquired_ds__extract_doy + , subq_15.metric_time__day + , subq_15.metric_time__week + , subq_15.metric_time__month + , subq_15.metric_time__quarter + , subq_15.metric_time__year + , subq_15.metric_time__extract_year + , subq_15.metric_time__extract_quarter + , subq_15.metric_time__extract_month + , subq_15.metric_time__extract_day + , subq_15.metric_time__extract_dow + , subq_15.metric_time__extract_doy + , subq_15.customer_id + , subq_15.customer_third_hop_id + , subq_15.customer_id__customer_third_hop_id + , subq_15.customer_third_hop_id__customer_id + , subq_15.country + , subq_15.customer_id__country + , subq_15.customer_third_hop_id__country + , subq_15.customers_with_other_data FROM ( - -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' SELECT - 1 AS customers_with_other_data - , customer_other_data_src_22000.country - , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, day) AS acquired_ds__day - , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, isoweek) AS acquired_ds__week - , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, month) AS acquired_ds__month - , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, quarter) AS acquired_ds__quarter - , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, year) AS acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day - , IF(EXTRACT(dayofweek FROM customer_other_data_src_22000.acquired_ds) = 1, 7, EXTRACT(dayofweek FROM customer_other_data_src_22000.acquired_ds) - 1) AS acquired_ds__extract_dow - , EXTRACT(dayofyear FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_id__country - , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, day) AS customer_id__acquired_ds__day - , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, isoweek) AS customer_id__acquired_ds__week - , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, month) AS customer_id__acquired_ds__month - , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, quarter) AS customer_id__acquired_ds__quarter - , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, year) AS customer_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day - , IF(EXTRACT(dayofweek FROM customer_other_data_src_22000.acquired_ds) = 1, 7, EXTRACT(dayofweek FROM customer_other_data_src_22000.acquired_ds) - 1) AS customer_id__acquired_ds__extract_dow - , EXTRACT(dayofyear FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_third_hop_id__country - , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, day) AS customer_third_hop_id__acquired_ds__day - , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, isoweek) AS customer_third_hop_id__acquired_ds__week - , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, month) AS customer_third_hop_id__acquired_ds__month - , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, quarter) AS customer_third_hop_id__acquired_ds__quarter - , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, year) AS customer_third_hop_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day - , IF(EXTRACT(dayofweek FROM customer_other_data_src_22000.acquired_ds) = 1, 7, EXTRACT(dayofweek FROM customer_other_data_src_22000.acquired_ds) - 1) AS customer_third_hop_id__acquired_ds__extract_dow - , EXTRACT(dayofyear FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy - , customer_other_data_src_22000.customer_id - , customer_other_data_src_22000.customer_third_hop_id - , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id - , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_9 - ) subq_10 - ) subq_11 + subq_14.acquired_ds__day + , subq_14.acquired_ds__week + , subq_14.acquired_ds__month + , subq_14.acquired_ds__quarter + , subq_14.acquired_ds__year + , subq_14.acquired_ds__extract_year + , subq_14.acquired_ds__extract_quarter + , subq_14.acquired_ds__extract_month + , subq_14.acquired_ds__extract_day + , subq_14.acquired_ds__extract_dow + , subq_14.acquired_ds__extract_doy + , subq_14.customer_id__acquired_ds__day + , subq_14.customer_id__acquired_ds__week + , subq_14.customer_id__acquired_ds__month + , subq_14.customer_id__acquired_ds__quarter + , subq_14.customer_id__acquired_ds__year + , subq_14.customer_id__acquired_ds__extract_year + , subq_14.customer_id__acquired_ds__extract_quarter + , subq_14.customer_id__acquired_ds__extract_month + , subq_14.customer_id__acquired_ds__extract_day + , subq_14.customer_id__acquired_ds__extract_dow + , subq_14.customer_id__acquired_ds__extract_doy + , subq_14.customer_third_hop_id__acquired_ds__day + , subq_14.customer_third_hop_id__acquired_ds__week + , subq_14.customer_third_hop_id__acquired_ds__month + , subq_14.customer_third_hop_id__acquired_ds__quarter + , subq_14.customer_third_hop_id__acquired_ds__year + , subq_14.customer_third_hop_id__acquired_ds__extract_year + , subq_14.customer_third_hop_id__acquired_ds__extract_quarter + , subq_14.customer_third_hop_id__acquired_ds__extract_month + , subq_14.customer_third_hop_id__acquired_ds__extract_day + , subq_14.customer_third_hop_id__acquired_ds__extract_dow + , subq_14.customer_third_hop_id__acquired_ds__extract_doy + , subq_14.acquired_ds__day AS metric_time__day + , subq_14.acquired_ds__week AS metric_time__week + , subq_14.acquired_ds__month AS metric_time__month + , subq_14.acquired_ds__quarter AS metric_time__quarter + , subq_14.acquired_ds__year AS metric_time__year + , subq_14.acquired_ds__extract_year AS metric_time__extract_year + , subq_14.acquired_ds__extract_quarter AS metric_time__extract_quarter + , subq_14.acquired_ds__extract_month AS metric_time__extract_month + , subq_14.acquired_ds__extract_day AS metric_time__extract_day + , subq_14.acquired_ds__extract_dow AS metric_time__extract_dow + , subq_14.acquired_ds__extract_doy AS metric_time__extract_doy + , subq_14.customer_id + , subq_14.customer_third_hop_id + , subq_14.customer_id__customer_third_hop_id + , subq_14.customer_third_hop_id__customer_id + , subq_14.country + , subq_14.customer_id__country + , subq_14.customer_third_hop_id__country + , subq_14.customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + SELECT + 1 AS customers_with_other_data + , customer_other_data_src_22000.country + , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, day) AS acquired_ds__day + , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, isoweek) AS acquired_ds__week + , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, month) AS acquired_ds__month + , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, quarter) AS acquired_ds__quarter + , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, year) AS acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day + , IF(EXTRACT(dayofweek FROM customer_other_data_src_22000.acquired_ds) = 1, 7, EXTRACT(dayofweek FROM customer_other_data_src_22000.acquired_ds) - 1) AS acquired_ds__extract_dow + , EXTRACT(dayofyear FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_id__country + , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, day) AS customer_id__acquired_ds__day + , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, isoweek) AS customer_id__acquired_ds__week + , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, month) AS customer_id__acquired_ds__month + , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, quarter) AS customer_id__acquired_ds__quarter + , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, year) AS customer_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day + , IF(EXTRACT(dayofweek FROM customer_other_data_src_22000.acquired_ds) = 1, 7, EXTRACT(dayofweek FROM customer_other_data_src_22000.acquired_ds) - 1) AS customer_id__acquired_ds__extract_dow + , EXTRACT(dayofyear FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_third_hop_id__country + , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, day) AS customer_third_hop_id__acquired_ds__day + , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, isoweek) AS customer_third_hop_id__acquired_ds__week + , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, month) AS customer_third_hop_id__acquired_ds__month + , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, quarter) AS customer_third_hop_id__acquired_ds__quarter + , DATE_TRUNC(customer_other_data_src_22000.acquired_ds, year) AS customer_third_hop_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day + , IF(EXTRACT(dayofweek FROM customer_other_data_src_22000.acquired_ds) = 1, 7, EXTRACT(dayofweek FROM customer_other_data_src_22000.acquired_ds) - 1) AS customer_third_hop_id__acquired_ds__extract_dow + , EXTRACT(dayofyear FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy + , customer_other_data_src_22000.customer_id + , customer_other_data_src_22000.customer_third_hop_id + , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id + , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_14 + ) subq_15 + WHERE customer_id__country = 'paraguay' + ) subq_16 + ) subq_17 WHERE customer_id__country = 'paraguay' - ) subq_12 - ) subq_13 + ) subq_18 + ) subq_19 GROUP BY customer_id__customer_third_hop_id - ) subq_14 - ) subq_15 - ) subq_16 + ) subq_20 + ) subq_21 + ) subq_22 ON - subq_8.customer_third_hop_id = subq_16.customer_id__customer_third_hop_id - ) subq_17 - ) subq_18 + subq_13.customer_third_hop_id = subq_22.customer_id__customer_third_hop_id + ) subq_23 + ) subq_24 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 - ) subq_19 - ) subq_20 -) subq_21 + ) subq_25 + ) subq_26 +) subq_27 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/BigQuery/test_inner_query_single_hop__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/BigQuery/test_inner_query_single_hop__plan0_optimized.sql index 2ad52ec04c..7c12d6cf98 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/BigQuery/test_inner_query_single_hop__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/BigQuery/test_inner_query_single_hop__plan0_optimized.sql @@ -8,7 +8,7 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_32.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + subq_39.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers , third_hop_table_src_22000.customer_third_hop_id AS third_hop_count FROM ***************************.third_hop_table third_hop_table_src_22000 LEFT OUTER JOIN ( @@ -21,20 +21,28 @@ FROM ( customer_id__customer_third_hop_id , SUM(customers_with_other_data) AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( - -- Read Elements From Semantic Model 'customer_other_data' - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - customer_third_hop_id AS customer_id__customer_third_hop_id - , country AS customer_id__country - , 1 AS customers_with_other_data - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_27 + customer_id__customer_third_hop_id + , customer_id__country + , customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' + SELECT + customer_third_hop_id AS customer_id__customer_third_hop_id + , country AS customer_id__country + , 1 AS customers_with_other_data + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_32 + WHERE customer_id__country = 'paraguay' + ) subq_34 WHERE customer_id__country = 'paraguay' GROUP BY customer_id__customer_third_hop_id - ) subq_32 + ) subq_39 ON - third_hop_table_src_22000.customer_third_hop_id = subq_32.customer_id__customer_third_hop_id -) subq_34 + third_hop_table_src_22000.customer_third_hop_id = subq_39.customer_id__customer_third_hop_id +) subq_41 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Databricks/test_inner_query_single_hop__plan0.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Databricks/test_inner_query_single_hop__plan0.sql index 41388a6d9b..add4b98b45 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Databricks/test_inner_query_single_hop__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Databricks/test_inner_query_single_hop__plan0.sql @@ -1,76 +1,76 @@ -- Compute Metrics via Expressions SELECT - subq_21.third_hop_count + subq_27.third_hop_count FROM ( -- Aggregate Measures SELECT - COUNT(DISTINCT subq_20.third_hop_count) AS third_hop_count + COUNT(DISTINCT subq_26.third_hop_count) AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count',] SELECT - subq_19.third_hop_count + subq_25.third_hop_count FROM ( -- Constrain Output with WHERE SELECT - subq_18.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_18.third_hop_count + subq_24.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_24.third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_17.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_17.third_hop_count + subq_23.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_23.third_hop_count FROM ( -- Join Standard Outputs SELECT - subq_8.customer_third_hop_id AS customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_8.third_hop_count AS third_hop_count + subq_13.customer_third_hop_id AS customer_third_hop_id + , subq_22.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id + , subq_22.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_13.third_hop_count AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id'] SELECT - subq_7.customer_third_hop_id - , subq_7.third_hop_count + subq_12.customer_third_hop_id + , subq_12.third_hop_count FROM ( -- Metric Time Dimension 'third_hop_ds' SELECT - subq_6.third_hop_ds__day - , subq_6.third_hop_ds__week - , subq_6.third_hop_ds__month - , subq_6.third_hop_ds__quarter - , subq_6.third_hop_ds__year - , subq_6.third_hop_ds__extract_year - , subq_6.third_hop_ds__extract_quarter - , subq_6.third_hop_ds__extract_month - , subq_6.third_hop_ds__extract_day - , subq_6.third_hop_ds__extract_dow - , subq_6.third_hop_ds__extract_doy - , subq_6.customer_third_hop_id__third_hop_ds__day - , subq_6.customer_third_hop_id__third_hop_ds__week - , subq_6.customer_third_hop_id__third_hop_ds__month - , subq_6.customer_third_hop_id__third_hop_ds__quarter - , subq_6.customer_third_hop_id__third_hop_ds__year - , subq_6.customer_third_hop_id__third_hop_ds__extract_year - , subq_6.customer_third_hop_id__third_hop_ds__extract_quarter - , subq_6.customer_third_hop_id__third_hop_ds__extract_month - , subq_6.customer_third_hop_id__third_hop_ds__extract_day - , subq_6.customer_third_hop_id__third_hop_ds__extract_dow - , subq_6.customer_third_hop_id__third_hop_ds__extract_doy - , subq_6.third_hop_ds__day AS metric_time__day - , subq_6.third_hop_ds__week AS metric_time__week - , subq_6.third_hop_ds__month AS metric_time__month - , subq_6.third_hop_ds__quarter AS metric_time__quarter - , subq_6.third_hop_ds__year AS metric_time__year - , subq_6.third_hop_ds__extract_year AS metric_time__extract_year - , subq_6.third_hop_ds__extract_quarter AS metric_time__extract_quarter - , subq_6.third_hop_ds__extract_month AS metric_time__extract_month - , subq_6.third_hop_ds__extract_day AS metric_time__extract_day - , subq_6.third_hop_ds__extract_dow AS metric_time__extract_dow - , subq_6.third_hop_ds__extract_doy AS metric_time__extract_doy - , subq_6.customer_third_hop_id - , subq_6.value - , subq_6.customer_third_hop_id__value - , subq_6.third_hop_count + subq_11.third_hop_ds__day + , subq_11.third_hop_ds__week + , subq_11.third_hop_ds__month + , subq_11.third_hop_ds__quarter + , subq_11.third_hop_ds__year + , subq_11.third_hop_ds__extract_year + , subq_11.third_hop_ds__extract_quarter + , subq_11.third_hop_ds__extract_month + , subq_11.third_hop_ds__extract_day + , subq_11.third_hop_ds__extract_dow + , subq_11.third_hop_ds__extract_doy + , subq_11.customer_third_hop_id__third_hop_ds__day + , subq_11.customer_third_hop_id__third_hop_ds__week + , subq_11.customer_third_hop_id__third_hop_ds__month + , subq_11.customer_third_hop_id__third_hop_ds__quarter + , subq_11.customer_third_hop_id__third_hop_ds__year + , subq_11.customer_third_hop_id__third_hop_ds__extract_year + , subq_11.customer_third_hop_id__third_hop_ds__extract_quarter + , subq_11.customer_third_hop_id__third_hop_ds__extract_month + , subq_11.customer_third_hop_id__third_hop_ds__extract_day + , subq_11.customer_third_hop_id__third_hop_ds__extract_dow + , subq_11.customer_third_hop_id__third_hop_ds__extract_doy + , subq_11.third_hop_ds__day AS metric_time__day + , subq_11.third_hop_ds__week AS metric_time__week + , subq_11.third_hop_ds__month AS metric_time__month + , subq_11.third_hop_ds__quarter AS metric_time__quarter + , subq_11.third_hop_ds__year AS metric_time__year + , subq_11.third_hop_ds__extract_year AS metric_time__extract_year + , subq_11.third_hop_ds__extract_quarter AS metric_time__extract_quarter + , subq_11.third_hop_ds__extract_month AS metric_time__extract_month + , subq_11.third_hop_ds__extract_day AS metric_time__extract_day + , subq_11.third_hop_ds__extract_dow AS metric_time__extract_dow + , subq_11.third_hop_ds__extract_doy AS metric_time__extract_doy + , subq_11.customer_third_hop_id + , subq_11.value + , subq_11.customer_third_hop_id__value + , subq_11.third_hop_count FROM ( -- Read Elements From Semantic Model 'third_hop_table' SELECT @@ -101,157 +101,214 @@ FROM ( , EXTRACT(doy FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_doy , third_hop_table_src_22000.customer_third_hop_id FROM ***************************.third_hop_table third_hop_table_src_22000 - ) subq_6 - ) subq_7 - ) subq_8 + ) subq_11 + ) subq_12 + ) subq_13 LEFT OUTER JOIN ( -- Pass Only Elements: ['customer_id__customer_third_hop_id', 'customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_15.customer_id__customer_third_hop_id - , subq_15.customer_id__customer_third_hop_id__paraguayan_customers + subq_21.customer_id__customer_third_hop_id + , subq_21.customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Compute Metrics via Expressions SELECT - subq_14.customer_id__customer_third_hop_id - , subq_14.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers + subq_20.customer_id__customer_third_hop_id + , subq_20.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Aggregate Measures SELECT - subq_13.customer_id__customer_third_hop_id - , SUM(subq_13.customers_with_other_data) AS customers_with_other_data + subq_19.customer_id__customer_third_hop_id + , SUM(subq_19.customers_with_other_data) AS customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__customer_third_hop_id'] SELECT - subq_12.customer_id__customer_third_hop_id - , subq_12.customers_with_other_data + subq_18.customer_id__customer_third_hop_id + , subq_18.customers_with_other_data FROM ( -- Constrain Output with WHERE SELECT - subq_11.customer_id__customer_third_hop_id - , subq_11.customer_id__country - , subq_11.customers_with_other_data + subq_17.customer_id__customer_third_hop_id + , subq_17.customer_id__country + , subq_17.customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - subq_10.customer_id__customer_third_hop_id - , subq_10.customer_id__country - , subq_10.customers_with_other_data + subq_16.customer_id__customer_third_hop_id + , subq_16.customer_id__country + , subq_16.customers_with_other_data FROM ( - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE SELECT - subq_9.acquired_ds__day - , subq_9.acquired_ds__week - , subq_9.acquired_ds__month - , subq_9.acquired_ds__quarter - , subq_9.acquired_ds__year - , subq_9.acquired_ds__extract_year - , subq_9.acquired_ds__extract_quarter - , subq_9.acquired_ds__extract_month - , subq_9.acquired_ds__extract_day - , subq_9.acquired_ds__extract_dow - , subq_9.acquired_ds__extract_doy - , subq_9.customer_id__acquired_ds__day - , subq_9.customer_id__acquired_ds__week - , subq_9.customer_id__acquired_ds__month - , subq_9.customer_id__acquired_ds__quarter - , subq_9.customer_id__acquired_ds__year - , subq_9.customer_id__acquired_ds__extract_year - , subq_9.customer_id__acquired_ds__extract_quarter - , subq_9.customer_id__acquired_ds__extract_month - , subq_9.customer_id__acquired_ds__extract_day - , subq_9.customer_id__acquired_ds__extract_dow - , subq_9.customer_id__acquired_ds__extract_doy - , subq_9.customer_third_hop_id__acquired_ds__day - , subq_9.customer_third_hop_id__acquired_ds__week - , subq_9.customer_third_hop_id__acquired_ds__month - , subq_9.customer_third_hop_id__acquired_ds__quarter - , subq_9.customer_third_hop_id__acquired_ds__year - , subq_9.customer_third_hop_id__acquired_ds__extract_year - , subq_9.customer_third_hop_id__acquired_ds__extract_quarter - , subq_9.customer_third_hop_id__acquired_ds__extract_month - , subq_9.customer_third_hop_id__acquired_ds__extract_day - , subq_9.customer_third_hop_id__acquired_ds__extract_dow - , subq_9.customer_third_hop_id__acquired_ds__extract_doy - , subq_9.acquired_ds__day AS metric_time__day - , subq_9.acquired_ds__week AS metric_time__week - , subq_9.acquired_ds__month AS metric_time__month - , subq_9.acquired_ds__quarter AS metric_time__quarter - , subq_9.acquired_ds__year AS metric_time__year - , subq_9.acquired_ds__extract_year AS metric_time__extract_year - , subq_9.acquired_ds__extract_quarter AS metric_time__extract_quarter - , subq_9.acquired_ds__extract_month AS metric_time__extract_month - , subq_9.acquired_ds__extract_day AS metric_time__extract_day - , subq_9.acquired_ds__extract_dow AS metric_time__extract_dow - , subq_9.acquired_ds__extract_doy AS metric_time__extract_doy - , subq_9.customer_id - , subq_9.customer_third_hop_id - , subq_9.customer_id__customer_third_hop_id - , subq_9.customer_third_hop_id__customer_id - , subq_9.country - , subq_9.customer_id__country - , subq_9.customer_third_hop_id__country - , subq_9.customers_with_other_data + subq_15.acquired_ds__day + , subq_15.acquired_ds__week + , subq_15.acquired_ds__month + , subq_15.acquired_ds__quarter + , subq_15.acquired_ds__year + , subq_15.acquired_ds__extract_year + , subq_15.acquired_ds__extract_quarter + , subq_15.acquired_ds__extract_month + , subq_15.acquired_ds__extract_day + , subq_15.acquired_ds__extract_dow + , subq_15.acquired_ds__extract_doy + , subq_15.customer_id__acquired_ds__day + , subq_15.customer_id__acquired_ds__week + , subq_15.customer_id__acquired_ds__month + , subq_15.customer_id__acquired_ds__quarter + , subq_15.customer_id__acquired_ds__year + , subq_15.customer_id__acquired_ds__extract_year + , subq_15.customer_id__acquired_ds__extract_quarter + , subq_15.customer_id__acquired_ds__extract_month + , subq_15.customer_id__acquired_ds__extract_day + , subq_15.customer_id__acquired_ds__extract_dow + , subq_15.customer_id__acquired_ds__extract_doy + , subq_15.customer_third_hop_id__acquired_ds__day + , subq_15.customer_third_hop_id__acquired_ds__week + , subq_15.customer_third_hop_id__acquired_ds__month + , subq_15.customer_third_hop_id__acquired_ds__quarter + , subq_15.customer_third_hop_id__acquired_ds__year + , subq_15.customer_third_hop_id__acquired_ds__extract_year + , subq_15.customer_third_hop_id__acquired_ds__extract_quarter + , subq_15.customer_third_hop_id__acquired_ds__extract_month + , subq_15.customer_third_hop_id__acquired_ds__extract_day + , subq_15.customer_third_hop_id__acquired_ds__extract_dow + , subq_15.customer_third_hop_id__acquired_ds__extract_doy + , subq_15.metric_time__day + , subq_15.metric_time__week + , subq_15.metric_time__month + , subq_15.metric_time__quarter + , subq_15.metric_time__year + , subq_15.metric_time__extract_year + , subq_15.metric_time__extract_quarter + , subq_15.metric_time__extract_month + , subq_15.metric_time__extract_day + , subq_15.metric_time__extract_dow + , subq_15.metric_time__extract_doy + , subq_15.customer_id + , subq_15.customer_third_hop_id + , subq_15.customer_id__customer_third_hop_id + , subq_15.customer_third_hop_id__customer_id + , subq_15.country + , subq_15.customer_id__country + , subq_15.customer_third_hop_id__country + , subq_15.customers_with_other_data FROM ( - -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' SELECT - 1 AS customers_with_other_data - , customer_other_data_src_22000.country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_third_hop_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy - , customer_other_data_src_22000.customer_id - , customer_other_data_src_22000.customer_third_hop_id - , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id - , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_9 - ) subq_10 - ) subq_11 + subq_14.acquired_ds__day + , subq_14.acquired_ds__week + , subq_14.acquired_ds__month + , subq_14.acquired_ds__quarter + , subq_14.acquired_ds__year + , subq_14.acquired_ds__extract_year + , subq_14.acquired_ds__extract_quarter + , subq_14.acquired_ds__extract_month + , subq_14.acquired_ds__extract_day + , subq_14.acquired_ds__extract_dow + , subq_14.acquired_ds__extract_doy + , subq_14.customer_id__acquired_ds__day + , subq_14.customer_id__acquired_ds__week + , subq_14.customer_id__acquired_ds__month + , subq_14.customer_id__acquired_ds__quarter + , subq_14.customer_id__acquired_ds__year + , subq_14.customer_id__acquired_ds__extract_year + , subq_14.customer_id__acquired_ds__extract_quarter + , subq_14.customer_id__acquired_ds__extract_month + , subq_14.customer_id__acquired_ds__extract_day + , subq_14.customer_id__acquired_ds__extract_dow + , subq_14.customer_id__acquired_ds__extract_doy + , subq_14.customer_third_hop_id__acquired_ds__day + , subq_14.customer_third_hop_id__acquired_ds__week + , subq_14.customer_third_hop_id__acquired_ds__month + , subq_14.customer_third_hop_id__acquired_ds__quarter + , subq_14.customer_third_hop_id__acquired_ds__year + , subq_14.customer_third_hop_id__acquired_ds__extract_year + , subq_14.customer_third_hop_id__acquired_ds__extract_quarter + , subq_14.customer_third_hop_id__acquired_ds__extract_month + , subq_14.customer_third_hop_id__acquired_ds__extract_day + , subq_14.customer_third_hop_id__acquired_ds__extract_dow + , subq_14.customer_third_hop_id__acquired_ds__extract_doy + , subq_14.acquired_ds__day AS metric_time__day + , subq_14.acquired_ds__week AS metric_time__week + , subq_14.acquired_ds__month AS metric_time__month + , subq_14.acquired_ds__quarter AS metric_time__quarter + , subq_14.acquired_ds__year AS metric_time__year + , subq_14.acquired_ds__extract_year AS metric_time__extract_year + , subq_14.acquired_ds__extract_quarter AS metric_time__extract_quarter + , subq_14.acquired_ds__extract_month AS metric_time__extract_month + , subq_14.acquired_ds__extract_day AS metric_time__extract_day + , subq_14.acquired_ds__extract_dow AS metric_time__extract_dow + , subq_14.acquired_ds__extract_doy AS metric_time__extract_doy + , subq_14.customer_id + , subq_14.customer_third_hop_id + , subq_14.customer_id__customer_third_hop_id + , subq_14.customer_third_hop_id__customer_id + , subq_14.country + , subq_14.customer_id__country + , subq_14.customer_third_hop_id__country + , subq_14.customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + SELECT + 1 AS customers_with_other_data + , customer_other_data_src_22000.country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_third_hop_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy + , customer_other_data_src_22000.customer_id + , customer_other_data_src_22000.customer_third_hop_id + , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id + , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_14 + ) subq_15 + WHERE customer_id__country = 'paraguay' + ) subq_16 + ) subq_17 WHERE customer_id__country = 'paraguay' - ) subq_12 - ) subq_13 + ) subq_18 + ) subq_19 GROUP BY - subq_13.customer_id__customer_third_hop_id - ) subq_14 - ) subq_15 - ) subq_16 + subq_19.customer_id__customer_third_hop_id + ) subq_20 + ) subq_21 + ) subq_22 ON - subq_8.customer_third_hop_id = subq_16.customer_id__customer_third_hop_id - ) subq_17 - ) subq_18 + subq_13.customer_third_hop_id = subq_22.customer_id__customer_third_hop_id + ) subq_23 + ) subq_24 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 - ) subq_19 - ) subq_20 -) subq_21 + ) subq_25 + ) subq_26 +) subq_27 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Databricks/test_inner_query_single_hop__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Databricks/test_inner_query_single_hop__plan0_optimized.sql index 2ad52ec04c..7c12d6cf98 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Databricks/test_inner_query_single_hop__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Databricks/test_inner_query_single_hop__plan0_optimized.sql @@ -8,7 +8,7 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_32.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + subq_39.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers , third_hop_table_src_22000.customer_third_hop_id AS third_hop_count FROM ***************************.third_hop_table third_hop_table_src_22000 LEFT OUTER JOIN ( @@ -21,20 +21,28 @@ FROM ( customer_id__customer_third_hop_id , SUM(customers_with_other_data) AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( - -- Read Elements From Semantic Model 'customer_other_data' - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - customer_third_hop_id AS customer_id__customer_third_hop_id - , country AS customer_id__country - , 1 AS customers_with_other_data - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_27 + customer_id__customer_third_hop_id + , customer_id__country + , customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' + SELECT + customer_third_hop_id AS customer_id__customer_third_hop_id + , country AS customer_id__country + , 1 AS customers_with_other_data + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_32 + WHERE customer_id__country = 'paraguay' + ) subq_34 WHERE customer_id__country = 'paraguay' GROUP BY customer_id__customer_third_hop_id - ) subq_32 + ) subq_39 ON - third_hop_table_src_22000.customer_third_hop_id = subq_32.customer_id__customer_third_hop_id -) subq_34 + third_hop_table_src_22000.customer_third_hop_id = subq_39.customer_id__customer_third_hop_id +) subq_41 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_single_hop__plan0.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_single_hop__plan0.sql index 6a27e35c22..795a470587 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_single_hop__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_single_hop__plan0.sql @@ -1,76 +1,76 @@ -- Compute Metrics via Expressions SELECT - subq_21.third_hop_count + subq_27.third_hop_count FROM ( -- Aggregate Measures SELECT - COUNT(DISTINCT subq_20.third_hop_count) AS third_hop_count + COUNT(DISTINCT subq_26.third_hop_count) AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count',] SELECT - subq_19.third_hop_count + subq_25.third_hop_count FROM ( -- Constrain Output with WHERE SELECT - subq_18.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_18.third_hop_count + subq_24.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_24.third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_17.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_17.third_hop_count + subq_23.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_23.third_hop_count FROM ( -- Join Standard Outputs SELECT - subq_8.customer_third_hop_id AS customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_8.third_hop_count AS third_hop_count + subq_13.customer_third_hop_id AS customer_third_hop_id + , subq_22.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id + , subq_22.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_13.third_hop_count AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id'] SELECT - subq_7.customer_third_hop_id - , subq_7.third_hop_count + subq_12.customer_third_hop_id + , subq_12.third_hop_count FROM ( -- Metric Time Dimension 'third_hop_ds' SELECT - subq_6.third_hop_ds__day - , subq_6.third_hop_ds__week - , subq_6.third_hop_ds__month - , subq_6.third_hop_ds__quarter - , subq_6.third_hop_ds__year - , subq_6.third_hop_ds__extract_year - , subq_6.third_hop_ds__extract_quarter - , subq_6.third_hop_ds__extract_month - , subq_6.third_hop_ds__extract_day - , subq_6.third_hop_ds__extract_dow - , subq_6.third_hop_ds__extract_doy - , subq_6.customer_third_hop_id__third_hop_ds__day - , subq_6.customer_third_hop_id__third_hop_ds__week - , subq_6.customer_third_hop_id__third_hop_ds__month - , subq_6.customer_third_hop_id__third_hop_ds__quarter - , subq_6.customer_third_hop_id__third_hop_ds__year - , subq_6.customer_third_hop_id__third_hop_ds__extract_year - , subq_6.customer_third_hop_id__third_hop_ds__extract_quarter - , subq_6.customer_third_hop_id__third_hop_ds__extract_month - , subq_6.customer_third_hop_id__third_hop_ds__extract_day - , subq_6.customer_third_hop_id__third_hop_ds__extract_dow - , subq_6.customer_third_hop_id__third_hop_ds__extract_doy - , subq_6.third_hop_ds__day AS metric_time__day - , subq_6.third_hop_ds__week AS metric_time__week - , subq_6.third_hop_ds__month AS metric_time__month - , subq_6.third_hop_ds__quarter AS metric_time__quarter - , subq_6.third_hop_ds__year AS metric_time__year - , subq_6.third_hop_ds__extract_year AS metric_time__extract_year - , subq_6.third_hop_ds__extract_quarter AS metric_time__extract_quarter - , subq_6.third_hop_ds__extract_month AS metric_time__extract_month - , subq_6.third_hop_ds__extract_day AS metric_time__extract_day - , subq_6.third_hop_ds__extract_dow AS metric_time__extract_dow - , subq_6.third_hop_ds__extract_doy AS metric_time__extract_doy - , subq_6.customer_third_hop_id - , subq_6.value - , subq_6.customer_third_hop_id__value - , subq_6.third_hop_count + subq_11.third_hop_ds__day + , subq_11.third_hop_ds__week + , subq_11.third_hop_ds__month + , subq_11.third_hop_ds__quarter + , subq_11.third_hop_ds__year + , subq_11.third_hop_ds__extract_year + , subq_11.third_hop_ds__extract_quarter + , subq_11.third_hop_ds__extract_month + , subq_11.third_hop_ds__extract_day + , subq_11.third_hop_ds__extract_dow + , subq_11.third_hop_ds__extract_doy + , subq_11.customer_third_hop_id__third_hop_ds__day + , subq_11.customer_third_hop_id__third_hop_ds__week + , subq_11.customer_third_hop_id__third_hop_ds__month + , subq_11.customer_third_hop_id__third_hop_ds__quarter + , subq_11.customer_third_hop_id__third_hop_ds__year + , subq_11.customer_third_hop_id__third_hop_ds__extract_year + , subq_11.customer_third_hop_id__third_hop_ds__extract_quarter + , subq_11.customer_third_hop_id__third_hop_ds__extract_month + , subq_11.customer_third_hop_id__third_hop_ds__extract_day + , subq_11.customer_third_hop_id__third_hop_ds__extract_dow + , subq_11.customer_third_hop_id__third_hop_ds__extract_doy + , subq_11.third_hop_ds__day AS metric_time__day + , subq_11.third_hop_ds__week AS metric_time__week + , subq_11.third_hop_ds__month AS metric_time__month + , subq_11.third_hop_ds__quarter AS metric_time__quarter + , subq_11.third_hop_ds__year AS metric_time__year + , subq_11.third_hop_ds__extract_year AS metric_time__extract_year + , subq_11.third_hop_ds__extract_quarter AS metric_time__extract_quarter + , subq_11.third_hop_ds__extract_month AS metric_time__extract_month + , subq_11.third_hop_ds__extract_day AS metric_time__extract_day + , subq_11.third_hop_ds__extract_dow AS metric_time__extract_dow + , subq_11.third_hop_ds__extract_doy AS metric_time__extract_doy + , subq_11.customer_third_hop_id + , subq_11.value + , subq_11.customer_third_hop_id__value + , subq_11.third_hop_count FROM ( -- Read Elements From Semantic Model 'third_hop_table' SELECT @@ -101,157 +101,214 @@ FROM ( , EXTRACT(doy FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_doy , third_hop_table_src_22000.customer_third_hop_id FROM ***************************.third_hop_table third_hop_table_src_22000 - ) subq_6 - ) subq_7 - ) subq_8 + ) subq_11 + ) subq_12 + ) subq_13 LEFT OUTER JOIN ( -- Pass Only Elements: ['customer_id__customer_third_hop_id', 'customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_15.customer_id__customer_third_hop_id - , subq_15.customer_id__customer_third_hop_id__paraguayan_customers + subq_21.customer_id__customer_third_hop_id + , subq_21.customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Compute Metrics via Expressions SELECT - subq_14.customer_id__customer_third_hop_id - , subq_14.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers + subq_20.customer_id__customer_third_hop_id + , subq_20.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Aggregate Measures SELECT - subq_13.customer_id__customer_third_hop_id - , SUM(subq_13.customers_with_other_data) AS customers_with_other_data + subq_19.customer_id__customer_third_hop_id + , SUM(subq_19.customers_with_other_data) AS customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__customer_third_hop_id'] SELECT - subq_12.customer_id__customer_third_hop_id - , subq_12.customers_with_other_data + subq_18.customer_id__customer_third_hop_id + , subq_18.customers_with_other_data FROM ( -- Constrain Output with WHERE SELECT - subq_11.customer_id__customer_third_hop_id - , subq_11.customer_id__country - , subq_11.customers_with_other_data + subq_17.customer_id__customer_third_hop_id + , subq_17.customer_id__country + , subq_17.customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - subq_10.customer_id__customer_third_hop_id - , subq_10.customer_id__country - , subq_10.customers_with_other_data + subq_16.customer_id__customer_third_hop_id + , subq_16.customer_id__country + , subq_16.customers_with_other_data FROM ( - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE SELECT - subq_9.acquired_ds__day - , subq_9.acquired_ds__week - , subq_9.acquired_ds__month - , subq_9.acquired_ds__quarter - , subq_9.acquired_ds__year - , subq_9.acquired_ds__extract_year - , subq_9.acquired_ds__extract_quarter - , subq_9.acquired_ds__extract_month - , subq_9.acquired_ds__extract_day - , subq_9.acquired_ds__extract_dow - , subq_9.acquired_ds__extract_doy - , subq_9.customer_id__acquired_ds__day - , subq_9.customer_id__acquired_ds__week - , subq_9.customer_id__acquired_ds__month - , subq_9.customer_id__acquired_ds__quarter - , subq_9.customer_id__acquired_ds__year - , subq_9.customer_id__acquired_ds__extract_year - , subq_9.customer_id__acquired_ds__extract_quarter - , subq_9.customer_id__acquired_ds__extract_month - , subq_9.customer_id__acquired_ds__extract_day - , subq_9.customer_id__acquired_ds__extract_dow - , subq_9.customer_id__acquired_ds__extract_doy - , subq_9.customer_third_hop_id__acquired_ds__day - , subq_9.customer_third_hop_id__acquired_ds__week - , subq_9.customer_third_hop_id__acquired_ds__month - , subq_9.customer_third_hop_id__acquired_ds__quarter - , subq_9.customer_third_hop_id__acquired_ds__year - , subq_9.customer_third_hop_id__acquired_ds__extract_year - , subq_9.customer_third_hop_id__acquired_ds__extract_quarter - , subq_9.customer_third_hop_id__acquired_ds__extract_month - , subq_9.customer_third_hop_id__acquired_ds__extract_day - , subq_9.customer_third_hop_id__acquired_ds__extract_dow - , subq_9.customer_third_hop_id__acquired_ds__extract_doy - , subq_9.acquired_ds__day AS metric_time__day - , subq_9.acquired_ds__week AS metric_time__week - , subq_9.acquired_ds__month AS metric_time__month - , subq_9.acquired_ds__quarter AS metric_time__quarter - , subq_9.acquired_ds__year AS metric_time__year - , subq_9.acquired_ds__extract_year AS metric_time__extract_year - , subq_9.acquired_ds__extract_quarter AS metric_time__extract_quarter - , subq_9.acquired_ds__extract_month AS metric_time__extract_month - , subq_9.acquired_ds__extract_day AS metric_time__extract_day - , subq_9.acquired_ds__extract_dow AS metric_time__extract_dow - , subq_9.acquired_ds__extract_doy AS metric_time__extract_doy - , subq_9.customer_id - , subq_9.customer_third_hop_id - , subq_9.customer_id__customer_third_hop_id - , subq_9.customer_third_hop_id__customer_id - , subq_9.country - , subq_9.customer_id__country - , subq_9.customer_third_hop_id__country - , subq_9.customers_with_other_data + subq_15.acquired_ds__day + , subq_15.acquired_ds__week + , subq_15.acquired_ds__month + , subq_15.acquired_ds__quarter + , subq_15.acquired_ds__year + , subq_15.acquired_ds__extract_year + , subq_15.acquired_ds__extract_quarter + , subq_15.acquired_ds__extract_month + , subq_15.acquired_ds__extract_day + , subq_15.acquired_ds__extract_dow + , subq_15.acquired_ds__extract_doy + , subq_15.customer_id__acquired_ds__day + , subq_15.customer_id__acquired_ds__week + , subq_15.customer_id__acquired_ds__month + , subq_15.customer_id__acquired_ds__quarter + , subq_15.customer_id__acquired_ds__year + , subq_15.customer_id__acquired_ds__extract_year + , subq_15.customer_id__acquired_ds__extract_quarter + , subq_15.customer_id__acquired_ds__extract_month + , subq_15.customer_id__acquired_ds__extract_day + , subq_15.customer_id__acquired_ds__extract_dow + , subq_15.customer_id__acquired_ds__extract_doy + , subq_15.customer_third_hop_id__acquired_ds__day + , subq_15.customer_third_hop_id__acquired_ds__week + , subq_15.customer_third_hop_id__acquired_ds__month + , subq_15.customer_third_hop_id__acquired_ds__quarter + , subq_15.customer_third_hop_id__acquired_ds__year + , subq_15.customer_third_hop_id__acquired_ds__extract_year + , subq_15.customer_third_hop_id__acquired_ds__extract_quarter + , subq_15.customer_third_hop_id__acquired_ds__extract_month + , subq_15.customer_third_hop_id__acquired_ds__extract_day + , subq_15.customer_third_hop_id__acquired_ds__extract_dow + , subq_15.customer_third_hop_id__acquired_ds__extract_doy + , subq_15.metric_time__day + , subq_15.metric_time__week + , subq_15.metric_time__month + , subq_15.metric_time__quarter + , subq_15.metric_time__year + , subq_15.metric_time__extract_year + , subq_15.metric_time__extract_quarter + , subq_15.metric_time__extract_month + , subq_15.metric_time__extract_day + , subq_15.metric_time__extract_dow + , subq_15.metric_time__extract_doy + , subq_15.customer_id + , subq_15.customer_third_hop_id + , subq_15.customer_id__customer_third_hop_id + , subq_15.customer_third_hop_id__customer_id + , subq_15.country + , subq_15.customer_id__country + , subq_15.customer_third_hop_id__country + , subq_15.customers_with_other_data FROM ( - -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' SELECT - 1 AS customers_with_other_data - , customer_other_data_src_22000.country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day - , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day - , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_third_hop_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day - , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy - , customer_other_data_src_22000.customer_id - , customer_other_data_src_22000.customer_third_hop_id - , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id - , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_9 - ) subq_10 - ) subq_11 + subq_14.acquired_ds__day + , subq_14.acquired_ds__week + , subq_14.acquired_ds__month + , subq_14.acquired_ds__quarter + , subq_14.acquired_ds__year + , subq_14.acquired_ds__extract_year + , subq_14.acquired_ds__extract_quarter + , subq_14.acquired_ds__extract_month + , subq_14.acquired_ds__extract_day + , subq_14.acquired_ds__extract_dow + , subq_14.acquired_ds__extract_doy + , subq_14.customer_id__acquired_ds__day + , subq_14.customer_id__acquired_ds__week + , subq_14.customer_id__acquired_ds__month + , subq_14.customer_id__acquired_ds__quarter + , subq_14.customer_id__acquired_ds__year + , subq_14.customer_id__acquired_ds__extract_year + , subq_14.customer_id__acquired_ds__extract_quarter + , subq_14.customer_id__acquired_ds__extract_month + , subq_14.customer_id__acquired_ds__extract_day + , subq_14.customer_id__acquired_ds__extract_dow + , subq_14.customer_id__acquired_ds__extract_doy + , subq_14.customer_third_hop_id__acquired_ds__day + , subq_14.customer_third_hop_id__acquired_ds__week + , subq_14.customer_third_hop_id__acquired_ds__month + , subq_14.customer_third_hop_id__acquired_ds__quarter + , subq_14.customer_third_hop_id__acquired_ds__year + , subq_14.customer_third_hop_id__acquired_ds__extract_year + , subq_14.customer_third_hop_id__acquired_ds__extract_quarter + , subq_14.customer_third_hop_id__acquired_ds__extract_month + , subq_14.customer_third_hop_id__acquired_ds__extract_day + , subq_14.customer_third_hop_id__acquired_ds__extract_dow + , subq_14.customer_third_hop_id__acquired_ds__extract_doy + , subq_14.acquired_ds__day AS metric_time__day + , subq_14.acquired_ds__week AS metric_time__week + , subq_14.acquired_ds__month AS metric_time__month + , subq_14.acquired_ds__quarter AS metric_time__quarter + , subq_14.acquired_ds__year AS metric_time__year + , subq_14.acquired_ds__extract_year AS metric_time__extract_year + , subq_14.acquired_ds__extract_quarter AS metric_time__extract_quarter + , subq_14.acquired_ds__extract_month AS metric_time__extract_month + , subq_14.acquired_ds__extract_day AS metric_time__extract_day + , subq_14.acquired_ds__extract_dow AS metric_time__extract_dow + , subq_14.acquired_ds__extract_doy AS metric_time__extract_doy + , subq_14.customer_id + , subq_14.customer_third_hop_id + , subq_14.customer_id__customer_third_hop_id + , subq_14.customer_third_hop_id__customer_id + , subq_14.country + , subq_14.customer_id__country + , subq_14.customer_third_hop_id__country + , subq_14.customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + SELECT + 1 AS customers_with_other_data + , customer_other_data_src_22000.country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day + , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day + , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_third_hop_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day + , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy + , customer_other_data_src_22000.customer_id + , customer_other_data_src_22000.customer_third_hop_id + , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id + , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_14 + ) subq_15 + WHERE customer_id__country = 'paraguay' + ) subq_16 + ) subq_17 WHERE customer_id__country = 'paraguay' - ) subq_12 - ) subq_13 + ) subq_18 + ) subq_19 GROUP BY - subq_13.customer_id__customer_third_hop_id - ) subq_14 - ) subq_15 - ) subq_16 + subq_19.customer_id__customer_third_hop_id + ) subq_20 + ) subq_21 + ) subq_22 ON - subq_8.customer_third_hop_id = subq_16.customer_id__customer_third_hop_id - ) subq_17 - ) subq_18 + subq_13.customer_third_hop_id = subq_22.customer_id__customer_third_hop_id + ) subq_23 + ) subq_24 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 - ) subq_19 - ) subq_20 -) subq_21 + ) subq_25 + ) subq_26 +) subq_27 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_single_hop__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_single_hop__plan0_optimized.sql index 2ad52ec04c..7c12d6cf98 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_single_hop__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_single_hop__plan0_optimized.sql @@ -8,7 +8,7 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_32.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + subq_39.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers , third_hop_table_src_22000.customer_third_hop_id AS third_hop_count FROM ***************************.third_hop_table third_hop_table_src_22000 LEFT OUTER JOIN ( @@ -21,20 +21,28 @@ FROM ( customer_id__customer_third_hop_id , SUM(customers_with_other_data) AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( - -- Read Elements From Semantic Model 'customer_other_data' - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - customer_third_hop_id AS customer_id__customer_third_hop_id - , country AS customer_id__country - , 1 AS customers_with_other_data - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_27 + customer_id__customer_third_hop_id + , customer_id__country + , customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' + SELECT + customer_third_hop_id AS customer_id__customer_third_hop_id + , country AS customer_id__country + , 1 AS customers_with_other_data + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_32 + WHERE customer_id__country = 'paraguay' + ) subq_34 WHERE customer_id__country = 'paraguay' GROUP BY customer_id__customer_third_hop_id - ) subq_32 + ) subq_39 ON - third_hop_table_src_22000.customer_third_hop_id = subq_32.customer_id__customer_third_hop_id -) subq_34 + third_hop_table_src_22000.customer_third_hop_id = subq_39.customer_id__customer_third_hop_id +) subq_41 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Postgres/test_inner_query_single_hop__plan0.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Postgres/test_inner_query_single_hop__plan0.sql index 6a27e35c22..795a470587 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Postgres/test_inner_query_single_hop__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Postgres/test_inner_query_single_hop__plan0.sql @@ -1,76 +1,76 @@ -- Compute Metrics via Expressions SELECT - subq_21.third_hop_count + subq_27.third_hop_count FROM ( -- Aggregate Measures SELECT - COUNT(DISTINCT subq_20.third_hop_count) AS third_hop_count + COUNT(DISTINCT subq_26.third_hop_count) AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count',] SELECT - subq_19.third_hop_count + subq_25.third_hop_count FROM ( -- Constrain Output with WHERE SELECT - subq_18.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_18.third_hop_count + subq_24.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_24.third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_17.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_17.third_hop_count + subq_23.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_23.third_hop_count FROM ( -- Join Standard Outputs SELECT - subq_8.customer_third_hop_id AS customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_8.third_hop_count AS third_hop_count + subq_13.customer_third_hop_id AS customer_third_hop_id + , subq_22.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id + , subq_22.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_13.third_hop_count AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id'] SELECT - subq_7.customer_third_hop_id - , subq_7.third_hop_count + subq_12.customer_third_hop_id + , subq_12.third_hop_count FROM ( -- Metric Time Dimension 'third_hop_ds' SELECT - subq_6.third_hop_ds__day - , subq_6.third_hop_ds__week - , subq_6.third_hop_ds__month - , subq_6.third_hop_ds__quarter - , subq_6.third_hop_ds__year - , subq_6.third_hop_ds__extract_year - , subq_6.third_hop_ds__extract_quarter - , subq_6.third_hop_ds__extract_month - , subq_6.third_hop_ds__extract_day - , subq_6.third_hop_ds__extract_dow - , subq_6.third_hop_ds__extract_doy - , subq_6.customer_third_hop_id__third_hop_ds__day - , subq_6.customer_third_hop_id__third_hop_ds__week - , subq_6.customer_third_hop_id__third_hop_ds__month - , subq_6.customer_third_hop_id__third_hop_ds__quarter - , subq_6.customer_third_hop_id__third_hop_ds__year - , subq_6.customer_third_hop_id__third_hop_ds__extract_year - , subq_6.customer_third_hop_id__third_hop_ds__extract_quarter - , subq_6.customer_third_hop_id__third_hop_ds__extract_month - , subq_6.customer_third_hop_id__third_hop_ds__extract_day - , subq_6.customer_third_hop_id__third_hop_ds__extract_dow - , subq_6.customer_third_hop_id__third_hop_ds__extract_doy - , subq_6.third_hop_ds__day AS metric_time__day - , subq_6.third_hop_ds__week AS metric_time__week - , subq_6.third_hop_ds__month AS metric_time__month - , subq_6.third_hop_ds__quarter AS metric_time__quarter - , subq_6.third_hop_ds__year AS metric_time__year - , subq_6.third_hop_ds__extract_year AS metric_time__extract_year - , subq_6.third_hop_ds__extract_quarter AS metric_time__extract_quarter - , subq_6.third_hop_ds__extract_month AS metric_time__extract_month - , subq_6.third_hop_ds__extract_day AS metric_time__extract_day - , subq_6.third_hop_ds__extract_dow AS metric_time__extract_dow - , subq_6.third_hop_ds__extract_doy AS metric_time__extract_doy - , subq_6.customer_third_hop_id - , subq_6.value - , subq_6.customer_third_hop_id__value - , subq_6.third_hop_count + subq_11.third_hop_ds__day + , subq_11.third_hop_ds__week + , subq_11.third_hop_ds__month + , subq_11.third_hop_ds__quarter + , subq_11.third_hop_ds__year + , subq_11.third_hop_ds__extract_year + , subq_11.third_hop_ds__extract_quarter + , subq_11.third_hop_ds__extract_month + , subq_11.third_hop_ds__extract_day + , subq_11.third_hop_ds__extract_dow + , subq_11.third_hop_ds__extract_doy + , subq_11.customer_third_hop_id__third_hop_ds__day + , subq_11.customer_third_hop_id__third_hop_ds__week + , subq_11.customer_third_hop_id__third_hop_ds__month + , subq_11.customer_third_hop_id__third_hop_ds__quarter + , subq_11.customer_third_hop_id__third_hop_ds__year + , subq_11.customer_third_hop_id__third_hop_ds__extract_year + , subq_11.customer_third_hop_id__third_hop_ds__extract_quarter + , subq_11.customer_third_hop_id__third_hop_ds__extract_month + , subq_11.customer_third_hop_id__third_hop_ds__extract_day + , subq_11.customer_third_hop_id__third_hop_ds__extract_dow + , subq_11.customer_third_hop_id__third_hop_ds__extract_doy + , subq_11.third_hop_ds__day AS metric_time__day + , subq_11.third_hop_ds__week AS metric_time__week + , subq_11.third_hop_ds__month AS metric_time__month + , subq_11.third_hop_ds__quarter AS metric_time__quarter + , subq_11.third_hop_ds__year AS metric_time__year + , subq_11.third_hop_ds__extract_year AS metric_time__extract_year + , subq_11.third_hop_ds__extract_quarter AS metric_time__extract_quarter + , subq_11.third_hop_ds__extract_month AS metric_time__extract_month + , subq_11.third_hop_ds__extract_day AS metric_time__extract_day + , subq_11.third_hop_ds__extract_dow AS metric_time__extract_dow + , subq_11.third_hop_ds__extract_doy AS metric_time__extract_doy + , subq_11.customer_third_hop_id + , subq_11.value + , subq_11.customer_third_hop_id__value + , subq_11.third_hop_count FROM ( -- Read Elements From Semantic Model 'third_hop_table' SELECT @@ -101,157 +101,214 @@ FROM ( , EXTRACT(doy FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_doy , third_hop_table_src_22000.customer_third_hop_id FROM ***************************.third_hop_table third_hop_table_src_22000 - ) subq_6 - ) subq_7 - ) subq_8 + ) subq_11 + ) subq_12 + ) subq_13 LEFT OUTER JOIN ( -- Pass Only Elements: ['customer_id__customer_third_hop_id', 'customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_15.customer_id__customer_third_hop_id - , subq_15.customer_id__customer_third_hop_id__paraguayan_customers + subq_21.customer_id__customer_third_hop_id + , subq_21.customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Compute Metrics via Expressions SELECT - subq_14.customer_id__customer_third_hop_id - , subq_14.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers + subq_20.customer_id__customer_third_hop_id + , subq_20.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Aggregate Measures SELECT - subq_13.customer_id__customer_third_hop_id - , SUM(subq_13.customers_with_other_data) AS customers_with_other_data + subq_19.customer_id__customer_third_hop_id + , SUM(subq_19.customers_with_other_data) AS customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__customer_third_hop_id'] SELECT - subq_12.customer_id__customer_third_hop_id - , subq_12.customers_with_other_data + subq_18.customer_id__customer_third_hop_id + , subq_18.customers_with_other_data FROM ( -- Constrain Output with WHERE SELECT - subq_11.customer_id__customer_third_hop_id - , subq_11.customer_id__country - , subq_11.customers_with_other_data + subq_17.customer_id__customer_third_hop_id + , subq_17.customer_id__country + , subq_17.customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - subq_10.customer_id__customer_third_hop_id - , subq_10.customer_id__country - , subq_10.customers_with_other_data + subq_16.customer_id__customer_third_hop_id + , subq_16.customer_id__country + , subq_16.customers_with_other_data FROM ( - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE SELECT - subq_9.acquired_ds__day - , subq_9.acquired_ds__week - , subq_9.acquired_ds__month - , subq_9.acquired_ds__quarter - , subq_9.acquired_ds__year - , subq_9.acquired_ds__extract_year - , subq_9.acquired_ds__extract_quarter - , subq_9.acquired_ds__extract_month - , subq_9.acquired_ds__extract_day - , subq_9.acquired_ds__extract_dow - , subq_9.acquired_ds__extract_doy - , subq_9.customer_id__acquired_ds__day - , subq_9.customer_id__acquired_ds__week - , subq_9.customer_id__acquired_ds__month - , subq_9.customer_id__acquired_ds__quarter - , subq_9.customer_id__acquired_ds__year - , subq_9.customer_id__acquired_ds__extract_year - , subq_9.customer_id__acquired_ds__extract_quarter - , subq_9.customer_id__acquired_ds__extract_month - , subq_9.customer_id__acquired_ds__extract_day - , subq_9.customer_id__acquired_ds__extract_dow - , subq_9.customer_id__acquired_ds__extract_doy - , subq_9.customer_third_hop_id__acquired_ds__day - , subq_9.customer_third_hop_id__acquired_ds__week - , subq_9.customer_third_hop_id__acquired_ds__month - , subq_9.customer_third_hop_id__acquired_ds__quarter - , subq_9.customer_third_hop_id__acquired_ds__year - , subq_9.customer_third_hop_id__acquired_ds__extract_year - , subq_9.customer_third_hop_id__acquired_ds__extract_quarter - , subq_9.customer_third_hop_id__acquired_ds__extract_month - , subq_9.customer_third_hop_id__acquired_ds__extract_day - , subq_9.customer_third_hop_id__acquired_ds__extract_dow - , subq_9.customer_third_hop_id__acquired_ds__extract_doy - , subq_9.acquired_ds__day AS metric_time__day - , subq_9.acquired_ds__week AS metric_time__week - , subq_9.acquired_ds__month AS metric_time__month - , subq_9.acquired_ds__quarter AS metric_time__quarter - , subq_9.acquired_ds__year AS metric_time__year - , subq_9.acquired_ds__extract_year AS metric_time__extract_year - , subq_9.acquired_ds__extract_quarter AS metric_time__extract_quarter - , subq_9.acquired_ds__extract_month AS metric_time__extract_month - , subq_9.acquired_ds__extract_day AS metric_time__extract_day - , subq_9.acquired_ds__extract_dow AS metric_time__extract_dow - , subq_9.acquired_ds__extract_doy AS metric_time__extract_doy - , subq_9.customer_id - , subq_9.customer_third_hop_id - , subq_9.customer_id__customer_third_hop_id - , subq_9.customer_third_hop_id__customer_id - , subq_9.country - , subq_9.customer_id__country - , subq_9.customer_third_hop_id__country - , subq_9.customers_with_other_data + subq_15.acquired_ds__day + , subq_15.acquired_ds__week + , subq_15.acquired_ds__month + , subq_15.acquired_ds__quarter + , subq_15.acquired_ds__year + , subq_15.acquired_ds__extract_year + , subq_15.acquired_ds__extract_quarter + , subq_15.acquired_ds__extract_month + , subq_15.acquired_ds__extract_day + , subq_15.acquired_ds__extract_dow + , subq_15.acquired_ds__extract_doy + , subq_15.customer_id__acquired_ds__day + , subq_15.customer_id__acquired_ds__week + , subq_15.customer_id__acquired_ds__month + , subq_15.customer_id__acquired_ds__quarter + , subq_15.customer_id__acquired_ds__year + , subq_15.customer_id__acquired_ds__extract_year + , subq_15.customer_id__acquired_ds__extract_quarter + , subq_15.customer_id__acquired_ds__extract_month + , subq_15.customer_id__acquired_ds__extract_day + , subq_15.customer_id__acquired_ds__extract_dow + , subq_15.customer_id__acquired_ds__extract_doy + , subq_15.customer_third_hop_id__acquired_ds__day + , subq_15.customer_third_hop_id__acquired_ds__week + , subq_15.customer_third_hop_id__acquired_ds__month + , subq_15.customer_third_hop_id__acquired_ds__quarter + , subq_15.customer_third_hop_id__acquired_ds__year + , subq_15.customer_third_hop_id__acquired_ds__extract_year + , subq_15.customer_third_hop_id__acquired_ds__extract_quarter + , subq_15.customer_third_hop_id__acquired_ds__extract_month + , subq_15.customer_third_hop_id__acquired_ds__extract_day + , subq_15.customer_third_hop_id__acquired_ds__extract_dow + , subq_15.customer_third_hop_id__acquired_ds__extract_doy + , subq_15.metric_time__day + , subq_15.metric_time__week + , subq_15.metric_time__month + , subq_15.metric_time__quarter + , subq_15.metric_time__year + , subq_15.metric_time__extract_year + , subq_15.metric_time__extract_quarter + , subq_15.metric_time__extract_month + , subq_15.metric_time__extract_day + , subq_15.metric_time__extract_dow + , subq_15.metric_time__extract_doy + , subq_15.customer_id + , subq_15.customer_third_hop_id + , subq_15.customer_id__customer_third_hop_id + , subq_15.customer_third_hop_id__customer_id + , subq_15.country + , subq_15.customer_id__country + , subq_15.customer_third_hop_id__country + , subq_15.customers_with_other_data FROM ( - -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' SELECT - 1 AS customers_with_other_data - , customer_other_data_src_22000.country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day - , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day - , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_third_hop_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day - , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy - , customer_other_data_src_22000.customer_id - , customer_other_data_src_22000.customer_third_hop_id - , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id - , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_9 - ) subq_10 - ) subq_11 + subq_14.acquired_ds__day + , subq_14.acquired_ds__week + , subq_14.acquired_ds__month + , subq_14.acquired_ds__quarter + , subq_14.acquired_ds__year + , subq_14.acquired_ds__extract_year + , subq_14.acquired_ds__extract_quarter + , subq_14.acquired_ds__extract_month + , subq_14.acquired_ds__extract_day + , subq_14.acquired_ds__extract_dow + , subq_14.acquired_ds__extract_doy + , subq_14.customer_id__acquired_ds__day + , subq_14.customer_id__acquired_ds__week + , subq_14.customer_id__acquired_ds__month + , subq_14.customer_id__acquired_ds__quarter + , subq_14.customer_id__acquired_ds__year + , subq_14.customer_id__acquired_ds__extract_year + , subq_14.customer_id__acquired_ds__extract_quarter + , subq_14.customer_id__acquired_ds__extract_month + , subq_14.customer_id__acquired_ds__extract_day + , subq_14.customer_id__acquired_ds__extract_dow + , subq_14.customer_id__acquired_ds__extract_doy + , subq_14.customer_third_hop_id__acquired_ds__day + , subq_14.customer_third_hop_id__acquired_ds__week + , subq_14.customer_third_hop_id__acquired_ds__month + , subq_14.customer_third_hop_id__acquired_ds__quarter + , subq_14.customer_third_hop_id__acquired_ds__year + , subq_14.customer_third_hop_id__acquired_ds__extract_year + , subq_14.customer_third_hop_id__acquired_ds__extract_quarter + , subq_14.customer_third_hop_id__acquired_ds__extract_month + , subq_14.customer_third_hop_id__acquired_ds__extract_day + , subq_14.customer_third_hop_id__acquired_ds__extract_dow + , subq_14.customer_third_hop_id__acquired_ds__extract_doy + , subq_14.acquired_ds__day AS metric_time__day + , subq_14.acquired_ds__week AS metric_time__week + , subq_14.acquired_ds__month AS metric_time__month + , subq_14.acquired_ds__quarter AS metric_time__quarter + , subq_14.acquired_ds__year AS metric_time__year + , subq_14.acquired_ds__extract_year AS metric_time__extract_year + , subq_14.acquired_ds__extract_quarter AS metric_time__extract_quarter + , subq_14.acquired_ds__extract_month AS metric_time__extract_month + , subq_14.acquired_ds__extract_day AS metric_time__extract_day + , subq_14.acquired_ds__extract_dow AS metric_time__extract_dow + , subq_14.acquired_ds__extract_doy AS metric_time__extract_doy + , subq_14.customer_id + , subq_14.customer_third_hop_id + , subq_14.customer_id__customer_third_hop_id + , subq_14.customer_third_hop_id__customer_id + , subq_14.country + , subq_14.customer_id__country + , subq_14.customer_third_hop_id__country + , subq_14.customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + SELECT + 1 AS customers_with_other_data + , customer_other_data_src_22000.country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day + , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day + , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_third_hop_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day + , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy + , customer_other_data_src_22000.customer_id + , customer_other_data_src_22000.customer_third_hop_id + , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id + , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_14 + ) subq_15 + WHERE customer_id__country = 'paraguay' + ) subq_16 + ) subq_17 WHERE customer_id__country = 'paraguay' - ) subq_12 - ) subq_13 + ) subq_18 + ) subq_19 GROUP BY - subq_13.customer_id__customer_third_hop_id - ) subq_14 - ) subq_15 - ) subq_16 + subq_19.customer_id__customer_third_hop_id + ) subq_20 + ) subq_21 + ) subq_22 ON - subq_8.customer_third_hop_id = subq_16.customer_id__customer_third_hop_id - ) subq_17 - ) subq_18 + subq_13.customer_third_hop_id = subq_22.customer_id__customer_third_hop_id + ) subq_23 + ) subq_24 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 - ) subq_19 - ) subq_20 -) subq_21 + ) subq_25 + ) subq_26 +) subq_27 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Postgres/test_inner_query_single_hop__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Postgres/test_inner_query_single_hop__plan0_optimized.sql index 2ad52ec04c..7c12d6cf98 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Postgres/test_inner_query_single_hop__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Postgres/test_inner_query_single_hop__plan0_optimized.sql @@ -8,7 +8,7 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_32.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + subq_39.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers , third_hop_table_src_22000.customer_third_hop_id AS third_hop_count FROM ***************************.third_hop_table third_hop_table_src_22000 LEFT OUTER JOIN ( @@ -21,20 +21,28 @@ FROM ( customer_id__customer_third_hop_id , SUM(customers_with_other_data) AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( - -- Read Elements From Semantic Model 'customer_other_data' - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - customer_third_hop_id AS customer_id__customer_third_hop_id - , country AS customer_id__country - , 1 AS customers_with_other_data - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_27 + customer_id__customer_third_hop_id + , customer_id__country + , customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' + SELECT + customer_third_hop_id AS customer_id__customer_third_hop_id + , country AS customer_id__country + , 1 AS customers_with_other_data + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_32 + WHERE customer_id__country = 'paraguay' + ) subq_34 WHERE customer_id__country = 'paraguay' GROUP BY customer_id__customer_third_hop_id - ) subq_32 + ) subq_39 ON - third_hop_table_src_22000.customer_third_hop_id = subq_32.customer_id__customer_third_hop_id -) subq_34 + third_hop_table_src_22000.customer_third_hop_id = subq_39.customer_id__customer_third_hop_id +) subq_41 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Redshift/test_inner_query_single_hop__plan0.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Redshift/test_inner_query_single_hop__plan0.sql index f881118554..deeac7d968 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Redshift/test_inner_query_single_hop__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Redshift/test_inner_query_single_hop__plan0.sql @@ -1,76 +1,76 @@ -- Compute Metrics via Expressions SELECT - subq_21.third_hop_count + subq_27.third_hop_count FROM ( -- Aggregate Measures SELECT - COUNT(DISTINCT subq_20.third_hop_count) AS third_hop_count + COUNT(DISTINCT subq_26.third_hop_count) AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count',] SELECT - subq_19.third_hop_count + subq_25.third_hop_count FROM ( -- Constrain Output with WHERE SELECT - subq_18.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_18.third_hop_count + subq_24.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_24.third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_17.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_17.third_hop_count + subq_23.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_23.third_hop_count FROM ( -- Join Standard Outputs SELECT - subq_8.customer_third_hop_id AS customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_8.third_hop_count AS third_hop_count + subq_13.customer_third_hop_id AS customer_third_hop_id + , subq_22.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id + , subq_22.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_13.third_hop_count AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id'] SELECT - subq_7.customer_third_hop_id - , subq_7.third_hop_count + subq_12.customer_third_hop_id + , subq_12.third_hop_count FROM ( -- Metric Time Dimension 'third_hop_ds' SELECT - subq_6.third_hop_ds__day - , subq_6.third_hop_ds__week - , subq_6.third_hop_ds__month - , subq_6.third_hop_ds__quarter - , subq_6.third_hop_ds__year - , subq_6.third_hop_ds__extract_year - , subq_6.third_hop_ds__extract_quarter - , subq_6.third_hop_ds__extract_month - , subq_6.third_hop_ds__extract_day - , subq_6.third_hop_ds__extract_dow - , subq_6.third_hop_ds__extract_doy - , subq_6.customer_third_hop_id__third_hop_ds__day - , subq_6.customer_third_hop_id__third_hop_ds__week - , subq_6.customer_third_hop_id__third_hop_ds__month - , subq_6.customer_third_hop_id__third_hop_ds__quarter - , subq_6.customer_third_hop_id__third_hop_ds__year - , subq_6.customer_third_hop_id__third_hop_ds__extract_year - , subq_6.customer_third_hop_id__third_hop_ds__extract_quarter - , subq_6.customer_third_hop_id__third_hop_ds__extract_month - , subq_6.customer_third_hop_id__third_hop_ds__extract_day - , subq_6.customer_third_hop_id__third_hop_ds__extract_dow - , subq_6.customer_third_hop_id__third_hop_ds__extract_doy - , subq_6.third_hop_ds__day AS metric_time__day - , subq_6.third_hop_ds__week AS metric_time__week - , subq_6.third_hop_ds__month AS metric_time__month - , subq_6.third_hop_ds__quarter AS metric_time__quarter - , subq_6.third_hop_ds__year AS metric_time__year - , subq_6.third_hop_ds__extract_year AS metric_time__extract_year - , subq_6.third_hop_ds__extract_quarter AS metric_time__extract_quarter - , subq_6.third_hop_ds__extract_month AS metric_time__extract_month - , subq_6.third_hop_ds__extract_day AS metric_time__extract_day - , subq_6.third_hop_ds__extract_dow AS metric_time__extract_dow - , subq_6.third_hop_ds__extract_doy AS metric_time__extract_doy - , subq_6.customer_third_hop_id - , subq_6.value - , subq_6.customer_third_hop_id__value - , subq_6.third_hop_count + subq_11.third_hop_ds__day + , subq_11.third_hop_ds__week + , subq_11.third_hop_ds__month + , subq_11.third_hop_ds__quarter + , subq_11.third_hop_ds__year + , subq_11.third_hop_ds__extract_year + , subq_11.third_hop_ds__extract_quarter + , subq_11.third_hop_ds__extract_month + , subq_11.third_hop_ds__extract_day + , subq_11.third_hop_ds__extract_dow + , subq_11.third_hop_ds__extract_doy + , subq_11.customer_third_hop_id__third_hop_ds__day + , subq_11.customer_third_hop_id__third_hop_ds__week + , subq_11.customer_third_hop_id__third_hop_ds__month + , subq_11.customer_third_hop_id__third_hop_ds__quarter + , subq_11.customer_third_hop_id__third_hop_ds__year + , subq_11.customer_third_hop_id__third_hop_ds__extract_year + , subq_11.customer_third_hop_id__third_hop_ds__extract_quarter + , subq_11.customer_third_hop_id__third_hop_ds__extract_month + , subq_11.customer_third_hop_id__third_hop_ds__extract_day + , subq_11.customer_third_hop_id__third_hop_ds__extract_dow + , subq_11.customer_third_hop_id__third_hop_ds__extract_doy + , subq_11.third_hop_ds__day AS metric_time__day + , subq_11.third_hop_ds__week AS metric_time__week + , subq_11.third_hop_ds__month AS metric_time__month + , subq_11.third_hop_ds__quarter AS metric_time__quarter + , subq_11.third_hop_ds__year AS metric_time__year + , subq_11.third_hop_ds__extract_year AS metric_time__extract_year + , subq_11.third_hop_ds__extract_quarter AS metric_time__extract_quarter + , subq_11.third_hop_ds__extract_month AS metric_time__extract_month + , subq_11.third_hop_ds__extract_day AS metric_time__extract_day + , subq_11.third_hop_ds__extract_dow AS metric_time__extract_dow + , subq_11.third_hop_ds__extract_doy AS metric_time__extract_doy + , subq_11.customer_third_hop_id + , subq_11.value + , subq_11.customer_third_hop_id__value + , subq_11.third_hop_count FROM ( -- Read Elements From Semantic Model 'third_hop_table' SELECT @@ -101,157 +101,214 @@ FROM ( , EXTRACT(doy FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_doy , third_hop_table_src_22000.customer_third_hop_id FROM ***************************.third_hop_table third_hop_table_src_22000 - ) subq_6 - ) subq_7 - ) subq_8 + ) subq_11 + ) subq_12 + ) subq_13 LEFT OUTER JOIN ( -- Pass Only Elements: ['customer_id__customer_third_hop_id', 'customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_15.customer_id__customer_third_hop_id - , subq_15.customer_id__customer_third_hop_id__paraguayan_customers + subq_21.customer_id__customer_third_hop_id + , subq_21.customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Compute Metrics via Expressions SELECT - subq_14.customer_id__customer_third_hop_id - , subq_14.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers + subq_20.customer_id__customer_third_hop_id + , subq_20.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Aggregate Measures SELECT - subq_13.customer_id__customer_third_hop_id - , SUM(subq_13.customers_with_other_data) AS customers_with_other_data + subq_19.customer_id__customer_third_hop_id + , SUM(subq_19.customers_with_other_data) AS customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__customer_third_hop_id'] SELECT - subq_12.customer_id__customer_third_hop_id - , subq_12.customers_with_other_data + subq_18.customer_id__customer_third_hop_id + , subq_18.customers_with_other_data FROM ( -- Constrain Output with WHERE SELECT - subq_11.customer_id__customer_third_hop_id - , subq_11.customer_id__country - , subq_11.customers_with_other_data + subq_17.customer_id__customer_third_hop_id + , subq_17.customer_id__country + , subq_17.customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - subq_10.customer_id__customer_third_hop_id - , subq_10.customer_id__country - , subq_10.customers_with_other_data + subq_16.customer_id__customer_third_hop_id + , subq_16.customer_id__country + , subq_16.customers_with_other_data FROM ( - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE SELECT - subq_9.acquired_ds__day - , subq_9.acquired_ds__week - , subq_9.acquired_ds__month - , subq_9.acquired_ds__quarter - , subq_9.acquired_ds__year - , subq_9.acquired_ds__extract_year - , subq_9.acquired_ds__extract_quarter - , subq_9.acquired_ds__extract_month - , subq_9.acquired_ds__extract_day - , subq_9.acquired_ds__extract_dow - , subq_9.acquired_ds__extract_doy - , subq_9.customer_id__acquired_ds__day - , subq_9.customer_id__acquired_ds__week - , subq_9.customer_id__acquired_ds__month - , subq_9.customer_id__acquired_ds__quarter - , subq_9.customer_id__acquired_ds__year - , subq_9.customer_id__acquired_ds__extract_year - , subq_9.customer_id__acquired_ds__extract_quarter - , subq_9.customer_id__acquired_ds__extract_month - , subq_9.customer_id__acquired_ds__extract_day - , subq_9.customer_id__acquired_ds__extract_dow - , subq_9.customer_id__acquired_ds__extract_doy - , subq_9.customer_third_hop_id__acquired_ds__day - , subq_9.customer_third_hop_id__acquired_ds__week - , subq_9.customer_third_hop_id__acquired_ds__month - , subq_9.customer_third_hop_id__acquired_ds__quarter - , subq_9.customer_third_hop_id__acquired_ds__year - , subq_9.customer_third_hop_id__acquired_ds__extract_year - , subq_9.customer_third_hop_id__acquired_ds__extract_quarter - , subq_9.customer_third_hop_id__acquired_ds__extract_month - , subq_9.customer_third_hop_id__acquired_ds__extract_day - , subq_9.customer_third_hop_id__acquired_ds__extract_dow - , subq_9.customer_third_hop_id__acquired_ds__extract_doy - , subq_9.acquired_ds__day AS metric_time__day - , subq_9.acquired_ds__week AS metric_time__week - , subq_9.acquired_ds__month AS metric_time__month - , subq_9.acquired_ds__quarter AS metric_time__quarter - , subq_9.acquired_ds__year AS metric_time__year - , subq_9.acquired_ds__extract_year AS metric_time__extract_year - , subq_9.acquired_ds__extract_quarter AS metric_time__extract_quarter - , subq_9.acquired_ds__extract_month AS metric_time__extract_month - , subq_9.acquired_ds__extract_day AS metric_time__extract_day - , subq_9.acquired_ds__extract_dow AS metric_time__extract_dow - , subq_9.acquired_ds__extract_doy AS metric_time__extract_doy - , subq_9.customer_id - , subq_9.customer_third_hop_id - , subq_9.customer_id__customer_third_hop_id - , subq_9.customer_third_hop_id__customer_id - , subq_9.country - , subq_9.customer_id__country - , subq_9.customer_third_hop_id__country - , subq_9.customers_with_other_data + subq_15.acquired_ds__day + , subq_15.acquired_ds__week + , subq_15.acquired_ds__month + , subq_15.acquired_ds__quarter + , subq_15.acquired_ds__year + , subq_15.acquired_ds__extract_year + , subq_15.acquired_ds__extract_quarter + , subq_15.acquired_ds__extract_month + , subq_15.acquired_ds__extract_day + , subq_15.acquired_ds__extract_dow + , subq_15.acquired_ds__extract_doy + , subq_15.customer_id__acquired_ds__day + , subq_15.customer_id__acquired_ds__week + , subq_15.customer_id__acquired_ds__month + , subq_15.customer_id__acquired_ds__quarter + , subq_15.customer_id__acquired_ds__year + , subq_15.customer_id__acquired_ds__extract_year + , subq_15.customer_id__acquired_ds__extract_quarter + , subq_15.customer_id__acquired_ds__extract_month + , subq_15.customer_id__acquired_ds__extract_day + , subq_15.customer_id__acquired_ds__extract_dow + , subq_15.customer_id__acquired_ds__extract_doy + , subq_15.customer_third_hop_id__acquired_ds__day + , subq_15.customer_third_hop_id__acquired_ds__week + , subq_15.customer_third_hop_id__acquired_ds__month + , subq_15.customer_third_hop_id__acquired_ds__quarter + , subq_15.customer_third_hop_id__acquired_ds__year + , subq_15.customer_third_hop_id__acquired_ds__extract_year + , subq_15.customer_third_hop_id__acquired_ds__extract_quarter + , subq_15.customer_third_hop_id__acquired_ds__extract_month + , subq_15.customer_third_hop_id__acquired_ds__extract_day + , subq_15.customer_third_hop_id__acquired_ds__extract_dow + , subq_15.customer_third_hop_id__acquired_ds__extract_doy + , subq_15.metric_time__day + , subq_15.metric_time__week + , subq_15.metric_time__month + , subq_15.metric_time__quarter + , subq_15.metric_time__year + , subq_15.metric_time__extract_year + , subq_15.metric_time__extract_quarter + , subq_15.metric_time__extract_month + , subq_15.metric_time__extract_day + , subq_15.metric_time__extract_dow + , subq_15.metric_time__extract_doy + , subq_15.customer_id + , subq_15.customer_third_hop_id + , subq_15.customer_id__customer_third_hop_id + , subq_15.customer_third_hop_id__customer_id + , subq_15.country + , subq_15.customer_id__country + , subq_15.customer_third_hop_id__country + , subq_15.customers_with_other_data FROM ( - -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' SELECT - 1 AS customers_with_other_data - , customer_other_data_src_22000.country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day - , CASE WHEN EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) = 0 THEN EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) + 7 ELSE EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) END AS acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day - , CASE WHEN EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) = 0 THEN EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) + 7 ELSE EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) END AS customer_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_third_hop_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day - , CASE WHEN EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) = 0 THEN EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) + 7 ELSE EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) END AS customer_third_hop_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy - , customer_other_data_src_22000.customer_id - , customer_other_data_src_22000.customer_third_hop_id - , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id - , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_9 - ) subq_10 - ) subq_11 + subq_14.acquired_ds__day + , subq_14.acquired_ds__week + , subq_14.acquired_ds__month + , subq_14.acquired_ds__quarter + , subq_14.acquired_ds__year + , subq_14.acquired_ds__extract_year + , subq_14.acquired_ds__extract_quarter + , subq_14.acquired_ds__extract_month + , subq_14.acquired_ds__extract_day + , subq_14.acquired_ds__extract_dow + , subq_14.acquired_ds__extract_doy + , subq_14.customer_id__acquired_ds__day + , subq_14.customer_id__acquired_ds__week + , subq_14.customer_id__acquired_ds__month + , subq_14.customer_id__acquired_ds__quarter + , subq_14.customer_id__acquired_ds__year + , subq_14.customer_id__acquired_ds__extract_year + , subq_14.customer_id__acquired_ds__extract_quarter + , subq_14.customer_id__acquired_ds__extract_month + , subq_14.customer_id__acquired_ds__extract_day + , subq_14.customer_id__acquired_ds__extract_dow + , subq_14.customer_id__acquired_ds__extract_doy + , subq_14.customer_third_hop_id__acquired_ds__day + , subq_14.customer_third_hop_id__acquired_ds__week + , subq_14.customer_third_hop_id__acquired_ds__month + , subq_14.customer_third_hop_id__acquired_ds__quarter + , subq_14.customer_third_hop_id__acquired_ds__year + , subq_14.customer_third_hop_id__acquired_ds__extract_year + , subq_14.customer_third_hop_id__acquired_ds__extract_quarter + , subq_14.customer_third_hop_id__acquired_ds__extract_month + , subq_14.customer_third_hop_id__acquired_ds__extract_day + , subq_14.customer_third_hop_id__acquired_ds__extract_dow + , subq_14.customer_third_hop_id__acquired_ds__extract_doy + , subq_14.acquired_ds__day AS metric_time__day + , subq_14.acquired_ds__week AS metric_time__week + , subq_14.acquired_ds__month AS metric_time__month + , subq_14.acquired_ds__quarter AS metric_time__quarter + , subq_14.acquired_ds__year AS metric_time__year + , subq_14.acquired_ds__extract_year AS metric_time__extract_year + , subq_14.acquired_ds__extract_quarter AS metric_time__extract_quarter + , subq_14.acquired_ds__extract_month AS metric_time__extract_month + , subq_14.acquired_ds__extract_day AS metric_time__extract_day + , subq_14.acquired_ds__extract_dow AS metric_time__extract_dow + , subq_14.acquired_ds__extract_doy AS metric_time__extract_doy + , subq_14.customer_id + , subq_14.customer_third_hop_id + , subq_14.customer_id__customer_third_hop_id + , subq_14.customer_third_hop_id__customer_id + , subq_14.country + , subq_14.customer_id__country + , subq_14.customer_third_hop_id__country + , subq_14.customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + SELECT + 1 AS customers_with_other_data + , customer_other_data_src_22000.country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day + , CASE WHEN EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) = 0 THEN EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) + 7 ELSE EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) END AS acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day + , CASE WHEN EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) = 0 THEN EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) + 7 ELSE EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) END AS customer_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_third_hop_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day + , CASE WHEN EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) = 0 THEN EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) + 7 ELSE EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) END AS customer_third_hop_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy + , customer_other_data_src_22000.customer_id + , customer_other_data_src_22000.customer_third_hop_id + , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id + , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_14 + ) subq_15 + WHERE customer_id__country = 'paraguay' + ) subq_16 + ) subq_17 WHERE customer_id__country = 'paraguay' - ) subq_12 - ) subq_13 + ) subq_18 + ) subq_19 GROUP BY - subq_13.customer_id__customer_third_hop_id - ) subq_14 - ) subq_15 - ) subq_16 + subq_19.customer_id__customer_third_hop_id + ) subq_20 + ) subq_21 + ) subq_22 ON - subq_8.customer_third_hop_id = subq_16.customer_id__customer_third_hop_id - ) subq_17 - ) subq_18 + subq_13.customer_third_hop_id = subq_22.customer_id__customer_third_hop_id + ) subq_23 + ) subq_24 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 - ) subq_19 - ) subq_20 -) subq_21 + ) subq_25 + ) subq_26 +) subq_27 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Redshift/test_inner_query_single_hop__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Redshift/test_inner_query_single_hop__plan0_optimized.sql index 2ad52ec04c..7c12d6cf98 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Redshift/test_inner_query_single_hop__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Redshift/test_inner_query_single_hop__plan0_optimized.sql @@ -8,7 +8,7 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_32.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + subq_39.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers , third_hop_table_src_22000.customer_third_hop_id AS third_hop_count FROM ***************************.third_hop_table third_hop_table_src_22000 LEFT OUTER JOIN ( @@ -21,20 +21,28 @@ FROM ( customer_id__customer_third_hop_id , SUM(customers_with_other_data) AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( - -- Read Elements From Semantic Model 'customer_other_data' - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - customer_third_hop_id AS customer_id__customer_third_hop_id - , country AS customer_id__country - , 1 AS customers_with_other_data - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_27 + customer_id__customer_third_hop_id + , customer_id__country + , customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' + SELECT + customer_third_hop_id AS customer_id__customer_third_hop_id + , country AS customer_id__country + , 1 AS customers_with_other_data + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_32 + WHERE customer_id__country = 'paraguay' + ) subq_34 WHERE customer_id__country = 'paraguay' GROUP BY customer_id__customer_third_hop_id - ) subq_32 + ) subq_39 ON - third_hop_table_src_22000.customer_third_hop_id = subq_32.customer_id__customer_third_hop_id -) subq_34 + third_hop_table_src_22000.customer_third_hop_id = subq_39.customer_id__customer_third_hop_id +) subq_41 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Snowflake/test_inner_query_single_hop__plan0.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Snowflake/test_inner_query_single_hop__plan0.sql index 9cebbd1f96..3e8a0a8f2a 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Snowflake/test_inner_query_single_hop__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Snowflake/test_inner_query_single_hop__plan0.sql @@ -1,76 +1,76 @@ -- Compute Metrics via Expressions SELECT - subq_21.third_hop_count + subq_27.third_hop_count FROM ( -- Aggregate Measures SELECT - COUNT(DISTINCT subq_20.third_hop_count) AS third_hop_count + COUNT(DISTINCT subq_26.third_hop_count) AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count',] SELECT - subq_19.third_hop_count + subq_25.third_hop_count FROM ( -- Constrain Output with WHERE SELECT - subq_18.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_18.third_hop_count + subq_24.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_24.third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_17.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_17.third_hop_count + subq_23.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_23.third_hop_count FROM ( -- Join Standard Outputs SELECT - subq_8.customer_third_hop_id AS customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_8.third_hop_count AS third_hop_count + subq_13.customer_third_hop_id AS customer_third_hop_id + , subq_22.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id + , subq_22.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_13.third_hop_count AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id'] SELECT - subq_7.customer_third_hop_id - , subq_7.third_hop_count + subq_12.customer_third_hop_id + , subq_12.third_hop_count FROM ( -- Metric Time Dimension 'third_hop_ds' SELECT - subq_6.third_hop_ds__day - , subq_6.third_hop_ds__week - , subq_6.third_hop_ds__month - , subq_6.third_hop_ds__quarter - , subq_6.third_hop_ds__year - , subq_6.third_hop_ds__extract_year - , subq_6.third_hop_ds__extract_quarter - , subq_6.third_hop_ds__extract_month - , subq_6.third_hop_ds__extract_day - , subq_6.third_hop_ds__extract_dow - , subq_6.third_hop_ds__extract_doy - , subq_6.customer_third_hop_id__third_hop_ds__day - , subq_6.customer_third_hop_id__third_hop_ds__week - , subq_6.customer_third_hop_id__third_hop_ds__month - , subq_6.customer_third_hop_id__third_hop_ds__quarter - , subq_6.customer_third_hop_id__third_hop_ds__year - , subq_6.customer_third_hop_id__third_hop_ds__extract_year - , subq_6.customer_third_hop_id__third_hop_ds__extract_quarter - , subq_6.customer_third_hop_id__third_hop_ds__extract_month - , subq_6.customer_third_hop_id__third_hop_ds__extract_day - , subq_6.customer_third_hop_id__third_hop_ds__extract_dow - , subq_6.customer_third_hop_id__third_hop_ds__extract_doy - , subq_6.third_hop_ds__day AS metric_time__day - , subq_6.third_hop_ds__week AS metric_time__week - , subq_6.third_hop_ds__month AS metric_time__month - , subq_6.third_hop_ds__quarter AS metric_time__quarter - , subq_6.third_hop_ds__year AS metric_time__year - , subq_6.third_hop_ds__extract_year AS metric_time__extract_year - , subq_6.third_hop_ds__extract_quarter AS metric_time__extract_quarter - , subq_6.third_hop_ds__extract_month AS metric_time__extract_month - , subq_6.third_hop_ds__extract_day AS metric_time__extract_day - , subq_6.third_hop_ds__extract_dow AS metric_time__extract_dow - , subq_6.third_hop_ds__extract_doy AS metric_time__extract_doy - , subq_6.customer_third_hop_id - , subq_6.value - , subq_6.customer_third_hop_id__value - , subq_6.third_hop_count + subq_11.third_hop_ds__day + , subq_11.third_hop_ds__week + , subq_11.third_hop_ds__month + , subq_11.third_hop_ds__quarter + , subq_11.third_hop_ds__year + , subq_11.third_hop_ds__extract_year + , subq_11.third_hop_ds__extract_quarter + , subq_11.third_hop_ds__extract_month + , subq_11.third_hop_ds__extract_day + , subq_11.third_hop_ds__extract_dow + , subq_11.third_hop_ds__extract_doy + , subq_11.customer_third_hop_id__third_hop_ds__day + , subq_11.customer_third_hop_id__third_hop_ds__week + , subq_11.customer_third_hop_id__third_hop_ds__month + , subq_11.customer_third_hop_id__third_hop_ds__quarter + , subq_11.customer_third_hop_id__third_hop_ds__year + , subq_11.customer_third_hop_id__third_hop_ds__extract_year + , subq_11.customer_third_hop_id__third_hop_ds__extract_quarter + , subq_11.customer_third_hop_id__third_hop_ds__extract_month + , subq_11.customer_third_hop_id__third_hop_ds__extract_day + , subq_11.customer_third_hop_id__third_hop_ds__extract_dow + , subq_11.customer_third_hop_id__third_hop_ds__extract_doy + , subq_11.third_hop_ds__day AS metric_time__day + , subq_11.third_hop_ds__week AS metric_time__week + , subq_11.third_hop_ds__month AS metric_time__month + , subq_11.third_hop_ds__quarter AS metric_time__quarter + , subq_11.third_hop_ds__year AS metric_time__year + , subq_11.third_hop_ds__extract_year AS metric_time__extract_year + , subq_11.third_hop_ds__extract_quarter AS metric_time__extract_quarter + , subq_11.third_hop_ds__extract_month AS metric_time__extract_month + , subq_11.third_hop_ds__extract_day AS metric_time__extract_day + , subq_11.third_hop_ds__extract_dow AS metric_time__extract_dow + , subq_11.third_hop_ds__extract_doy AS metric_time__extract_doy + , subq_11.customer_third_hop_id + , subq_11.value + , subq_11.customer_third_hop_id__value + , subq_11.third_hop_count FROM ( -- Read Elements From Semantic Model 'third_hop_table' SELECT @@ -101,157 +101,214 @@ FROM ( , EXTRACT(doy FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_doy , third_hop_table_src_22000.customer_third_hop_id FROM ***************************.third_hop_table third_hop_table_src_22000 - ) subq_6 - ) subq_7 - ) subq_8 + ) subq_11 + ) subq_12 + ) subq_13 LEFT OUTER JOIN ( -- Pass Only Elements: ['customer_id__customer_third_hop_id', 'customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_15.customer_id__customer_third_hop_id - , subq_15.customer_id__customer_third_hop_id__paraguayan_customers + subq_21.customer_id__customer_third_hop_id + , subq_21.customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Compute Metrics via Expressions SELECT - subq_14.customer_id__customer_third_hop_id - , subq_14.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers + subq_20.customer_id__customer_third_hop_id + , subq_20.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Aggregate Measures SELECT - subq_13.customer_id__customer_third_hop_id - , SUM(subq_13.customers_with_other_data) AS customers_with_other_data + subq_19.customer_id__customer_third_hop_id + , SUM(subq_19.customers_with_other_data) AS customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__customer_third_hop_id'] SELECT - subq_12.customer_id__customer_third_hop_id - , subq_12.customers_with_other_data + subq_18.customer_id__customer_third_hop_id + , subq_18.customers_with_other_data FROM ( -- Constrain Output with WHERE SELECT - subq_11.customer_id__customer_third_hop_id - , subq_11.customer_id__country - , subq_11.customers_with_other_data + subq_17.customer_id__customer_third_hop_id + , subq_17.customer_id__country + , subq_17.customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - subq_10.customer_id__customer_third_hop_id - , subq_10.customer_id__country - , subq_10.customers_with_other_data + subq_16.customer_id__customer_third_hop_id + , subq_16.customer_id__country + , subq_16.customers_with_other_data FROM ( - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE SELECT - subq_9.acquired_ds__day - , subq_9.acquired_ds__week - , subq_9.acquired_ds__month - , subq_9.acquired_ds__quarter - , subq_9.acquired_ds__year - , subq_9.acquired_ds__extract_year - , subq_9.acquired_ds__extract_quarter - , subq_9.acquired_ds__extract_month - , subq_9.acquired_ds__extract_day - , subq_9.acquired_ds__extract_dow - , subq_9.acquired_ds__extract_doy - , subq_9.customer_id__acquired_ds__day - , subq_9.customer_id__acquired_ds__week - , subq_9.customer_id__acquired_ds__month - , subq_9.customer_id__acquired_ds__quarter - , subq_9.customer_id__acquired_ds__year - , subq_9.customer_id__acquired_ds__extract_year - , subq_9.customer_id__acquired_ds__extract_quarter - , subq_9.customer_id__acquired_ds__extract_month - , subq_9.customer_id__acquired_ds__extract_day - , subq_9.customer_id__acquired_ds__extract_dow - , subq_9.customer_id__acquired_ds__extract_doy - , subq_9.customer_third_hop_id__acquired_ds__day - , subq_9.customer_third_hop_id__acquired_ds__week - , subq_9.customer_third_hop_id__acquired_ds__month - , subq_9.customer_third_hop_id__acquired_ds__quarter - , subq_9.customer_third_hop_id__acquired_ds__year - , subq_9.customer_third_hop_id__acquired_ds__extract_year - , subq_9.customer_third_hop_id__acquired_ds__extract_quarter - , subq_9.customer_third_hop_id__acquired_ds__extract_month - , subq_9.customer_third_hop_id__acquired_ds__extract_day - , subq_9.customer_third_hop_id__acquired_ds__extract_dow - , subq_9.customer_third_hop_id__acquired_ds__extract_doy - , subq_9.acquired_ds__day AS metric_time__day - , subq_9.acquired_ds__week AS metric_time__week - , subq_9.acquired_ds__month AS metric_time__month - , subq_9.acquired_ds__quarter AS metric_time__quarter - , subq_9.acquired_ds__year AS metric_time__year - , subq_9.acquired_ds__extract_year AS metric_time__extract_year - , subq_9.acquired_ds__extract_quarter AS metric_time__extract_quarter - , subq_9.acquired_ds__extract_month AS metric_time__extract_month - , subq_9.acquired_ds__extract_day AS metric_time__extract_day - , subq_9.acquired_ds__extract_dow AS metric_time__extract_dow - , subq_9.acquired_ds__extract_doy AS metric_time__extract_doy - , subq_9.customer_id - , subq_9.customer_third_hop_id - , subq_9.customer_id__customer_third_hop_id - , subq_9.customer_third_hop_id__customer_id - , subq_9.country - , subq_9.customer_id__country - , subq_9.customer_third_hop_id__country - , subq_9.customers_with_other_data + subq_15.acquired_ds__day + , subq_15.acquired_ds__week + , subq_15.acquired_ds__month + , subq_15.acquired_ds__quarter + , subq_15.acquired_ds__year + , subq_15.acquired_ds__extract_year + , subq_15.acquired_ds__extract_quarter + , subq_15.acquired_ds__extract_month + , subq_15.acquired_ds__extract_day + , subq_15.acquired_ds__extract_dow + , subq_15.acquired_ds__extract_doy + , subq_15.customer_id__acquired_ds__day + , subq_15.customer_id__acquired_ds__week + , subq_15.customer_id__acquired_ds__month + , subq_15.customer_id__acquired_ds__quarter + , subq_15.customer_id__acquired_ds__year + , subq_15.customer_id__acquired_ds__extract_year + , subq_15.customer_id__acquired_ds__extract_quarter + , subq_15.customer_id__acquired_ds__extract_month + , subq_15.customer_id__acquired_ds__extract_day + , subq_15.customer_id__acquired_ds__extract_dow + , subq_15.customer_id__acquired_ds__extract_doy + , subq_15.customer_third_hop_id__acquired_ds__day + , subq_15.customer_third_hop_id__acquired_ds__week + , subq_15.customer_third_hop_id__acquired_ds__month + , subq_15.customer_third_hop_id__acquired_ds__quarter + , subq_15.customer_third_hop_id__acquired_ds__year + , subq_15.customer_third_hop_id__acquired_ds__extract_year + , subq_15.customer_third_hop_id__acquired_ds__extract_quarter + , subq_15.customer_third_hop_id__acquired_ds__extract_month + , subq_15.customer_third_hop_id__acquired_ds__extract_day + , subq_15.customer_third_hop_id__acquired_ds__extract_dow + , subq_15.customer_third_hop_id__acquired_ds__extract_doy + , subq_15.metric_time__day + , subq_15.metric_time__week + , subq_15.metric_time__month + , subq_15.metric_time__quarter + , subq_15.metric_time__year + , subq_15.metric_time__extract_year + , subq_15.metric_time__extract_quarter + , subq_15.metric_time__extract_month + , subq_15.metric_time__extract_day + , subq_15.metric_time__extract_dow + , subq_15.metric_time__extract_doy + , subq_15.customer_id + , subq_15.customer_third_hop_id + , subq_15.customer_id__customer_third_hop_id + , subq_15.customer_third_hop_id__customer_id + , subq_15.country + , subq_15.customer_id__country + , subq_15.customer_third_hop_id__country + , subq_15.customers_with_other_data FROM ( - -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' SELECT - 1 AS customers_with_other_data - , customer_other_data_src_22000.country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day - , EXTRACT(dayofweekiso FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day - , EXTRACT(dayofweekiso FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_third_hop_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day - , EXTRACT(dayofweekiso FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy - , customer_other_data_src_22000.customer_id - , customer_other_data_src_22000.customer_third_hop_id - , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id - , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_9 - ) subq_10 - ) subq_11 + subq_14.acquired_ds__day + , subq_14.acquired_ds__week + , subq_14.acquired_ds__month + , subq_14.acquired_ds__quarter + , subq_14.acquired_ds__year + , subq_14.acquired_ds__extract_year + , subq_14.acquired_ds__extract_quarter + , subq_14.acquired_ds__extract_month + , subq_14.acquired_ds__extract_day + , subq_14.acquired_ds__extract_dow + , subq_14.acquired_ds__extract_doy + , subq_14.customer_id__acquired_ds__day + , subq_14.customer_id__acquired_ds__week + , subq_14.customer_id__acquired_ds__month + , subq_14.customer_id__acquired_ds__quarter + , subq_14.customer_id__acquired_ds__year + , subq_14.customer_id__acquired_ds__extract_year + , subq_14.customer_id__acquired_ds__extract_quarter + , subq_14.customer_id__acquired_ds__extract_month + , subq_14.customer_id__acquired_ds__extract_day + , subq_14.customer_id__acquired_ds__extract_dow + , subq_14.customer_id__acquired_ds__extract_doy + , subq_14.customer_third_hop_id__acquired_ds__day + , subq_14.customer_third_hop_id__acquired_ds__week + , subq_14.customer_third_hop_id__acquired_ds__month + , subq_14.customer_third_hop_id__acquired_ds__quarter + , subq_14.customer_third_hop_id__acquired_ds__year + , subq_14.customer_third_hop_id__acquired_ds__extract_year + , subq_14.customer_third_hop_id__acquired_ds__extract_quarter + , subq_14.customer_third_hop_id__acquired_ds__extract_month + , subq_14.customer_third_hop_id__acquired_ds__extract_day + , subq_14.customer_third_hop_id__acquired_ds__extract_dow + , subq_14.customer_third_hop_id__acquired_ds__extract_doy + , subq_14.acquired_ds__day AS metric_time__day + , subq_14.acquired_ds__week AS metric_time__week + , subq_14.acquired_ds__month AS metric_time__month + , subq_14.acquired_ds__quarter AS metric_time__quarter + , subq_14.acquired_ds__year AS metric_time__year + , subq_14.acquired_ds__extract_year AS metric_time__extract_year + , subq_14.acquired_ds__extract_quarter AS metric_time__extract_quarter + , subq_14.acquired_ds__extract_month AS metric_time__extract_month + , subq_14.acquired_ds__extract_day AS metric_time__extract_day + , subq_14.acquired_ds__extract_dow AS metric_time__extract_dow + , subq_14.acquired_ds__extract_doy AS metric_time__extract_doy + , subq_14.customer_id + , subq_14.customer_third_hop_id + , subq_14.customer_id__customer_third_hop_id + , subq_14.customer_third_hop_id__customer_id + , subq_14.country + , subq_14.customer_id__country + , subq_14.customer_third_hop_id__country + , subq_14.customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + SELECT + 1 AS customers_with_other_data + , customer_other_data_src_22000.country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day + , EXTRACT(dayofweekiso FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day + , EXTRACT(dayofweekiso FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_third_hop_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day + , EXTRACT(dayofweekiso FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy + , customer_other_data_src_22000.customer_id + , customer_other_data_src_22000.customer_third_hop_id + , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id + , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_14 + ) subq_15 + WHERE customer_id__country = 'paraguay' + ) subq_16 + ) subq_17 WHERE customer_id__country = 'paraguay' - ) subq_12 - ) subq_13 + ) subq_18 + ) subq_19 GROUP BY - subq_13.customer_id__customer_third_hop_id - ) subq_14 - ) subq_15 - ) subq_16 + subq_19.customer_id__customer_third_hop_id + ) subq_20 + ) subq_21 + ) subq_22 ON - subq_8.customer_third_hop_id = subq_16.customer_id__customer_third_hop_id - ) subq_17 - ) subq_18 + subq_13.customer_third_hop_id = subq_22.customer_id__customer_third_hop_id + ) subq_23 + ) subq_24 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 - ) subq_19 - ) subq_20 -) subq_21 + ) subq_25 + ) subq_26 +) subq_27 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Snowflake/test_inner_query_single_hop__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Snowflake/test_inner_query_single_hop__plan0_optimized.sql index 2ad52ec04c..7c12d6cf98 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Snowflake/test_inner_query_single_hop__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Snowflake/test_inner_query_single_hop__plan0_optimized.sql @@ -8,7 +8,7 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_32.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + subq_39.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers , third_hop_table_src_22000.customer_third_hop_id AS third_hop_count FROM ***************************.third_hop_table third_hop_table_src_22000 LEFT OUTER JOIN ( @@ -21,20 +21,28 @@ FROM ( customer_id__customer_third_hop_id , SUM(customers_with_other_data) AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( - -- Read Elements From Semantic Model 'customer_other_data' - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - customer_third_hop_id AS customer_id__customer_third_hop_id - , country AS customer_id__country - , 1 AS customers_with_other_data - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_27 + customer_id__customer_third_hop_id + , customer_id__country + , customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' + SELECT + customer_third_hop_id AS customer_id__customer_third_hop_id + , country AS customer_id__country + , 1 AS customers_with_other_data + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_32 + WHERE customer_id__country = 'paraguay' + ) subq_34 WHERE customer_id__country = 'paraguay' GROUP BY customer_id__customer_third_hop_id - ) subq_32 + ) subq_39 ON - third_hop_table_src_22000.customer_third_hop_id = subq_32.customer_id__customer_third_hop_id -) subq_34 + third_hop_table_src_22000.customer_third_hop_id = subq_39.customer_id__customer_third_hop_id +) subq_41 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Trino/test_inner_query_single_hop__plan0.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Trino/test_inner_query_single_hop__plan0.sql index 12899f47dc..7b23ae782a 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Trino/test_inner_query_single_hop__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Trino/test_inner_query_single_hop__plan0.sql @@ -1,76 +1,76 @@ -- Compute Metrics via Expressions SELECT - subq_21.third_hop_count + subq_27.third_hop_count FROM ( -- Aggregate Measures SELECT - COUNT(DISTINCT subq_20.third_hop_count) AS third_hop_count + COUNT(DISTINCT subq_26.third_hop_count) AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count',] SELECT - subq_19.third_hop_count + subq_25.third_hop_count FROM ( -- Constrain Output with WHERE SELECT - subq_18.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_18.third_hop_count + subq_24.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_24.third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_17.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_17.third_hop_count + subq_23.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_23.third_hop_count FROM ( -- Join Standard Outputs SELECT - subq_8.customer_third_hop_id AS customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_8.third_hop_count AS third_hop_count + subq_13.customer_third_hop_id AS customer_third_hop_id + , subq_22.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id + , subq_22.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_13.third_hop_count AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id'] SELECT - subq_7.customer_third_hop_id - , subq_7.third_hop_count + subq_12.customer_third_hop_id + , subq_12.third_hop_count FROM ( -- Metric Time Dimension 'third_hop_ds' SELECT - subq_6.third_hop_ds__day - , subq_6.third_hop_ds__week - , subq_6.third_hop_ds__month - , subq_6.third_hop_ds__quarter - , subq_6.third_hop_ds__year - , subq_6.third_hop_ds__extract_year - , subq_6.third_hop_ds__extract_quarter - , subq_6.third_hop_ds__extract_month - , subq_6.third_hop_ds__extract_day - , subq_6.third_hop_ds__extract_dow - , subq_6.third_hop_ds__extract_doy - , subq_6.customer_third_hop_id__third_hop_ds__day - , subq_6.customer_third_hop_id__third_hop_ds__week - , subq_6.customer_third_hop_id__third_hop_ds__month - , subq_6.customer_third_hop_id__third_hop_ds__quarter - , subq_6.customer_third_hop_id__third_hop_ds__year - , subq_6.customer_third_hop_id__third_hop_ds__extract_year - , subq_6.customer_third_hop_id__third_hop_ds__extract_quarter - , subq_6.customer_third_hop_id__third_hop_ds__extract_month - , subq_6.customer_third_hop_id__third_hop_ds__extract_day - , subq_6.customer_third_hop_id__third_hop_ds__extract_dow - , subq_6.customer_third_hop_id__third_hop_ds__extract_doy - , subq_6.third_hop_ds__day AS metric_time__day - , subq_6.third_hop_ds__week AS metric_time__week - , subq_6.third_hop_ds__month AS metric_time__month - , subq_6.third_hop_ds__quarter AS metric_time__quarter - , subq_6.third_hop_ds__year AS metric_time__year - , subq_6.third_hop_ds__extract_year AS metric_time__extract_year - , subq_6.third_hop_ds__extract_quarter AS metric_time__extract_quarter - , subq_6.third_hop_ds__extract_month AS metric_time__extract_month - , subq_6.third_hop_ds__extract_day AS metric_time__extract_day - , subq_6.third_hop_ds__extract_dow AS metric_time__extract_dow - , subq_6.third_hop_ds__extract_doy AS metric_time__extract_doy - , subq_6.customer_third_hop_id - , subq_6.value - , subq_6.customer_third_hop_id__value - , subq_6.third_hop_count + subq_11.third_hop_ds__day + , subq_11.third_hop_ds__week + , subq_11.third_hop_ds__month + , subq_11.third_hop_ds__quarter + , subq_11.third_hop_ds__year + , subq_11.third_hop_ds__extract_year + , subq_11.third_hop_ds__extract_quarter + , subq_11.third_hop_ds__extract_month + , subq_11.third_hop_ds__extract_day + , subq_11.third_hop_ds__extract_dow + , subq_11.third_hop_ds__extract_doy + , subq_11.customer_third_hop_id__third_hop_ds__day + , subq_11.customer_third_hop_id__third_hop_ds__week + , subq_11.customer_third_hop_id__third_hop_ds__month + , subq_11.customer_third_hop_id__third_hop_ds__quarter + , subq_11.customer_third_hop_id__third_hop_ds__year + , subq_11.customer_third_hop_id__third_hop_ds__extract_year + , subq_11.customer_third_hop_id__third_hop_ds__extract_quarter + , subq_11.customer_third_hop_id__third_hop_ds__extract_month + , subq_11.customer_third_hop_id__third_hop_ds__extract_day + , subq_11.customer_third_hop_id__third_hop_ds__extract_dow + , subq_11.customer_third_hop_id__third_hop_ds__extract_doy + , subq_11.third_hop_ds__day AS metric_time__day + , subq_11.third_hop_ds__week AS metric_time__week + , subq_11.third_hop_ds__month AS metric_time__month + , subq_11.third_hop_ds__quarter AS metric_time__quarter + , subq_11.third_hop_ds__year AS metric_time__year + , subq_11.third_hop_ds__extract_year AS metric_time__extract_year + , subq_11.third_hop_ds__extract_quarter AS metric_time__extract_quarter + , subq_11.third_hop_ds__extract_month AS metric_time__extract_month + , subq_11.third_hop_ds__extract_day AS metric_time__extract_day + , subq_11.third_hop_ds__extract_dow AS metric_time__extract_dow + , subq_11.third_hop_ds__extract_doy AS metric_time__extract_doy + , subq_11.customer_third_hop_id + , subq_11.value + , subq_11.customer_third_hop_id__value + , subq_11.third_hop_count FROM ( -- Read Elements From Semantic Model 'third_hop_table' SELECT @@ -101,157 +101,214 @@ FROM ( , EXTRACT(doy FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_doy , third_hop_table_src_22000.customer_third_hop_id FROM ***************************.third_hop_table third_hop_table_src_22000 - ) subq_6 - ) subq_7 - ) subq_8 + ) subq_11 + ) subq_12 + ) subq_13 LEFT OUTER JOIN ( -- Pass Only Elements: ['customer_id__customer_third_hop_id', 'customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_15.customer_id__customer_third_hop_id - , subq_15.customer_id__customer_third_hop_id__paraguayan_customers + subq_21.customer_id__customer_third_hop_id + , subq_21.customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Compute Metrics via Expressions SELECT - subq_14.customer_id__customer_third_hop_id - , subq_14.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers + subq_20.customer_id__customer_third_hop_id + , subq_20.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Aggregate Measures SELECT - subq_13.customer_id__customer_third_hop_id - , SUM(subq_13.customers_with_other_data) AS customers_with_other_data + subq_19.customer_id__customer_third_hop_id + , SUM(subq_19.customers_with_other_data) AS customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__customer_third_hop_id'] SELECT - subq_12.customer_id__customer_third_hop_id - , subq_12.customers_with_other_data + subq_18.customer_id__customer_third_hop_id + , subq_18.customers_with_other_data FROM ( -- Constrain Output with WHERE SELECT - subq_11.customer_id__customer_third_hop_id - , subq_11.customer_id__country - , subq_11.customers_with_other_data + subq_17.customer_id__customer_third_hop_id + , subq_17.customer_id__country + , subq_17.customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - subq_10.customer_id__customer_third_hop_id - , subq_10.customer_id__country - , subq_10.customers_with_other_data + subq_16.customer_id__customer_third_hop_id + , subq_16.customer_id__country + , subq_16.customers_with_other_data FROM ( - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE SELECT - subq_9.acquired_ds__day - , subq_9.acquired_ds__week - , subq_9.acquired_ds__month - , subq_9.acquired_ds__quarter - , subq_9.acquired_ds__year - , subq_9.acquired_ds__extract_year - , subq_9.acquired_ds__extract_quarter - , subq_9.acquired_ds__extract_month - , subq_9.acquired_ds__extract_day - , subq_9.acquired_ds__extract_dow - , subq_9.acquired_ds__extract_doy - , subq_9.customer_id__acquired_ds__day - , subq_9.customer_id__acquired_ds__week - , subq_9.customer_id__acquired_ds__month - , subq_9.customer_id__acquired_ds__quarter - , subq_9.customer_id__acquired_ds__year - , subq_9.customer_id__acquired_ds__extract_year - , subq_9.customer_id__acquired_ds__extract_quarter - , subq_9.customer_id__acquired_ds__extract_month - , subq_9.customer_id__acquired_ds__extract_day - , subq_9.customer_id__acquired_ds__extract_dow - , subq_9.customer_id__acquired_ds__extract_doy - , subq_9.customer_third_hop_id__acquired_ds__day - , subq_9.customer_third_hop_id__acquired_ds__week - , subq_9.customer_third_hop_id__acquired_ds__month - , subq_9.customer_third_hop_id__acquired_ds__quarter - , subq_9.customer_third_hop_id__acquired_ds__year - , subq_9.customer_third_hop_id__acquired_ds__extract_year - , subq_9.customer_third_hop_id__acquired_ds__extract_quarter - , subq_9.customer_third_hop_id__acquired_ds__extract_month - , subq_9.customer_third_hop_id__acquired_ds__extract_day - , subq_9.customer_third_hop_id__acquired_ds__extract_dow - , subq_9.customer_third_hop_id__acquired_ds__extract_doy - , subq_9.acquired_ds__day AS metric_time__day - , subq_9.acquired_ds__week AS metric_time__week - , subq_9.acquired_ds__month AS metric_time__month - , subq_9.acquired_ds__quarter AS metric_time__quarter - , subq_9.acquired_ds__year AS metric_time__year - , subq_9.acquired_ds__extract_year AS metric_time__extract_year - , subq_9.acquired_ds__extract_quarter AS metric_time__extract_quarter - , subq_9.acquired_ds__extract_month AS metric_time__extract_month - , subq_9.acquired_ds__extract_day AS metric_time__extract_day - , subq_9.acquired_ds__extract_dow AS metric_time__extract_dow - , subq_9.acquired_ds__extract_doy AS metric_time__extract_doy - , subq_9.customer_id - , subq_9.customer_third_hop_id - , subq_9.customer_id__customer_third_hop_id - , subq_9.customer_third_hop_id__customer_id - , subq_9.country - , subq_9.customer_id__country - , subq_9.customer_third_hop_id__country - , subq_9.customers_with_other_data + subq_15.acquired_ds__day + , subq_15.acquired_ds__week + , subq_15.acquired_ds__month + , subq_15.acquired_ds__quarter + , subq_15.acquired_ds__year + , subq_15.acquired_ds__extract_year + , subq_15.acquired_ds__extract_quarter + , subq_15.acquired_ds__extract_month + , subq_15.acquired_ds__extract_day + , subq_15.acquired_ds__extract_dow + , subq_15.acquired_ds__extract_doy + , subq_15.customer_id__acquired_ds__day + , subq_15.customer_id__acquired_ds__week + , subq_15.customer_id__acquired_ds__month + , subq_15.customer_id__acquired_ds__quarter + , subq_15.customer_id__acquired_ds__year + , subq_15.customer_id__acquired_ds__extract_year + , subq_15.customer_id__acquired_ds__extract_quarter + , subq_15.customer_id__acquired_ds__extract_month + , subq_15.customer_id__acquired_ds__extract_day + , subq_15.customer_id__acquired_ds__extract_dow + , subq_15.customer_id__acquired_ds__extract_doy + , subq_15.customer_third_hop_id__acquired_ds__day + , subq_15.customer_third_hop_id__acquired_ds__week + , subq_15.customer_third_hop_id__acquired_ds__month + , subq_15.customer_third_hop_id__acquired_ds__quarter + , subq_15.customer_third_hop_id__acquired_ds__year + , subq_15.customer_third_hop_id__acquired_ds__extract_year + , subq_15.customer_third_hop_id__acquired_ds__extract_quarter + , subq_15.customer_third_hop_id__acquired_ds__extract_month + , subq_15.customer_third_hop_id__acquired_ds__extract_day + , subq_15.customer_third_hop_id__acquired_ds__extract_dow + , subq_15.customer_third_hop_id__acquired_ds__extract_doy + , subq_15.metric_time__day + , subq_15.metric_time__week + , subq_15.metric_time__month + , subq_15.metric_time__quarter + , subq_15.metric_time__year + , subq_15.metric_time__extract_year + , subq_15.metric_time__extract_quarter + , subq_15.metric_time__extract_month + , subq_15.metric_time__extract_day + , subq_15.metric_time__extract_dow + , subq_15.metric_time__extract_doy + , subq_15.customer_id + , subq_15.customer_third_hop_id + , subq_15.customer_id__customer_third_hop_id + , subq_15.customer_third_hop_id__customer_id + , subq_15.country + , subq_15.customer_id__country + , subq_15.customer_third_hop_id__country + , subq_15.customers_with_other_data FROM ( - -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' SELECT - 1 AS customers_with_other_data - , customer_other_data_src_22000.country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_third_hop_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy - , customer_other_data_src_22000.customer_id - , customer_other_data_src_22000.customer_third_hop_id - , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id - , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_9 - ) subq_10 - ) subq_11 + subq_14.acquired_ds__day + , subq_14.acquired_ds__week + , subq_14.acquired_ds__month + , subq_14.acquired_ds__quarter + , subq_14.acquired_ds__year + , subq_14.acquired_ds__extract_year + , subq_14.acquired_ds__extract_quarter + , subq_14.acquired_ds__extract_month + , subq_14.acquired_ds__extract_day + , subq_14.acquired_ds__extract_dow + , subq_14.acquired_ds__extract_doy + , subq_14.customer_id__acquired_ds__day + , subq_14.customer_id__acquired_ds__week + , subq_14.customer_id__acquired_ds__month + , subq_14.customer_id__acquired_ds__quarter + , subq_14.customer_id__acquired_ds__year + , subq_14.customer_id__acquired_ds__extract_year + , subq_14.customer_id__acquired_ds__extract_quarter + , subq_14.customer_id__acquired_ds__extract_month + , subq_14.customer_id__acquired_ds__extract_day + , subq_14.customer_id__acquired_ds__extract_dow + , subq_14.customer_id__acquired_ds__extract_doy + , subq_14.customer_third_hop_id__acquired_ds__day + , subq_14.customer_third_hop_id__acquired_ds__week + , subq_14.customer_third_hop_id__acquired_ds__month + , subq_14.customer_third_hop_id__acquired_ds__quarter + , subq_14.customer_third_hop_id__acquired_ds__year + , subq_14.customer_third_hop_id__acquired_ds__extract_year + , subq_14.customer_third_hop_id__acquired_ds__extract_quarter + , subq_14.customer_third_hop_id__acquired_ds__extract_month + , subq_14.customer_third_hop_id__acquired_ds__extract_day + , subq_14.customer_third_hop_id__acquired_ds__extract_dow + , subq_14.customer_third_hop_id__acquired_ds__extract_doy + , subq_14.acquired_ds__day AS metric_time__day + , subq_14.acquired_ds__week AS metric_time__week + , subq_14.acquired_ds__month AS metric_time__month + , subq_14.acquired_ds__quarter AS metric_time__quarter + , subq_14.acquired_ds__year AS metric_time__year + , subq_14.acquired_ds__extract_year AS metric_time__extract_year + , subq_14.acquired_ds__extract_quarter AS metric_time__extract_quarter + , subq_14.acquired_ds__extract_month AS metric_time__extract_month + , subq_14.acquired_ds__extract_day AS metric_time__extract_day + , subq_14.acquired_ds__extract_dow AS metric_time__extract_dow + , subq_14.acquired_ds__extract_doy AS metric_time__extract_doy + , subq_14.customer_id + , subq_14.customer_third_hop_id + , subq_14.customer_id__customer_third_hop_id + , subq_14.customer_third_hop_id__customer_id + , subq_14.country + , subq_14.customer_id__country + , subq_14.customer_third_hop_id__country + , subq_14.customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + SELECT + 1 AS customers_with_other_data + , customer_other_data_src_22000.country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_third_hop_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy + , customer_other_data_src_22000.customer_id + , customer_other_data_src_22000.customer_third_hop_id + , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id + , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_14 + ) subq_15 + WHERE customer_id__country = 'paraguay' + ) subq_16 + ) subq_17 WHERE customer_id__country = 'paraguay' - ) subq_12 - ) subq_13 + ) subq_18 + ) subq_19 GROUP BY - subq_13.customer_id__customer_third_hop_id - ) subq_14 - ) subq_15 - ) subq_16 + subq_19.customer_id__customer_third_hop_id + ) subq_20 + ) subq_21 + ) subq_22 ON - subq_8.customer_third_hop_id = subq_16.customer_id__customer_third_hop_id - ) subq_17 - ) subq_18 + subq_13.customer_third_hop_id = subq_22.customer_id__customer_third_hop_id + ) subq_23 + ) subq_24 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 - ) subq_19 - ) subq_20 -) subq_21 + ) subq_25 + ) subq_26 +) subq_27 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Trino/test_inner_query_single_hop__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Trino/test_inner_query_single_hop__plan0_optimized.sql index 2ad52ec04c..7c12d6cf98 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Trino/test_inner_query_single_hop__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Trino/test_inner_query_single_hop__plan0_optimized.sql @@ -8,7 +8,7 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_32.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + subq_39.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers , third_hop_table_src_22000.customer_third_hop_id AS third_hop_count FROM ***************************.third_hop_table third_hop_table_src_22000 LEFT OUTER JOIN ( @@ -21,20 +21,28 @@ FROM ( customer_id__customer_third_hop_id , SUM(customers_with_other_data) AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( - -- Read Elements From Semantic Model 'customer_other_data' - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - customer_third_hop_id AS customer_id__customer_third_hop_id - , country AS customer_id__country - , 1 AS customers_with_other_data - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_27 + customer_id__customer_third_hop_id + , customer_id__country + , customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' + SELECT + customer_third_hop_id AS customer_id__customer_third_hop_id + , country AS customer_id__country + , 1 AS customers_with_other_data + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_32 + WHERE customer_id__country = 'paraguay' + ) subq_34 WHERE customer_id__country = 'paraguay' GROUP BY customer_id__customer_third_hop_id - ) subq_32 + ) subq_39 ON - third_hop_table_src_22000.customer_third_hop_id = subq_32.customer_id__customer_third_hop_id -) subq_34 + third_hop_table_src_22000.customer_third_hop_id = subq_39.customer_id__customer_third_hop_id +) subq_41 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_categorical_dimension_pushdown__plan0.sql new file mode 100644 index 0000000000..2338468a44 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_categorical_dimension_pushdown__plan0.sql @@ -0,0 +1,387 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.booking__is_instant + , subq_10.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_9.booking__is_instant + , SUM(subq_9.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant'] + SELECT + subq_8.booking__is_instant + , subq_8.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.booking__is_instant + , subq_7.listing__is_lux_latest + , subq_7.listing__capacity_latest + , subq_7.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing__is_lux_latest', 'listing__capacity_latest'] + SELECT + subq_6.booking__is_instant + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_2.listing AS listing + , subq_2.booking__is_instant AS booking__is_instant + , subq_5.is_lux_latest AS listing__is_lux_latest + , subq_5.capacity_latest AS listing__capacity_latest + , subq_2.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_1.listing + , subq_1.booking__is_instant + , subq_1.bookings + 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.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.booking__paid_at__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.listing + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC(bookings_source_src_28000.ds, day) AS ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC(bookings_source_src_28000.ds, day) AS booking__ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS booking__ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS booking__ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS booking__ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS booking__ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS booking__ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS booking__ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS booking__ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS booking__ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS booking__ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS booking__paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS booking__paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS booking__paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS booking__paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS booking__paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['is_lux_latest', 'capacity_latest', 'listing', 'listing'] + SELECT + subq_4.listing + , subq_4.is_lux_latest + , subq_4.capacity_latest + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.ds__day AS metric_time__day + , subq_3.ds__week AS metric_time__week + , subq_3.ds__month AS metric_time__month + , subq_3.ds__quarter AS metric_time__quarter + , subq_3.ds__year AS metric_time__year + , subq_3.ds__extract_year AS metric_time__extract_year + , subq_3.ds__extract_quarter AS metric_time__extract_quarter + , subq_3.ds__extract_month AS metric_time__extract_month + , subq_3.ds__extract_day AS metric_time__extract_day + , subq_3.ds__extract_dow AS metric_time__extract_dow + , subq_3.ds__extract_doy AS metric_time__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS ds__day + , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS ds__week + , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS ds__month + , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS ds__quarter + , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS created_at__day + , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS created_at__week + , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS created_at__month + , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS created_at__quarter + , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS created_at__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS listing__ds__day + , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS listing__ds__week + , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS listing__ds__month + , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS listing__ds__quarter + , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS listing__ds__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS listing__created_at__day + , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS listing__created_at__week + , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS listing__created_at__month + , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS listing__created_at__quarter + , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS listing__created_at__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_3 + ) subq_4 + ) subq_5 + ON + subq_2.listing = subq_5.listing + ) subq_6 + ) subq_7 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_8 + ) subq_9 + GROUP BY + booking__is_instant +) subq_10 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..98cc26bb70 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql @@ -0,0 +1,33 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'booking__is_instant'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + booking__is_instant + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing__is_lux_latest', 'listing__capacity_latest'] + SELECT + subq_13.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , subq_13.bookings AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_13.listing = listings_latest_src_28000.listing_id +) subq_18 +WHERE listing__is_lux_latest OR listing__capacity_latest > 4 +GROUP BY + booking__is_instant diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..c538d056f2 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql @@ -0,0 +1,651 @@ +-- Compute Metrics via Expressions +SELECT + CAST(subq_28.west_coast_balance_first_day AS FLOAT64) / CAST(NULLIF(subq_28.east_coast_balance_first_dat, 0) AS FLOAT64) AS regional_starting_balance_ratios +FROM ( + -- Combine Aggregated Outputs + SELECT + MAX(subq_13.west_coast_balance_first_day) AS west_coast_balance_first_day + , MAX(subq_27.east_coast_balance_first_dat) AS east_coast_balance_first_dat + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_12.total_account_balance_first_day AS west_coast_balance_first_day + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_11.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_10.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_7.ds__day AS ds__day + , subq_7.user__home_state_latest AS user__home_state_latest + , subq_7.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + 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.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__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.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC(accounts_source_src_28000.ds, day) AS ds__day + , DATE_TRUNC(accounts_source_src_28000.ds, isoweek) AS ds__week + , DATE_TRUNC(accounts_source_src_28000.ds, month) AS ds__month + , DATE_TRUNC(accounts_source_src_28000.ds, quarter) AS ds__quarter + , DATE_TRUNC(accounts_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM accounts_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM accounts_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC(accounts_source_src_28000.ds, day) AS account__ds__day + , DATE_TRUNC(accounts_source_src_28000.ds, isoweek) AS account__ds__week + , DATE_TRUNC(accounts_source_src_28000.ds, month) AS account__ds__month + , DATE_TRUNC(accounts_source_src_28000.ds, quarter) AS account__ds__quarter + , DATE_TRUNC(accounts_source_src_28000.ds, year) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , IF(EXTRACT(dayofweek FROM accounts_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM accounts_source_src_28000.ds) - 1) AS account__ds__extract_dow + , EXTRACT(dayofyear FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC(users_latest_src_28000.ds, day) AS ds_latest__day + , DATE_TRUNC(users_latest_src_28000.ds, isoweek) AS ds_latest__week + , DATE_TRUNC(users_latest_src_28000.ds, month) AS ds_latest__month + , DATE_TRUNC(users_latest_src_28000.ds, quarter) AS ds_latest__quarter + , DATE_TRUNC(users_latest_src_28000.ds, year) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS ds_latest__extract_dow + , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC(users_latest_src_28000.ds, day) AS user__ds_latest__day + , DATE_TRUNC(users_latest_src_28000.ds, isoweek) AS user__ds_latest__week + , DATE_TRUNC(users_latest_src_28000.ds, month) AS user__ds_latest__month + , DATE_TRUNC(users_latest_src_28000.ds, quarter) AS user__ds_latest__quarter + , DATE_TRUNC(users_latest_src_28000.ds, year) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS user__ds_latest__extract_dow + , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_7 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_8.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + 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.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__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.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC(accounts_source_src_28000.ds, day) AS ds__day + , DATE_TRUNC(accounts_source_src_28000.ds, isoweek) AS ds__week + , DATE_TRUNC(accounts_source_src_28000.ds, month) AS ds__month + , DATE_TRUNC(accounts_source_src_28000.ds, quarter) AS ds__quarter + , DATE_TRUNC(accounts_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM accounts_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM accounts_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC(accounts_source_src_28000.ds, day) AS account__ds__day + , DATE_TRUNC(accounts_source_src_28000.ds, isoweek) AS account__ds__week + , DATE_TRUNC(accounts_source_src_28000.ds, month) AS account__ds__month + , DATE_TRUNC(accounts_source_src_28000.ds, quarter) AS account__ds__quarter + , DATE_TRUNC(accounts_source_src_28000.ds, year) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , IF(EXTRACT(dayofweek FROM accounts_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM accounts_source_src_28000.ds) - 1) AS account__ds__extract_dow + , EXTRACT(dayofyear FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC(users_latest_src_28000.ds, day) AS ds_latest__day + , DATE_TRUNC(users_latest_src_28000.ds, isoweek) AS ds_latest__week + , DATE_TRUNC(users_latest_src_28000.ds, month) AS ds_latest__month + , DATE_TRUNC(users_latest_src_28000.ds, quarter) AS ds_latest__quarter + , DATE_TRUNC(users_latest_src_28000.ds, year) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS ds_latest__extract_dow + , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC(users_latest_src_28000.ds, day) AS user__ds_latest__day + , DATE_TRUNC(users_latest_src_28000.ds, isoweek) AS user__ds_latest__week + , DATE_TRUNC(users_latest_src_28000.ds, month) AS user__ds_latest__month + , DATE_TRUNC(users_latest_src_28000.ds, quarter) AS user__ds_latest__quarter + , DATE_TRUNC(users_latest_src_28000.ds, year) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS user__ds_latest__extract_dow + , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_8 + ) subq_9 + ON + subq_7.ds__day = subq_9.ds__day__complete + ) subq_10 + ) subq_11 + ) subq_12 + ) subq_13 + CROSS JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_26.total_account_balance_first_day AS east_coast_balance_first_dat + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_25.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_24.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_21.ds__day AS ds__day + , subq_21.user__home_state_latest AS user__home_state_latest + , subq_21.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_14.ds__day + , subq_14.ds__week + , subq_14.ds__month + , subq_14.ds__quarter + , subq_14.ds__year + , subq_14.ds__extract_year + , subq_14.ds__extract_quarter + , subq_14.ds__extract_month + , subq_14.ds__extract_day + , subq_14.ds__extract_dow + , subq_14.ds__extract_doy + , subq_14.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__extract_doy + , subq_14.ds__day AS metric_time__day + , subq_14.ds__week AS metric_time__week + , subq_14.ds__month AS metric_time__month + , subq_14.ds__quarter AS metric_time__quarter + , subq_14.ds__year AS metric_time__year + , subq_14.ds__extract_year AS metric_time__extract_year + , subq_14.ds__extract_quarter AS metric_time__extract_quarter + , subq_14.ds__extract_month AS metric_time__extract_month + , subq_14.ds__extract_day AS metric_time__extract_day + , subq_14.ds__extract_dow AS metric_time__extract_dow + , subq_14.ds__extract_doy AS metric_time__extract_doy + , subq_14.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC(accounts_source_src_28000.ds, day) AS ds__day + , DATE_TRUNC(accounts_source_src_28000.ds, isoweek) AS ds__week + , DATE_TRUNC(accounts_source_src_28000.ds, month) AS ds__month + , DATE_TRUNC(accounts_source_src_28000.ds, quarter) AS ds__quarter + , DATE_TRUNC(accounts_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM accounts_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM accounts_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC(accounts_source_src_28000.ds, day) AS account__ds__day + , DATE_TRUNC(accounts_source_src_28000.ds, isoweek) AS account__ds__week + , DATE_TRUNC(accounts_source_src_28000.ds, month) AS account__ds__month + , DATE_TRUNC(accounts_source_src_28000.ds, quarter) AS account__ds__quarter + , DATE_TRUNC(accounts_source_src_28000.ds, year) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , IF(EXTRACT(dayofweek FROM accounts_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM accounts_source_src_28000.ds) - 1) AS account__ds__extract_dow + , EXTRACT(dayofyear FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC(users_latest_src_28000.ds, day) AS ds_latest__day + , DATE_TRUNC(users_latest_src_28000.ds, isoweek) AS ds_latest__week + , DATE_TRUNC(users_latest_src_28000.ds, month) AS ds_latest__month + , DATE_TRUNC(users_latest_src_28000.ds, quarter) AS ds_latest__quarter + , DATE_TRUNC(users_latest_src_28000.ds, year) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS ds_latest__extract_dow + , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC(users_latest_src_28000.ds, day) AS user__ds_latest__day + , DATE_TRUNC(users_latest_src_28000.ds, isoweek) AS user__ds_latest__week + , DATE_TRUNC(users_latest_src_28000.ds, month) AS user__ds_latest__month + , DATE_TRUNC(users_latest_src_28000.ds, quarter) AS user__ds_latest__quarter + , DATE_TRUNC(users_latest_src_28000.ds, year) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS user__ds_latest__extract_dow + , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_21 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_22.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_14.ds__day + , subq_14.ds__week + , subq_14.ds__month + , subq_14.ds__quarter + , subq_14.ds__year + , subq_14.ds__extract_year + , subq_14.ds__extract_quarter + , subq_14.ds__extract_month + , subq_14.ds__extract_day + , subq_14.ds__extract_dow + , subq_14.ds__extract_doy + , subq_14.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__extract_doy + , subq_14.ds__day AS metric_time__day + , subq_14.ds__week AS metric_time__week + , subq_14.ds__month AS metric_time__month + , subq_14.ds__quarter AS metric_time__quarter + , subq_14.ds__year AS metric_time__year + , subq_14.ds__extract_year AS metric_time__extract_year + , subq_14.ds__extract_quarter AS metric_time__extract_quarter + , subq_14.ds__extract_month AS metric_time__extract_month + , subq_14.ds__extract_day AS metric_time__extract_day + , subq_14.ds__extract_dow AS metric_time__extract_dow + , subq_14.ds__extract_doy AS metric_time__extract_doy + , subq_14.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC(accounts_source_src_28000.ds, day) AS ds__day + , DATE_TRUNC(accounts_source_src_28000.ds, isoweek) AS ds__week + , DATE_TRUNC(accounts_source_src_28000.ds, month) AS ds__month + , DATE_TRUNC(accounts_source_src_28000.ds, quarter) AS ds__quarter + , DATE_TRUNC(accounts_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM accounts_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM accounts_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC(accounts_source_src_28000.ds, day) AS account__ds__day + , DATE_TRUNC(accounts_source_src_28000.ds, isoweek) AS account__ds__week + , DATE_TRUNC(accounts_source_src_28000.ds, month) AS account__ds__month + , DATE_TRUNC(accounts_source_src_28000.ds, quarter) AS account__ds__quarter + , DATE_TRUNC(accounts_source_src_28000.ds, year) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , IF(EXTRACT(dayofweek FROM accounts_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM accounts_source_src_28000.ds) - 1) AS account__ds__extract_dow + , EXTRACT(dayofyear FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC(users_latest_src_28000.ds, day) AS ds_latest__day + , DATE_TRUNC(users_latest_src_28000.ds, isoweek) AS ds_latest__week + , DATE_TRUNC(users_latest_src_28000.ds, month) AS ds_latest__month + , DATE_TRUNC(users_latest_src_28000.ds, quarter) AS ds_latest__quarter + , DATE_TRUNC(users_latest_src_28000.ds, year) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS ds_latest__extract_dow + , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC(users_latest_src_28000.ds, day) AS user__ds_latest__day + , DATE_TRUNC(users_latest_src_28000.ds, isoweek) AS user__ds_latest__week + , DATE_TRUNC(users_latest_src_28000.ds, month) AS user__ds_latest__month + , DATE_TRUNC(users_latest_src_28000.ds, quarter) AS user__ds_latest__quarter + , DATE_TRUNC(users_latest_src_28000.ds, year) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS user__ds_latest__extract_dow + , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_22 + ) subq_23 + ON + subq_21.ds__day = subq_23.ds__day__complete + ) subq_24 + ) subq_25 + ) subq_26 + ) subq_27 +) subq_28 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..6b681abe33 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,102 @@ +-- Combine Aggregated Outputs +-- Compute Metrics via Expressions +SELECT + CAST(MAX(subq_42.west_coast_balance_first_day) AS FLOAT64) / CAST(NULLIF(MAX(subq_56.east_coast_balance_first_dat), 0) AS FLOAT64) AS regional_starting_balance_ratios +FROM ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_36.total_account_balance_first_day) AS west_coast_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC(accounts_source_src_28000.ds, day) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_36 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC(accounts_source_src_28000.ds, day) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_38 + ON + subq_36.ds__day = subq_38.ds__day__complete +) subq_42 +CROSS JOIN ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_50.total_account_balance_first_day) AS east_coast_balance_first_dat + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC(accounts_source_src_28000.ds, day) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_50 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC(accounts_source_src_28000.ds, day) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_52 + ON + subq_50.ds__day = subq_52.ds__day__complete +) subq_56 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..7ee349a6c7 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql @@ -0,0 +1,563 @@ +-- Compute Metrics via Expressions +SELECT + subq_19.metric_time__day + , CAST(subq_19.average_booking_value AS FLOAT64) / CAST(NULLIF(subq_19.max_booking_value, 0) AS FLOAT64) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) AS metric_time__day + , MAX(subq_13.average_booking_value) AS average_booking_value + , MAX(subq_18.max_booking_value) AS max_booking_value + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_12.metric_time__day + , subq_12.average_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_11.metric_time__day + , AVG(subq_11.average_booking_value) AS average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + SELECT + subq_10.metric_time__day + , subq_10.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__week + , subq_7.ds__month + , subq_7.ds__quarter + , subq_7.ds__year + , subq_7.ds__extract_year + , subq_7.ds__extract_quarter + , subq_7.ds__extract_month + , subq_7.ds__extract_day + , subq_7.ds__extract_dow + , subq_7.ds__extract_doy + , subq_7.ds_partitioned__day + , subq_7.ds_partitioned__week + , subq_7.ds_partitioned__month + , subq_7.ds_partitioned__quarter + , subq_7.ds_partitioned__year + , subq_7.ds_partitioned__extract_year + , subq_7.ds_partitioned__extract_quarter + , subq_7.ds_partitioned__extract_month + , subq_7.ds_partitioned__extract_day + , subq_7.ds_partitioned__extract_dow + , subq_7.ds_partitioned__extract_doy + , subq_7.paid_at__day + , subq_7.paid_at__week + , subq_7.paid_at__month + , subq_7.paid_at__quarter + , subq_7.paid_at__year + , subq_7.paid_at__extract_year + , subq_7.paid_at__extract_quarter + , subq_7.paid_at__extract_month + , subq_7.paid_at__extract_day + , subq_7.paid_at__extract_dow + , subq_7.paid_at__extract_doy + , subq_7.booking__ds__day + , subq_7.booking__ds__week + , subq_7.booking__ds__month + , subq_7.booking__ds__quarter + , subq_7.booking__ds__year + , subq_7.booking__ds__extract_year + , subq_7.booking__ds__extract_quarter + , subq_7.booking__ds__extract_month + , subq_7.booking__ds__extract_day + , subq_7.booking__ds__extract_dow + , subq_7.booking__ds__extract_doy + , subq_7.booking__ds_partitioned__day + , subq_7.booking__ds_partitioned__week + , subq_7.booking__ds_partitioned__month + , subq_7.booking__ds_partitioned__quarter + , subq_7.booking__ds_partitioned__year + , subq_7.booking__ds_partitioned__extract_year + , subq_7.booking__ds_partitioned__extract_quarter + , subq_7.booking__ds_partitioned__extract_month + , subq_7.booking__ds_partitioned__extract_day + , subq_7.booking__ds_partitioned__extract_dow + , subq_7.booking__ds_partitioned__extract_doy + , subq_7.booking__paid_at__day + , subq_7.booking__paid_at__week + , subq_7.booking__paid_at__month + , subq_7.booking__paid_at__quarter + , subq_7.booking__paid_at__year + , subq_7.booking__paid_at__extract_year + , subq_7.booking__paid_at__extract_quarter + , subq_7.booking__paid_at__extract_month + , subq_7.booking__paid_at__extract_day + , subq_7.booking__paid_at__extract_dow + , subq_7.booking__paid_at__extract_doy + , subq_7.metric_time__day + , subq_7.metric_time__week + , subq_7.metric_time__month + , subq_7.metric_time__quarter + , subq_7.metric_time__year + , subq_7.metric_time__extract_year + , subq_7.metric_time__extract_quarter + , subq_7.metric_time__extract_month + , subq_7.metric_time__extract_day + , subq_7.metric_time__extract_dow + , subq_7.metric_time__extract_doy + , subq_7.listing + , subq_7.guest + , subq_7.host + , subq_7.booking__listing + , subq_7.booking__guest + , subq_7.booking__host + , subq_7.is_instant + , subq_7.booking__is_instant + , subq_7.bookings + , subq_7.instant_bookings + , subq_7.booking_value + , subq_7.max_booking_value + , subq_7.min_booking_value + , subq_7.bookers + , subq_7.average_booking_value + , subq_7.referred_bookings + , subq_7.median_booking_value + , subq_7.booking_value_p99 + , subq_7.discrete_booking_value_p99 + , subq_7.approximate_continuous_booking_value_p99 + , subq_7.approximate_discrete_booking_value_p99 + 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.ds_partitioned__day + , subq_6.ds_partitioned__week + , subq_6.ds_partitioned__month + , subq_6.ds_partitioned__quarter + , subq_6.ds_partitioned__year + , subq_6.ds_partitioned__extract_year + , subq_6.ds_partitioned__extract_quarter + , subq_6.ds_partitioned__extract_month + , subq_6.ds_partitioned__extract_day + , subq_6.ds_partitioned__extract_dow + , subq_6.ds_partitioned__extract_doy + , subq_6.paid_at__day + , subq_6.paid_at__week + , subq_6.paid_at__month + , subq_6.paid_at__quarter + , subq_6.paid_at__year + , subq_6.paid_at__extract_year + , subq_6.paid_at__extract_quarter + , subq_6.paid_at__extract_month + , subq_6.paid_at__extract_day + , subq_6.paid_at__extract_dow + , subq_6.paid_at__extract_doy + , subq_6.booking__ds__day + , subq_6.booking__ds__week + , subq_6.booking__ds__month + , subq_6.booking__ds__quarter + , subq_6.booking__ds__year + , subq_6.booking__ds__extract_year + , subq_6.booking__ds__extract_quarter + , subq_6.booking__ds__extract_month + , subq_6.booking__ds__extract_day + , subq_6.booking__ds__extract_dow + , subq_6.booking__ds__extract_doy + , subq_6.booking__ds_partitioned__day + , subq_6.booking__ds_partitioned__week + , subq_6.booking__ds_partitioned__month + , subq_6.booking__ds_partitioned__quarter + , subq_6.booking__ds_partitioned__year + , subq_6.booking__ds_partitioned__extract_year + , subq_6.booking__ds_partitioned__extract_quarter + , subq_6.booking__ds_partitioned__extract_month + , subq_6.booking__ds_partitioned__extract_day + , subq_6.booking__ds_partitioned__extract_dow + , subq_6.booking__ds_partitioned__extract_doy + , subq_6.booking__paid_at__day + , subq_6.booking__paid_at__week + , subq_6.booking__paid_at__month + , subq_6.booking__paid_at__quarter + , subq_6.booking__paid_at__year + , subq_6.booking__paid_at__extract_year + , subq_6.booking__paid_at__extract_quarter + , subq_6.booking__paid_at__extract_month + , subq_6.booking__paid_at__extract_day + , subq_6.booking__paid_at__extract_dow + , subq_6.booking__paid_at__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.listing + , subq_6.guest + , subq_6.host + , subq_6.booking__listing + , subq_6.booking__guest + , subq_6.booking__host + , subq_6.is_instant + , subq_6.booking__is_instant + , subq_6.bookings + , subq_6.instant_bookings + , subq_6.booking_value + , subq_6.max_booking_value + , subq_6.min_booking_value + , subq_6.bookers + , subq_6.average_booking_value + , subq_6.referred_bookings + , subq_6.median_booking_value + , subq_6.booking_value_p99 + , subq_6.discrete_booking_value_p99 + , subq_6.approximate_continuous_booking_value_p99 + , subq_6.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC(bookings_source_src_28000.ds, day) AS ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC(bookings_source_src_28000.ds, day) AS booking__ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS booking__ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS booking__ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS booking__ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS booking__ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS booking__ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS booking__ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS booking__ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS booking__ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS booking__ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS booking__paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS booking__paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS booking__paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS booking__paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS booking__paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 + WHERE booking__is_instant + ) subq_10 + ) subq_11 + GROUP BY + metric_time__day + ) subq_12 + ) subq_13 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_17.metric_time__day + , subq_17.max_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_16.metric_time__day + , MAX(subq_16.max_booking_value) AS max_booking_value + FROM ( + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + SELECT + subq_15.metric_time__day + , subq_15.max_booking_value + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_14.ds__day + , subq_14.ds__week + , subq_14.ds__month + , subq_14.ds__quarter + , subq_14.ds__year + , subq_14.ds__extract_year + , subq_14.ds__extract_quarter + , subq_14.ds__extract_month + , subq_14.ds__extract_day + , subq_14.ds__extract_dow + , subq_14.ds__extract_doy + , subq_14.ds_partitioned__day + , subq_14.ds_partitioned__week + , subq_14.ds_partitioned__month + , subq_14.ds_partitioned__quarter + , subq_14.ds_partitioned__year + , subq_14.ds_partitioned__extract_year + , subq_14.ds_partitioned__extract_quarter + , subq_14.ds_partitioned__extract_month + , subq_14.ds_partitioned__extract_day + , subq_14.ds_partitioned__extract_dow + , subq_14.ds_partitioned__extract_doy + , subq_14.paid_at__day + , subq_14.paid_at__week + , subq_14.paid_at__month + , subq_14.paid_at__quarter + , subq_14.paid_at__year + , subq_14.paid_at__extract_year + , subq_14.paid_at__extract_quarter + , subq_14.paid_at__extract_month + , subq_14.paid_at__extract_day + , subq_14.paid_at__extract_dow + , subq_14.paid_at__extract_doy + , subq_14.booking__ds__day + , subq_14.booking__ds__week + , subq_14.booking__ds__month + , subq_14.booking__ds__quarter + , subq_14.booking__ds__year + , subq_14.booking__ds__extract_year + , subq_14.booking__ds__extract_quarter + , subq_14.booking__ds__extract_month + , subq_14.booking__ds__extract_day + , subq_14.booking__ds__extract_dow + , subq_14.booking__ds__extract_doy + , subq_14.booking__ds_partitioned__day + , subq_14.booking__ds_partitioned__week + , subq_14.booking__ds_partitioned__month + , subq_14.booking__ds_partitioned__quarter + , subq_14.booking__ds_partitioned__year + , subq_14.booking__ds_partitioned__extract_year + , subq_14.booking__ds_partitioned__extract_quarter + , subq_14.booking__ds_partitioned__extract_month + , subq_14.booking__ds_partitioned__extract_day + , subq_14.booking__ds_partitioned__extract_dow + , subq_14.booking__ds_partitioned__extract_doy + , subq_14.booking__paid_at__day + , subq_14.booking__paid_at__week + , subq_14.booking__paid_at__month + , subq_14.booking__paid_at__quarter + , subq_14.booking__paid_at__year + , subq_14.booking__paid_at__extract_year + , subq_14.booking__paid_at__extract_quarter + , subq_14.booking__paid_at__extract_month + , subq_14.booking__paid_at__extract_day + , subq_14.booking__paid_at__extract_dow + , subq_14.booking__paid_at__extract_doy + , subq_14.ds__day AS metric_time__day + , subq_14.ds__week AS metric_time__week + , subq_14.ds__month AS metric_time__month + , subq_14.ds__quarter AS metric_time__quarter + , subq_14.ds__year AS metric_time__year + , subq_14.ds__extract_year AS metric_time__extract_year + , subq_14.ds__extract_quarter AS metric_time__extract_quarter + , subq_14.ds__extract_month AS metric_time__extract_month + , subq_14.ds__extract_day AS metric_time__extract_day + , subq_14.ds__extract_dow AS metric_time__extract_dow + , subq_14.ds__extract_doy AS metric_time__extract_doy + , subq_14.listing + , subq_14.guest + , subq_14.host + , subq_14.booking__listing + , subq_14.booking__guest + , subq_14.booking__host + , subq_14.is_instant + , subq_14.booking__is_instant + , subq_14.bookings + , subq_14.instant_bookings + , subq_14.booking_value + , subq_14.max_booking_value + , subq_14.min_booking_value + , subq_14.bookers + , subq_14.average_booking_value + , subq_14.referred_bookings + , subq_14.median_booking_value + , subq_14.booking_value_p99 + , subq_14.discrete_booking_value_p99 + , subq_14.approximate_continuous_booking_value_p99 + , subq_14.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC(bookings_source_src_28000.ds, day) AS ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC(bookings_source_src_28000.ds, day) AS booking__ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS booking__ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS booking__ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS booking__ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS booking__ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS booking__ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS booking__ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS booking__ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS booking__ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS booking__ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS booking__paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS booking__paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS booking__paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS booking__paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS booking__paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + GROUP BY + metric_time__day + ) subq_17 + ) subq_18 + ON + subq_13.metric_time__day = subq_18.metric_time__day + GROUP BY + metric_time__day +) subq_19 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..938931502a --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,58 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , CAST(average_booking_value AS FLOAT64) / CAST(NULLIF(max_booking_value, 0) AS FLOAT64) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) AS metric_time__day + , MAX(subq_27.average_booking_value) AS average_booking_value + , MAX(subq_32.max_booking_value) AS max_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , AVG(average_booking_value) AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + metric_time__day + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC(ds, day) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_21 + WHERE booking__is_instant + ) subq_23 + WHERE booking__is_instant + GROUP BY + metric_time__day + ) subq_27 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC(ds, day) AS metric_time__day + , MAX(booking_value) AS max_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + GROUP BY + metric_time__day + ) subq_32 + ON + subq_27.metric_time__day = subq_32.metric_time__day + GROUP BY + metric_time__day +) subq_33 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_single_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_single_categorical_dimension_pushdown__plan0.sql new file mode 100644 index 0000000000..01e8c2274d --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_single_categorical_dimension_pushdown__plan0.sql @@ -0,0 +1,486 @@ +-- Compute Metrics via Expressions +SELECT + subq_17.listing__country_latest + , subq_17.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_16.listing__country_latest + , SUM(subq_16.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest'] + SELECT + subq_15.listing__country_latest + , subq_15.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_14.booking__is_instant + , subq_14.listing__country_latest + , subq_14.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] + SELECT + subq_13.booking__is_instant + , subq_13.listing__country_latest + , subq_13.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_9.listing AS listing + , subq_9.booking__is_instant AS booking__is_instant + , subq_12.country_latest AS listing__country_latest + , subq_9.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_8.listing + , subq_8.booking__is_instant + , subq_8.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__week + , subq_7.ds__month + , subq_7.ds__quarter + , subq_7.ds__year + , subq_7.ds__extract_year + , subq_7.ds__extract_quarter + , subq_7.ds__extract_month + , subq_7.ds__extract_day + , subq_7.ds__extract_dow + , subq_7.ds__extract_doy + , subq_7.ds_partitioned__day + , subq_7.ds_partitioned__week + , subq_7.ds_partitioned__month + , subq_7.ds_partitioned__quarter + , subq_7.ds_partitioned__year + , subq_7.ds_partitioned__extract_year + , subq_7.ds_partitioned__extract_quarter + , subq_7.ds_partitioned__extract_month + , subq_7.ds_partitioned__extract_day + , subq_7.ds_partitioned__extract_dow + , subq_7.ds_partitioned__extract_doy + , subq_7.paid_at__day + , subq_7.paid_at__week + , subq_7.paid_at__month + , subq_7.paid_at__quarter + , subq_7.paid_at__year + , subq_7.paid_at__extract_year + , subq_7.paid_at__extract_quarter + , subq_7.paid_at__extract_month + , subq_7.paid_at__extract_day + , subq_7.paid_at__extract_dow + , subq_7.paid_at__extract_doy + , subq_7.booking__ds__day + , subq_7.booking__ds__week + , subq_7.booking__ds__month + , subq_7.booking__ds__quarter + , subq_7.booking__ds__year + , subq_7.booking__ds__extract_year + , subq_7.booking__ds__extract_quarter + , subq_7.booking__ds__extract_month + , subq_7.booking__ds__extract_day + , subq_7.booking__ds__extract_dow + , subq_7.booking__ds__extract_doy + , subq_7.booking__ds_partitioned__day + , subq_7.booking__ds_partitioned__week + , subq_7.booking__ds_partitioned__month + , subq_7.booking__ds_partitioned__quarter + , subq_7.booking__ds_partitioned__year + , subq_7.booking__ds_partitioned__extract_year + , subq_7.booking__ds_partitioned__extract_quarter + , subq_7.booking__ds_partitioned__extract_month + , subq_7.booking__ds_partitioned__extract_day + , subq_7.booking__ds_partitioned__extract_dow + , subq_7.booking__ds_partitioned__extract_doy + , subq_7.booking__paid_at__day + , subq_7.booking__paid_at__week + , subq_7.booking__paid_at__month + , subq_7.booking__paid_at__quarter + , subq_7.booking__paid_at__year + , subq_7.booking__paid_at__extract_year + , subq_7.booking__paid_at__extract_quarter + , subq_7.booking__paid_at__extract_month + , subq_7.booking__paid_at__extract_day + , subq_7.booking__paid_at__extract_dow + , subq_7.booking__paid_at__extract_doy + , subq_7.metric_time__day + , subq_7.metric_time__week + , subq_7.metric_time__month + , subq_7.metric_time__quarter + , subq_7.metric_time__year + , subq_7.metric_time__extract_year + , subq_7.metric_time__extract_quarter + , subq_7.metric_time__extract_month + , subq_7.metric_time__extract_day + , subq_7.metric_time__extract_dow + , subq_7.metric_time__extract_doy + , subq_7.listing + , subq_7.guest + , subq_7.host + , subq_7.booking__listing + , subq_7.booking__guest + , subq_7.booking__host + , subq_7.is_instant + , subq_7.booking__is_instant + , subq_7.bookings + , subq_7.instant_bookings + , subq_7.booking_value + , subq_7.max_booking_value + , subq_7.min_booking_value + , subq_7.bookers + , subq_7.average_booking_value + , subq_7.referred_bookings + , subq_7.median_booking_value + , subq_7.booking_value_p99 + , subq_7.discrete_booking_value_p99 + , subq_7.approximate_continuous_booking_value_p99 + , subq_7.approximate_discrete_booking_value_p99 + 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.ds_partitioned__day + , subq_6.ds_partitioned__week + , subq_6.ds_partitioned__month + , subq_6.ds_partitioned__quarter + , subq_6.ds_partitioned__year + , subq_6.ds_partitioned__extract_year + , subq_6.ds_partitioned__extract_quarter + , subq_6.ds_partitioned__extract_month + , subq_6.ds_partitioned__extract_day + , subq_6.ds_partitioned__extract_dow + , subq_6.ds_partitioned__extract_doy + , subq_6.paid_at__day + , subq_6.paid_at__week + , subq_6.paid_at__month + , subq_6.paid_at__quarter + , subq_6.paid_at__year + , subq_6.paid_at__extract_year + , subq_6.paid_at__extract_quarter + , subq_6.paid_at__extract_month + , subq_6.paid_at__extract_day + , subq_6.paid_at__extract_dow + , subq_6.paid_at__extract_doy + , subq_6.booking__ds__day + , subq_6.booking__ds__week + , subq_6.booking__ds__month + , subq_6.booking__ds__quarter + , subq_6.booking__ds__year + , subq_6.booking__ds__extract_year + , subq_6.booking__ds__extract_quarter + , subq_6.booking__ds__extract_month + , subq_6.booking__ds__extract_day + , subq_6.booking__ds__extract_dow + , subq_6.booking__ds__extract_doy + , subq_6.booking__ds_partitioned__day + , subq_6.booking__ds_partitioned__week + , subq_6.booking__ds_partitioned__month + , subq_6.booking__ds_partitioned__quarter + , subq_6.booking__ds_partitioned__year + , subq_6.booking__ds_partitioned__extract_year + , subq_6.booking__ds_partitioned__extract_quarter + , subq_6.booking__ds_partitioned__extract_month + , subq_6.booking__ds_partitioned__extract_day + , subq_6.booking__ds_partitioned__extract_dow + , subq_6.booking__ds_partitioned__extract_doy + , subq_6.booking__paid_at__day + , subq_6.booking__paid_at__week + , subq_6.booking__paid_at__month + , subq_6.booking__paid_at__quarter + , subq_6.booking__paid_at__year + , subq_6.booking__paid_at__extract_year + , subq_6.booking__paid_at__extract_quarter + , subq_6.booking__paid_at__extract_month + , subq_6.booking__paid_at__extract_day + , subq_6.booking__paid_at__extract_dow + , subq_6.booking__paid_at__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.listing + , subq_6.guest + , subq_6.host + , subq_6.booking__listing + , subq_6.booking__guest + , subq_6.booking__host + , subq_6.is_instant + , subq_6.booking__is_instant + , subq_6.bookings + , subq_6.instant_bookings + , subq_6.booking_value + , subq_6.max_booking_value + , subq_6.min_booking_value + , subq_6.bookers + , subq_6.average_booking_value + , subq_6.referred_bookings + , subq_6.median_booking_value + , subq_6.booking_value_p99 + , subq_6.discrete_booking_value_p99 + , subq_6.approximate_continuous_booking_value_p99 + , subq_6.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC(bookings_source_src_28000.ds, day) AS ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC(bookings_source_src_28000.ds, day) AS booking__ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS booking__ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS booking__ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS booking__ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS booking__ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS booking__ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS booking__ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS booking__ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS booking__ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS booking__ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS booking__paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS booking__paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS booking__paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS booking__paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS booking__paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['country_latest', 'listing'] + SELECT + subq_11.listing + , subq_11.country_latest + FROM ( + -- Metric Time Dimension 'ds' + 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.created_at__day + , subq_10.created_at__week + , subq_10.created_at__month + , subq_10.created_at__quarter + , subq_10.created_at__year + , subq_10.created_at__extract_year + , subq_10.created_at__extract_quarter + , subq_10.created_at__extract_month + , subq_10.created_at__extract_day + , subq_10.created_at__extract_dow + , subq_10.created_at__extract_doy + , subq_10.listing__ds__day + , subq_10.listing__ds__week + , subq_10.listing__ds__month + , subq_10.listing__ds__quarter + , subq_10.listing__ds__year + , subq_10.listing__ds__extract_year + , subq_10.listing__ds__extract_quarter + , subq_10.listing__ds__extract_month + , subq_10.listing__ds__extract_day + , subq_10.listing__ds__extract_dow + , subq_10.listing__ds__extract_doy + , subq_10.listing__created_at__day + , subq_10.listing__created_at__week + , subq_10.listing__created_at__month + , subq_10.listing__created_at__quarter + , subq_10.listing__created_at__year + , subq_10.listing__created_at__extract_year + , subq_10.listing__created_at__extract_quarter + , subq_10.listing__created_at__extract_month + , subq_10.listing__created_at__extract_day + , subq_10.listing__created_at__extract_dow + , subq_10.listing__created_at__extract_doy + , subq_10.ds__day AS metric_time__day + , subq_10.ds__week AS metric_time__week + , subq_10.ds__month AS metric_time__month + , subq_10.ds__quarter AS metric_time__quarter + , subq_10.ds__year AS metric_time__year + , subq_10.ds__extract_year AS metric_time__extract_year + , subq_10.ds__extract_quarter AS metric_time__extract_quarter + , subq_10.ds__extract_month AS metric_time__extract_month + , subq_10.ds__extract_day AS metric_time__extract_day + , subq_10.ds__extract_dow AS metric_time__extract_dow + , subq_10.ds__extract_doy AS metric_time__extract_doy + , subq_10.listing + , subq_10.user + , subq_10.listing__user + , subq_10.country_latest + , subq_10.is_lux_latest + , subq_10.capacity_latest + , subq_10.listing__country_latest + , subq_10.listing__is_lux_latest + , subq_10.listing__capacity_latest + , subq_10.listings + , subq_10.largest_listing + , subq_10.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS ds__day + , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS ds__week + , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS ds__month + , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS ds__quarter + , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS created_at__day + , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS created_at__week + , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS created_at__month + , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS created_at__quarter + , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS created_at__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS listing__ds__day + , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS listing__ds__week + , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS listing__ds__month + , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS listing__ds__quarter + , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS listing__ds__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS listing__created_at__day + , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS listing__created_at__week + , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS listing__created_at__month + , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS listing__created_at__quarter + , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS listing__created_at__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_10 + ) subq_11 + ) subq_12 + ON + subq_9.listing = subq_12.listing + ) subq_13 + ) subq_14 + WHERE booking__is_instant + ) subq_15 + ) subq_16 + GROUP BY + listing__country_latest +) subq_17 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_single_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_single_categorical_dimension_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..b0a46663de --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_single_categorical_dimension_pushdown__plan0_optimized.sql @@ -0,0 +1,40 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'listing__country_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] + SELECT + subq_21.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.country AS listing__country_latest + , subq_21.bookings AS bookings + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_19 + WHERE booking__is_instant + ) subq_21 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_21.listing = listings_latest_src_28000.listing_id +) subq_26 +WHERE booking__is_instant +GROUP BY + listing__country_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_skipped_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_skipped_pushdown__plan0.sql new file mode 100644 index 0000000000..8f2f8c3458 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_skipped_pushdown__plan0.sql @@ -0,0 +1,387 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.listing__country_latest + , subq_10.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_9.listing__country_latest + , SUM(subq_9.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest'] + SELECT + subq_8.listing__country_latest + , subq_8.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.booking__is_instant + , subq_7.listing__country_latest + , subq_7.listing__is_lux_latest + , subq_7.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] + SELECT + subq_6.booking__is_instant + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_2.listing AS listing + , subq_2.booking__is_instant AS booking__is_instant + , subq_5.country_latest AS listing__country_latest + , subq_5.is_lux_latest AS listing__is_lux_latest + , subq_2.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_1.listing + , subq_1.booking__is_instant + , subq_1.bookings + 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.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.booking__paid_at__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.listing + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC(bookings_source_src_28000.ds, day) AS ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC(bookings_source_src_28000.ds, day) AS booking__ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS booking__ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS booking__ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS booking__ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS booking__ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS booking__ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS booking__ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS booking__ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS booking__ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS booking__ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS booking__paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS booking__paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS booking__paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS booking__paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS booking__paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['country_latest', 'is_lux_latest', 'listing', 'listing'] + SELECT + subq_4.listing + , subq_4.country_latest + , subq_4.is_lux_latest + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.ds__day AS metric_time__day + , subq_3.ds__week AS metric_time__week + , subq_3.ds__month AS metric_time__month + , subq_3.ds__quarter AS metric_time__quarter + , subq_3.ds__year AS metric_time__year + , subq_3.ds__extract_year AS metric_time__extract_year + , subq_3.ds__extract_quarter AS metric_time__extract_quarter + , subq_3.ds__extract_month AS metric_time__extract_month + , subq_3.ds__extract_day AS metric_time__extract_day + , subq_3.ds__extract_dow AS metric_time__extract_dow + , subq_3.ds__extract_doy AS metric_time__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS ds__day + , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS ds__week + , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS ds__month + , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS ds__quarter + , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS created_at__day + , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS created_at__week + , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS created_at__month + , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS created_at__quarter + , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS created_at__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS listing__ds__day + , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS listing__ds__week + , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS listing__ds__month + , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS listing__ds__quarter + , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS listing__ds__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS listing__created_at__day + , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS listing__created_at__week + , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS listing__created_at__month + , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS listing__created_at__quarter + , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS listing__created_at__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_3 + ) subq_4 + ) subq_5 + ON + subq_2.listing = subq_5.listing + ) subq_6 + ) subq_7 + WHERE booking__is_instant OR listing__is_lux_latest + ) subq_8 + ) subq_9 + GROUP BY + listing__country_latest +) subq_10 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_skipped_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_skipped_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..be31b01767 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_skipped_pushdown__plan0_optimized.sql @@ -0,0 +1,33 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'listing__country_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] + SELECT + subq_13.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , subq_13.bookings AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_13.listing = listings_latest_src_28000.listing_id +) subq_18 +WHERE booking__is_instant OR listing__is_lux_latest +GROUP BY + listing__country_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_categorical_dimension_pushdown__plan0.sql new file mode 100644 index 0000000000..bc12b03102 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_categorical_dimension_pushdown__plan0.sql @@ -0,0 +1,387 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.booking__is_instant + , subq_10.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_9.booking__is_instant + , SUM(subq_9.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant'] + SELECT + subq_8.booking__is_instant + , subq_8.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.booking__is_instant + , subq_7.listing__is_lux_latest + , subq_7.listing__capacity_latest + , subq_7.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing__is_lux_latest', 'listing__capacity_latest'] + SELECT + subq_6.booking__is_instant + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_2.listing AS listing + , subq_2.booking__is_instant AS booking__is_instant + , subq_5.is_lux_latest AS listing__is_lux_latest + , subq_5.capacity_latest AS listing__capacity_latest + , subq_2.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_1.listing + , subq_1.booking__is_instant + , subq_1.bookings + 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.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.booking__paid_at__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.listing + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['is_lux_latest', 'capacity_latest', 'listing', 'listing'] + SELECT + subq_4.listing + , subq_4.is_lux_latest + , subq_4.capacity_latest + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.ds__day AS metric_time__day + , subq_3.ds__week AS metric_time__week + , subq_3.ds__month AS metric_time__month + , subq_3.ds__quarter AS metric_time__quarter + , subq_3.ds__year AS metric_time__year + , subq_3.ds__extract_year AS metric_time__extract_year + , subq_3.ds__extract_quarter AS metric_time__extract_quarter + , subq_3.ds__extract_month AS metric_time__extract_month + , subq_3.ds__extract_day AS metric_time__extract_day + , subq_3.ds__extract_dow AS metric_time__extract_dow + , subq_3.ds__extract_doy AS metric_time__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_3 + ) subq_4 + ) subq_5 + ON + subq_2.listing = subq_5.listing + ) subq_6 + ) subq_7 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_8 + ) subq_9 + GROUP BY + subq_9.booking__is_instant +) subq_10 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..98cc26bb70 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql @@ -0,0 +1,33 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'booking__is_instant'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + booking__is_instant + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing__is_lux_latest', 'listing__capacity_latest'] + SELECT + subq_13.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , subq_13.bookings AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_13.listing = listings_latest_src_28000.listing_id +) subq_18 +WHERE listing__is_lux_latest OR listing__capacity_latest > 4 +GROUP BY + booking__is_instant diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..9022b49e18 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql @@ -0,0 +1,651 @@ +-- Compute Metrics via Expressions +SELECT + CAST(subq_28.west_coast_balance_first_day AS DOUBLE) / CAST(NULLIF(subq_28.east_coast_balance_first_dat, 0) AS DOUBLE) AS regional_starting_balance_ratios +FROM ( + -- Combine Aggregated Outputs + SELECT + MAX(subq_13.west_coast_balance_first_day) AS west_coast_balance_first_day + , MAX(subq_27.east_coast_balance_first_dat) AS east_coast_balance_first_dat + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_12.total_account_balance_first_day AS west_coast_balance_first_day + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_11.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_10.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_7.ds__day AS ds__day + , subq_7.user__home_state_latest AS user__home_state_latest + , subq_7.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + 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.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__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.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_7 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_8.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + 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.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__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.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_8 + ) subq_9 + ON + subq_7.ds__day = subq_9.ds__day__complete + ) subq_10 + ) subq_11 + ) subq_12 + ) subq_13 + CROSS JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_26.total_account_balance_first_day AS east_coast_balance_first_dat + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_25.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_24.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_21.ds__day AS ds__day + , subq_21.user__home_state_latest AS user__home_state_latest + , subq_21.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_14.ds__day + , subq_14.ds__week + , subq_14.ds__month + , subq_14.ds__quarter + , subq_14.ds__year + , subq_14.ds__extract_year + , subq_14.ds__extract_quarter + , subq_14.ds__extract_month + , subq_14.ds__extract_day + , subq_14.ds__extract_dow + , subq_14.ds__extract_doy + , subq_14.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__extract_doy + , subq_14.ds__day AS metric_time__day + , subq_14.ds__week AS metric_time__week + , subq_14.ds__month AS metric_time__month + , subq_14.ds__quarter AS metric_time__quarter + , subq_14.ds__year AS metric_time__year + , subq_14.ds__extract_year AS metric_time__extract_year + , subq_14.ds__extract_quarter AS metric_time__extract_quarter + , subq_14.ds__extract_month AS metric_time__extract_month + , subq_14.ds__extract_day AS metric_time__extract_day + , subq_14.ds__extract_dow AS metric_time__extract_dow + , subq_14.ds__extract_doy AS metric_time__extract_doy + , subq_14.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_21 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_22.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_14.ds__day + , subq_14.ds__week + , subq_14.ds__month + , subq_14.ds__quarter + , subq_14.ds__year + , subq_14.ds__extract_year + , subq_14.ds__extract_quarter + , subq_14.ds__extract_month + , subq_14.ds__extract_day + , subq_14.ds__extract_dow + , subq_14.ds__extract_doy + , subq_14.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__extract_doy + , subq_14.ds__day AS metric_time__day + , subq_14.ds__week AS metric_time__week + , subq_14.ds__month AS metric_time__month + , subq_14.ds__quarter AS metric_time__quarter + , subq_14.ds__year AS metric_time__year + , subq_14.ds__extract_year AS metric_time__extract_year + , subq_14.ds__extract_quarter AS metric_time__extract_quarter + , subq_14.ds__extract_month AS metric_time__extract_month + , subq_14.ds__extract_day AS metric_time__extract_day + , subq_14.ds__extract_dow AS metric_time__extract_dow + , subq_14.ds__extract_doy AS metric_time__extract_doy + , subq_14.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_22 + ) subq_23 + ON + subq_21.ds__day = subq_23.ds__day__complete + ) subq_24 + ) subq_25 + ) subq_26 + ) subq_27 +) subq_28 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..44eac537d1 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,102 @@ +-- Combine Aggregated Outputs +-- Compute Metrics via Expressions +SELECT + CAST(MAX(subq_42.west_coast_balance_first_day) AS DOUBLE) / CAST(NULLIF(MAX(subq_56.east_coast_balance_first_dat), 0) AS DOUBLE) AS regional_starting_balance_ratios +FROM ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_36.total_account_balance_first_day) AS west_coast_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_36 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_38 + ON + subq_36.ds__day = subq_38.ds__day__complete +) subq_42 +CROSS JOIN ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_50.total_account_balance_first_day) AS east_coast_balance_first_dat + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_50 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_52 + ON + subq_50.ds__day = subq_52.ds__day__complete +) subq_56 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..eba0dec278 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql @@ -0,0 +1,563 @@ +-- Compute Metrics via Expressions +SELECT + subq_19.metric_time__day + , CAST(subq_19.average_booking_value AS DOUBLE) / CAST(NULLIF(subq_19.max_booking_value, 0) AS DOUBLE) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) AS metric_time__day + , MAX(subq_13.average_booking_value) AS average_booking_value + , MAX(subq_18.max_booking_value) AS max_booking_value + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_12.metric_time__day + , subq_12.average_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_11.metric_time__day + , AVG(subq_11.average_booking_value) AS average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + SELECT + subq_10.metric_time__day + , subq_10.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__week + , subq_7.ds__month + , subq_7.ds__quarter + , subq_7.ds__year + , subq_7.ds__extract_year + , subq_7.ds__extract_quarter + , subq_7.ds__extract_month + , subq_7.ds__extract_day + , subq_7.ds__extract_dow + , subq_7.ds__extract_doy + , subq_7.ds_partitioned__day + , subq_7.ds_partitioned__week + , subq_7.ds_partitioned__month + , subq_7.ds_partitioned__quarter + , subq_7.ds_partitioned__year + , subq_7.ds_partitioned__extract_year + , subq_7.ds_partitioned__extract_quarter + , subq_7.ds_partitioned__extract_month + , subq_7.ds_partitioned__extract_day + , subq_7.ds_partitioned__extract_dow + , subq_7.ds_partitioned__extract_doy + , subq_7.paid_at__day + , subq_7.paid_at__week + , subq_7.paid_at__month + , subq_7.paid_at__quarter + , subq_7.paid_at__year + , subq_7.paid_at__extract_year + , subq_7.paid_at__extract_quarter + , subq_7.paid_at__extract_month + , subq_7.paid_at__extract_day + , subq_7.paid_at__extract_dow + , subq_7.paid_at__extract_doy + , subq_7.booking__ds__day + , subq_7.booking__ds__week + , subq_7.booking__ds__month + , subq_7.booking__ds__quarter + , subq_7.booking__ds__year + , subq_7.booking__ds__extract_year + , subq_7.booking__ds__extract_quarter + , subq_7.booking__ds__extract_month + , subq_7.booking__ds__extract_day + , subq_7.booking__ds__extract_dow + , subq_7.booking__ds__extract_doy + , subq_7.booking__ds_partitioned__day + , subq_7.booking__ds_partitioned__week + , subq_7.booking__ds_partitioned__month + , subq_7.booking__ds_partitioned__quarter + , subq_7.booking__ds_partitioned__year + , subq_7.booking__ds_partitioned__extract_year + , subq_7.booking__ds_partitioned__extract_quarter + , subq_7.booking__ds_partitioned__extract_month + , subq_7.booking__ds_partitioned__extract_day + , subq_7.booking__ds_partitioned__extract_dow + , subq_7.booking__ds_partitioned__extract_doy + , subq_7.booking__paid_at__day + , subq_7.booking__paid_at__week + , subq_7.booking__paid_at__month + , subq_7.booking__paid_at__quarter + , subq_7.booking__paid_at__year + , subq_7.booking__paid_at__extract_year + , subq_7.booking__paid_at__extract_quarter + , subq_7.booking__paid_at__extract_month + , subq_7.booking__paid_at__extract_day + , subq_7.booking__paid_at__extract_dow + , subq_7.booking__paid_at__extract_doy + , subq_7.metric_time__day + , subq_7.metric_time__week + , subq_7.metric_time__month + , subq_7.metric_time__quarter + , subq_7.metric_time__year + , subq_7.metric_time__extract_year + , subq_7.metric_time__extract_quarter + , subq_7.metric_time__extract_month + , subq_7.metric_time__extract_day + , subq_7.metric_time__extract_dow + , subq_7.metric_time__extract_doy + , subq_7.listing + , subq_7.guest + , subq_7.host + , subq_7.booking__listing + , subq_7.booking__guest + , subq_7.booking__host + , subq_7.is_instant + , subq_7.booking__is_instant + , subq_7.bookings + , subq_7.instant_bookings + , subq_7.booking_value + , subq_7.max_booking_value + , subq_7.min_booking_value + , subq_7.bookers + , subq_7.average_booking_value + , subq_7.referred_bookings + , subq_7.median_booking_value + , subq_7.booking_value_p99 + , subq_7.discrete_booking_value_p99 + , subq_7.approximate_continuous_booking_value_p99 + , subq_7.approximate_discrete_booking_value_p99 + 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.ds_partitioned__day + , subq_6.ds_partitioned__week + , subq_6.ds_partitioned__month + , subq_6.ds_partitioned__quarter + , subq_6.ds_partitioned__year + , subq_6.ds_partitioned__extract_year + , subq_6.ds_partitioned__extract_quarter + , subq_6.ds_partitioned__extract_month + , subq_6.ds_partitioned__extract_day + , subq_6.ds_partitioned__extract_dow + , subq_6.ds_partitioned__extract_doy + , subq_6.paid_at__day + , subq_6.paid_at__week + , subq_6.paid_at__month + , subq_6.paid_at__quarter + , subq_6.paid_at__year + , subq_6.paid_at__extract_year + , subq_6.paid_at__extract_quarter + , subq_6.paid_at__extract_month + , subq_6.paid_at__extract_day + , subq_6.paid_at__extract_dow + , subq_6.paid_at__extract_doy + , subq_6.booking__ds__day + , subq_6.booking__ds__week + , subq_6.booking__ds__month + , subq_6.booking__ds__quarter + , subq_6.booking__ds__year + , subq_6.booking__ds__extract_year + , subq_6.booking__ds__extract_quarter + , subq_6.booking__ds__extract_month + , subq_6.booking__ds__extract_day + , subq_6.booking__ds__extract_dow + , subq_6.booking__ds__extract_doy + , subq_6.booking__ds_partitioned__day + , subq_6.booking__ds_partitioned__week + , subq_6.booking__ds_partitioned__month + , subq_6.booking__ds_partitioned__quarter + , subq_6.booking__ds_partitioned__year + , subq_6.booking__ds_partitioned__extract_year + , subq_6.booking__ds_partitioned__extract_quarter + , subq_6.booking__ds_partitioned__extract_month + , subq_6.booking__ds_partitioned__extract_day + , subq_6.booking__ds_partitioned__extract_dow + , subq_6.booking__ds_partitioned__extract_doy + , subq_6.booking__paid_at__day + , subq_6.booking__paid_at__week + , subq_6.booking__paid_at__month + , subq_6.booking__paid_at__quarter + , subq_6.booking__paid_at__year + , subq_6.booking__paid_at__extract_year + , subq_6.booking__paid_at__extract_quarter + , subq_6.booking__paid_at__extract_month + , subq_6.booking__paid_at__extract_day + , subq_6.booking__paid_at__extract_dow + , subq_6.booking__paid_at__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.listing + , subq_6.guest + , subq_6.host + , subq_6.booking__listing + , subq_6.booking__guest + , subq_6.booking__host + , subq_6.is_instant + , subq_6.booking__is_instant + , subq_6.bookings + , subq_6.instant_bookings + , subq_6.booking_value + , subq_6.max_booking_value + , subq_6.min_booking_value + , subq_6.bookers + , subq_6.average_booking_value + , subq_6.referred_bookings + , subq_6.median_booking_value + , subq_6.booking_value_p99 + , subq_6.discrete_booking_value_p99 + , subq_6.approximate_continuous_booking_value_p99 + , subq_6.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 + WHERE booking__is_instant + ) subq_10 + ) subq_11 + GROUP BY + subq_11.metric_time__day + ) subq_12 + ) subq_13 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_17.metric_time__day + , subq_17.max_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_16.metric_time__day + , MAX(subq_16.max_booking_value) AS max_booking_value + FROM ( + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + SELECT + subq_15.metric_time__day + , subq_15.max_booking_value + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_14.ds__day + , subq_14.ds__week + , subq_14.ds__month + , subq_14.ds__quarter + , subq_14.ds__year + , subq_14.ds__extract_year + , subq_14.ds__extract_quarter + , subq_14.ds__extract_month + , subq_14.ds__extract_day + , subq_14.ds__extract_dow + , subq_14.ds__extract_doy + , subq_14.ds_partitioned__day + , subq_14.ds_partitioned__week + , subq_14.ds_partitioned__month + , subq_14.ds_partitioned__quarter + , subq_14.ds_partitioned__year + , subq_14.ds_partitioned__extract_year + , subq_14.ds_partitioned__extract_quarter + , subq_14.ds_partitioned__extract_month + , subq_14.ds_partitioned__extract_day + , subq_14.ds_partitioned__extract_dow + , subq_14.ds_partitioned__extract_doy + , subq_14.paid_at__day + , subq_14.paid_at__week + , subq_14.paid_at__month + , subq_14.paid_at__quarter + , subq_14.paid_at__year + , subq_14.paid_at__extract_year + , subq_14.paid_at__extract_quarter + , subq_14.paid_at__extract_month + , subq_14.paid_at__extract_day + , subq_14.paid_at__extract_dow + , subq_14.paid_at__extract_doy + , subq_14.booking__ds__day + , subq_14.booking__ds__week + , subq_14.booking__ds__month + , subq_14.booking__ds__quarter + , subq_14.booking__ds__year + , subq_14.booking__ds__extract_year + , subq_14.booking__ds__extract_quarter + , subq_14.booking__ds__extract_month + , subq_14.booking__ds__extract_day + , subq_14.booking__ds__extract_dow + , subq_14.booking__ds__extract_doy + , subq_14.booking__ds_partitioned__day + , subq_14.booking__ds_partitioned__week + , subq_14.booking__ds_partitioned__month + , subq_14.booking__ds_partitioned__quarter + , subq_14.booking__ds_partitioned__year + , subq_14.booking__ds_partitioned__extract_year + , subq_14.booking__ds_partitioned__extract_quarter + , subq_14.booking__ds_partitioned__extract_month + , subq_14.booking__ds_partitioned__extract_day + , subq_14.booking__ds_partitioned__extract_dow + , subq_14.booking__ds_partitioned__extract_doy + , subq_14.booking__paid_at__day + , subq_14.booking__paid_at__week + , subq_14.booking__paid_at__month + , subq_14.booking__paid_at__quarter + , subq_14.booking__paid_at__year + , subq_14.booking__paid_at__extract_year + , subq_14.booking__paid_at__extract_quarter + , subq_14.booking__paid_at__extract_month + , subq_14.booking__paid_at__extract_day + , subq_14.booking__paid_at__extract_dow + , subq_14.booking__paid_at__extract_doy + , subq_14.ds__day AS metric_time__day + , subq_14.ds__week AS metric_time__week + , subq_14.ds__month AS metric_time__month + , subq_14.ds__quarter AS metric_time__quarter + , subq_14.ds__year AS metric_time__year + , subq_14.ds__extract_year AS metric_time__extract_year + , subq_14.ds__extract_quarter AS metric_time__extract_quarter + , subq_14.ds__extract_month AS metric_time__extract_month + , subq_14.ds__extract_day AS metric_time__extract_day + , subq_14.ds__extract_dow AS metric_time__extract_dow + , subq_14.ds__extract_doy AS metric_time__extract_doy + , subq_14.listing + , subq_14.guest + , subq_14.host + , subq_14.booking__listing + , subq_14.booking__guest + , subq_14.booking__host + , subq_14.is_instant + , subq_14.booking__is_instant + , subq_14.bookings + , subq_14.instant_bookings + , subq_14.booking_value + , subq_14.max_booking_value + , subq_14.min_booking_value + , subq_14.bookers + , subq_14.average_booking_value + , subq_14.referred_bookings + , subq_14.median_booking_value + , subq_14.booking_value_p99 + , subq_14.discrete_booking_value_p99 + , subq_14.approximate_continuous_booking_value_p99 + , subq_14.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + GROUP BY + subq_16.metric_time__day + ) subq_17 + ) subq_18 + ON + subq_13.metric_time__day = subq_18.metric_time__day + GROUP BY + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) +) subq_19 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..111a82caa8 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,58 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , CAST(average_booking_value AS DOUBLE) / CAST(NULLIF(max_booking_value, 0) AS DOUBLE) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) AS metric_time__day + , MAX(subq_27.average_booking_value) AS average_booking_value + , MAX(subq_32.max_booking_value) AS max_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , AVG(average_booking_value) AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + metric_time__day + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_21 + WHERE booking__is_instant + ) subq_23 + WHERE booking__is_instant + GROUP BY + metric_time__day + ) subq_27 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , MAX(booking_value) AS max_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_32 + ON + subq_27.metric_time__day = subq_32.metric_time__day + GROUP BY + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) +) subq_33 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_single_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_single_categorical_dimension_pushdown__plan0.sql new file mode 100644 index 0000000000..85f5d39687 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_single_categorical_dimension_pushdown__plan0.sql @@ -0,0 +1,486 @@ +-- Compute Metrics via Expressions +SELECT + subq_17.listing__country_latest + , subq_17.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_16.listing__country_latest + , SUM(subq_16.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest'] + SELECT + subq_15.listing__country_latest + , subq_15.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_14.booking__is_instant + , subq_14.listing__country_latest + , subq_14.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] + SELECT + subq_13.booking__is_instant + , subq_13.listing__country_latest + , subq_13.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_9.listing AS listing + , subq_9.booking__is_instant AS booking__is_instant + , subq_12.country_latest AS listing__country_latest + , subq_9.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_8.listing + , subq_8.booking__is_instant + , subq_8.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__week + , subq_7.ds__month + , subq_7.ds__quarter + , subq_7.ds__year + , subq_7.ds__extract_year + , subq_7.ds__extract_quarter + , subq_7.ds__extract_month + , subq_7.ds__extract_day + , subq_7.ds__extract_dow + , subq_7.ds__extract_doy + , subq_7.ds_partitioned__day + , subq_7.ds_partitioned__week + , subq_7.ds_partitioned__month + , subq_7.ds_partitioned__quarter + , subq_7.ds_partitioned__year + , subq_7.ds_partitioned__extract_year + , subq_7.ds_partitioned__extract_quarter + , subq_7.ds_partitioned__extract_month + , subq_7.ds_partitioned__extract_day + , subq_7.ds_partitioned__extract_dow + , subq_7.ds_partitioned__extract_doy + , subq_7.paid_at__day + , subq_7.paid_at__week + , subq_7.paid_at__month + , subq_7.paid_at__quarter + , subq_7.paid_at__year + , subq_7.paid_at__extract_year + , subq_7.paid_at__extract_quarter + , subq_7.paid_at__extract_month + , subq_7.paid_at__extract_day + , subq_7.paid_at__extract_dow + , subq_7.paid_at__extract_doy + , subq_7.booking__ds__day + , subq_7.booking__ds__week + , subq_7.booking__ds__month + , subq_7.booking__ds__quarter + , subq_7.booking__ds__year + , subq_7.booking__ds__extract_year + , subq_7.booking__ds__extract_quarter + , subq_7.booking__ds__extract_month + , subq_7.booking__ds__extract_day + , subq_7.booking__ds__extract_dow + , subq_7.booking__ds__extract_doy + , subq_7.booking__ds_partitioned__day + , subq_7.booking__ds_partitioned__week + , subq_7.booking__ds_partitioned__month + , subq_7.booking__ds_partitioned__quarter + , subq_7.booking__ds_partitioned__year + , subq_7.booking__ds_partitioned__extract_year + , subq_7.booking__ds_partitioned__extract_quarter + , subq_7.booking__ds_partitioned__extract_month + , subq_7.booking__ds_partitioned__extract_day + , subq_7.booking__ds_partitioned__extract_dow + , subq_7.booking__ds_partitioned__extract_doy + , subq_7.booking__paid_at__day + , subq_7.booking__paid_at__week + , subq_7.booking__paid_at__month + , subq_7.booking__paid_at__quarter + , subq_7.booking__paid_at__year + , subq_7.booking__paid_at__extract_year + , subq_7.booking__paid_at__extract_quarter + , subq_7.booking__paid_at__extract_month + , subq_7.booking__paid_at__extract_day + , subq_7.booking__paid_at__extract_dow + , subq_7.booking__paid_at__extract_doy + , subq_7.metric_time__day + , subq_7.metric_time__week + , subq_7.metric_time__month + , subq_7.metric_time__quarter + , subq_7.metric_time__year + , subq_7.metric_time__extract_year + , subq_7.metric_time__extract_quarter + , subq_7.metric_time__extract_month + , subq_7.metric_time__extract_day + , subq_7.metric_time__extract_dow + , subq_7.metric_time__extract_doy + , subq_7.listing + , subq_7.guest + , subq_7.host + , subq_7.booking__listing + , subq_7.booking__guest + , subq_7.booking__host + , subq_7.is_instant + , subq_7.booking__is_instant + , subq_7.bookings + , subq_7.instant_bookings + , subq_7.booking_value + , subq_7.max_booking_value + , subq_7.min_booking_value + , subq_7.bookers + , subq_7.average_booking_value + , subq_7.referred_bookings + , subq_7.median_booking_value + , subq_7.booking_value_p99 + , subq_7.discrete_booking_value_p99 + , subq_7.approximate_continuous_booking_value_p99 + , subq_7.approximate_discrete_booking_value_p99 + 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.ds_partitioned__day + , subq_6.ds_partitioned__week + , subq_6.ds_partitioned__month + , subq_6.ds_partitioned__quarter + , subq_6.ds_partitioned__year + , subq_6.ds_partitioned__extract_year + , subq_6.ds_partitioned__extract_quarter + , subq_6.ds_partitioned__extract_month + , subq_6.ds_partitioned__extract_day + , subq_6.ds_partitioned__extract_dow + , subq_6.ds_partitioned__extract_doy + , subq_6.paid_at__day + , subq_6.paid_at__week + , subq_6.paid_at__month + , subq_6.paid_at__quarter + , subq_6.paid_at__year + , subq_6.paid_at__extract_year + , subq_6.paid_at__extract_quarter + , subq_6.paid_at__extract_month + , subq_6.paid_at__extract_day + , subq_6.paid_at__extract_dow + , subq_6.paid_at__extract_doy + , subq_6.booking__ds__day + , subq_6.booking__ds__week + , subq_6.booking__ds__month + , subq_6.booking__ds__quarter + , subq_6.booking__ds__year + , subq_6.booking__ds__extract_year + , subq_6.booking__ds__extract_quarter + , subq_6.booking__ds__extract_month + , subq_6.booking__ds__extract_day + , subq_6.booking__ds__extract_dow + , subq_6.booking__ds__extract_doy + , subq_6.booking__ds_partitioned__day + , subq_6.booking__ds_partitioned__week + , subq_6.booking__ds_partitioned__month + , subq_6.booking__ds_partitioned__quarter + , subq_6.booking__ds_partitioned__year + , subq_6.booking__ds_partitioned__extract_year + , subq_6.booking__ds_partitioned__extract_quarter + , subq_6.booking__ds_partitioned__extract_month + , subq_6.booking__ds_partitioned__extract_day + , subq_6.booking__ds_partitioned__extract_dow + , subq_6.booking__ds_partitioned__extract_doy + , subq_6.booking__paid_at__day + , subq_6.booking__paid_at__week + , subq_6.booking__paid_at__month + , subq_6.booking__paid_at__quarter + , subq_6.booking__paid_at__year + , subq_6.booking__paid_at__extract_year + , subq_6.booking__paid_at__extract_quarter + , subq_6.booking__paid_at__extract_month + , subq_6.booking__paid_at__extract_day + , subq_6.booking__paid_at__extract_dow + , subq_6.booking__paid_at__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.listing + , subq_6.guest + , subq_6.host + , subq_6.booking__listing + , subq_6.booking__guest + , subq_6.booking__host + , subq_6.is_instant + , subq_6.booking__is_instant + , subq_6.bookings + , subq_6.instant_bookings + , subq_6.booking_value + , subq_6.max_booking_value + , subq_6.min_booking_value + , subq_6.bookers + , subq_6.average_booking_value + , subq_6.referred_bookings + , subq_6.median_booking_value + , subq_6.booking_value_p99 + , subq_6.discrete_booking_value_p99 + , subq_6.approximate_continuous_booking_value_p99 + , subq_6.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['country_latest', 'listing'] + SELECT + subq_11.listing + , subq_11.country_latest + FROM ( + -- Metric Time Dimension 'ds' + 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.created_at__day + , subq_10.created_at__week + , subq_10.created_at__month + , subq_10.created_at__quarter + , subq_10.created_at__year + , subq_10.created_at__extract_year + , subq_10.created_at__extract_quarter + , subq_10.created_at__extract_month + , subq_10.created_at__extract_day + , subq_10.created_at__extract_dow + , subq_10.created_at__extract_doy + , subq_10.listing__ds__day + , subq_10.listing__ds__week + , subq_10.listing__ds__month + , subq_10.listing__ds__quarter + , subq_10.listing__ds__year + , subq_10.listing__ds__extract_year + , subq_10.listing__ds__extract_quarter + , subq_10.listing__ds__extract_month + , subq_10.listing__ds__extract_day + , subq_10.listing__ds__extract_dow + , subq_10.listing__ds__extract_doy + , subq_10.listing__created_at__day + , subq_10.listing__created_at__week + , subq_10.listing__created_at__month + , subq_10.listing__created_at__quarter + , subq_10.listing__created_at__year + , subq_10.listing__created_at__extract_year + , subq_10.listing__created_at__extract_quarter + , subq_10.listing__created_at__extract_month + , subq_10.listing__created_at__extract_day + , subq_10.listing__created_at__extract_dow + , subq_10.listing__created_at__extract_doy + , subq_10.ds__day AS metric_time__day + , subq_10.ds__week AS metric_time__week + , subq_10.ds__month AS metric_time__month + , subq_10.ds__quarter AS metric_time__quarter + , subq_10.ds__year AS metric_time__year + , subq_10.ds__extract_year AS metric_time__extract_year + , subq_10.ds__extract_quarter AS metric_time__extract_quarter + , subq_10.ds__extract_month AS metric_time__extract_month + , subq_10.ds__extract_day AS metric_time__extract_day + , subq_10.ds__extract_dow AS metric_time__extract_dow + , subq_10.ds__extract_doy AS metric_time__extract_doy + , subq_10.listing + , subq_10.user + , subq_10.listing__user + , subq_10.country_latest + , subq_10.is_lux_latest + , subq_10.capacity_latest + , subq_10.listing__country_latest + , subq_10.listing__is_lux_latest + , subq_10.listing__capacity_latest + , subq_10.listings + , subq_10.largest_listing + , subq_10.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_10 + ) subq_11 + ) subq_12 + ON + subq_9.listing = subq_12.listing + ) subq_13 + ) subq_14 + WHERE booking__is_instant + ) subq_15 + ) subq_16 + GROUP BY + subq_16.listing__country_latest +) subq_17 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_single_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_single_categorical_dimension_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..b0a46663de --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_single_categorical_dimension_pushdown__plan0_optimized.sql @@ -0,0 +1,40 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'listing__country_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] + SELECT + subq_21.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.country AS listing__country_latest + , subq_21.bookings AS bookings + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_19 + WHERE booking__is_instant + ) subq_21 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_21.listing = listings_latest_src_28000.listing_id +) subq_26 +WHERE booking__is_instant +GROUP BY + listing__country_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_skipped_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_skipped_pushdown__plan0.sql new file mode 100644 index 0000000000..968378bfc3 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_skipped_pushdown__plan0.sql @@ -0,0 +1,387 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.listing__country_latest + , subq_10.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_9.listing__country_latest + , SUM(subq_9.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest'] + SELECT + subq_8.listing__country_latest + , subq_8.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.booking__is_instant + , subq_7.listing__country_latest + , subq_7.listing__is_lux_latest + , subq_7.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] + SELECT + subq_6.booking__is_instant + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_2.listing AS listing + , subq_2.booking__is_instant AS booking__is_instant + , subq_5.country_latest AS listing__country_latest + , subq_5.is_lux_latest AS listing__is_lux_latest + , subq_2.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_1.listing + , subq_1.booking__is_instant + , subq_1.bookings + 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.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.booking__paid_at__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.listing + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['country_latest', 'is_lux_latest', 'listing', 'listing'] + SELECT + subq_4.listing + , subq_4.country_latest + , subq_4.is_lux_latest + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.ds__day AS metric_time__day + , subq_3.ds__week AS metric_time__week + , subq_3.ds__month AS metric_time__month + , subq_3.ds__quarter AS metric_time__quarter + , subq_3.ds__year AS metric_time__year + , subq_3.ds__extract_year AS metric_time__extract_year + , subq_3.ds__extract_quarter AS metric_time__extract_quarter + , subq_3.ds__extract_month AS metric_time__extract_month + , subq_3.ds__extract_day AS metric_time__extract_day + , subq_3.ds__extract_dow AS metric_time__extract_dow + , subq_3.ds__extract_doy AS metric_time__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_3 + ) subq_4 + ) subq_5 + ON + subq_2.listing = subq_5.listing + ) subq_6 + ) subq_7 + WHERE booking__is_instant OR listing__is_lux_latest + ) subq_8 + ) subq_9 + GROUP BY + subq_9.listing__country_latest +) subq_10 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_skipped_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_skipped_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..be31b01767 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_skipped_pushdown__plan0_optimized.sql @@ -0,0 +1,33 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'listing__country_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] + SELECT + subq_13.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , subq_13.bookings AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_13.listing = listings_latest_src_28000.listing_id +) subq_18 +WHERE booking__is_instant OR listing__is_lux_latest +GROUP BY + listing__country_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_categorical_dimension_pushdown__plan0.sql new file mode 100644 index 0000000000..c864c9883c --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_categorical_dimension_pushdown__plan0.sql @@ -0,0 +1,387 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.booking__is_instant + , subq_10.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_9.booking__is_instant + , SUM(subq_9.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant'] + SELECT + subq_8.booking__is_instant + , subq_8.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.booking__is_instant + , subq_7.listing__is_lux_latest + , subq_7.listing__capacity_latest + , subq_7.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing__is_lux_latest', 'listing__capacity_latest'] + SELECT + subq_6.booking__is_instant + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_2.listing AS listing + , subq_2.booking__is_instant AS booking__is_instant + , subq_5.is_lux_latest AS listing__is_lux_latest + , subq_5.capacity_latest AS listing__capacity_latest + , subq_2.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_1.listing + , subq_1.booking__is_instant + , subq_1.bookings + 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.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.booking__paid_at__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.listing + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['is_lux_latest', 'capacity_latest', 'listing', 'listing'] + SELECT + subq_4.listing + , subq_4.is_lux_latest + , subq_4.capacity_latest + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.ds__day AS metric_time__day + , subq_3.ds__week AS metric_time__week + , subq_3.ds__month AS metric_time__month + , subq_3.ds__quarter AS metric_time__quarter + , subq_3.ds__year AS metric_time__year + , subq_3.ds__extract_year AS metric_time__extract_year + , subq_3.ds__extract_quarter AS metric_time__extract_quarter + , subq_3.ds__extract_month AS metric_time__extract_month + , subq_3.ds__extract_day AS metric_time__extract_day + , subq_3.ds__extract_dow AS metric_time__extract_dow + , subq_3.ds__extract_doy AS metric_time__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_3 + ) subq_4 + ) subq_5 + ON + subq_2.listing = subq_5.listing + ) subq_6 + ) subq_7 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_8 + ) subq_9 + GROUP BY + subq_9.booking__is_instant +) subq_10 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..98cc26bb70 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql @@ -0,0 +1,33 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'booking__is_instant'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + booking__is_instant + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing__is_lux_latest', 'listing__capacity_latest'] + SELECT + subq_13.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , subq_13.bookings AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_13.listing = listings_latest_src_28000.listing_id +) subq_18 +WHERE listing__is_lux_latest OR listing__capacity_latest > 4 +GROUP BY + booking__is_instant diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..e1b07ee2ad --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql @@ -0,0 +1,651 @@ +-- Compute Metrics via Expressions +SELECT + CAST(subq_28.west_coast_balance_first_day AS DOUBLE PRECISION) / CAST(NULLIF(subq_28.east_coast_balance_first_dat, 0) AS DOUBLE PRECISION) AS regional_starting_balance_ratios +FROM ( + -- Combine Aggregated Outputs + SELECT + MAX(subq_13.west_coast_balance_first_day) AS west_coast_balance_first_day + , MAX(subq_27.east_coast_balance_first_dat) AS east_coast_balance_first_dat + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_12.total_account_balance_first_day AS west_coast_balance_first_day + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_11.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_10.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_7.ds__day AS ds__day + , subq_7.user__home_state_latest AS user__home_state_latest + , subq_7.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + 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.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__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.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_7 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_8.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + 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.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__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.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_8 + ) subq_9 + ON + subq_7.ds__day = subq_9.ds__day__complete + ) subq_10 + ) subq_11 + ) subq_12 + ) subq_13 + CROSS JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_26.total_account_balance_first_day AS east_coast_balance_first_dat + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_25.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_24.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_21.ds__day AS ds__day + , subq_21.user__home_state_latest AS user__home_state_latest + , subq_21.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_14.ds__day + , subq_14.ds__week + , subq_14.ds__month + , subq_14.ds__quarter + , subq_14.ds__year + , subq_14.ds__extract_year + , subq_14.ds__extract_quarter + , subq_14.ds__extract_month + , subq_14.ds__extract_day + , subq_14.ds__extract_dow + , subq_14.ds__extract_doy + , subq_14.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__extract_doy + , subq_14.ds__day AS metric_time__day + , subq_14.ds__week AS metric_time__week + , subq_14.ds__month AS metric_time__month + , subq_14.ds__quarter AS metric_time__quarter + , subq_14.ds__year AS metric_time__year + , subq_14.ds__extract_year AS metric_time__extract_year + , subq_14.ds__extract_quarter AS metric_time__extract_quarter + , subq_14.ds__extract_month AS metric_time__extract_month + , subq_14.ds__extract_day AS metric_time__extract_day + , subq_14.ds__extract_dow AS metric_time__extract_dow + , subq_14.ds__extract_doy AS metric_time__extract_doy + , subq_14.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_21 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_22.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_14.ds__day + , subq_14.ds__week + , subq_14.ds__month + , subq_14.ds__quarter + , subq_14.ds__year + , subq_14.ds__extract_year + , subq_14.ds__extract_quarter + , subq_14.ds__extract_month + , subq_14.ds__extract_day + , subq_14.ds__extract_dow + , subq_14.ds__extract_doy + , subq_14.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__extract_doy + , subq_14.ds__day AS metric_time__day + , subq_14.ds__week AS metric_time__week + , subq_14.ds__month AS metric_time__month + , subq_14.ds__quarter AS metric_time__quarter + , subq_14.ds__year AS metric_time__year + , subq_14.ds__extract_year AS metric_time__extract_year + , subq_14.ds__extract_quarter AS metric_time__extract_quarter + , subq_14.ds__extract_month AS metric_time__extract_month + , subq_14.ds__extract_day AS metric_time__extract_day + , subq_14.ds__extract_dow AS metric_time__extract_dow + , subq_14.ds__extract_doy AS metric_time__extract_doy + , subq_14.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_22 + ) subq_23 + ON + subq_21.ds__day = subq_23.ds__day__complete + ) subq_24 + ) subq_25 + ) subq_26 + ) subq_27 +) subq_28 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..80c554f04a --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,102 @@ +-- Combine Aggregated Outputs +-- Compute Metrics via Expressions +SELECT + CAST(MAX(subq_42.west_coast_balance_first_day) AS DOUBLE PRECISION) / CAST(NULLIF(MAX(subq_56.east_coast_balance_first_dat), 0) AS DOUBLE PRECISION) AS regional_starting_balance_ratios +FROM ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_36.total_account_balance_first_day) AS west_coast_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_36 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_38 + ON + subq_36.ds__day = subq_38.ds__day__complete +) subq_42 +CROSS JOIN ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_50.total_account_balance_first_day) AS east_coast_balance_first_dat + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_50 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_52 + ON + subq_50.ds__day = subq_52.ds__day__complete +) subq_56 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..f11c286f44 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql @@ -0,0 +1,563 @@ +-- Compute Metrics via Expressions +SELECT + subq_19.metric_time__day + , CAST(subq_19.average_booking_value AS DOUBLE PRECISION) / CAST(NULLIF(subq_19.max_booking_value, 0) AS DOUBLE PRECISION) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) AS metric_time__day + , MAX(subq_13.average_booking_value) AS average_booking_value + , MAX(subq_18.max_booking_value) AS max_booking_value + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_12.metric_time__day + , subq_12.average_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_11.metric_time__day + , AVG(subq_11.average_booking_value) AS average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + SELECT + subq_10.metric_time__day + , subq_10.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__week + , subq_7.ds__month + , subq_7.ds__quarter + , subq_7.ds__year + , subq_7.ds__extract_year + , subq_7.ds__extract_quarter + , subq_7.ds__extract_month + , subq_7.ds__extract_day + , subq_7.ds__extract_dow + , subq_7.ds__extract_doy + , subq_7.ds_partitioned__day + , subq_7.ds_partitioned__week + , subq_7.ds_partitioned__month + , subq_7.ds_partitioned__quarter + , subq_7.ds_partitioned__year + , subq_7.ds_partitioned__extract_year + , subq_7.ds_partitioned__extract_quarter + , subq_7.ds_partitioned__extract_month + , subq_7.ds_partitioned__extract_day + , subq_7.ds_partitioned__extract_dow + , subq_7.ds_partitioned__extract_doy + , subq_7.paid_at__day + , subq_7.paid_at__week + , subq_7.paid_at__month + , subq_7.paid_at__quarter + , subq_7.paid_at__year + , subq_7.paid_at__extract_year + , subq_7.paid_at__extract_quarter + , subq_7.paid_at__extract_month + , subq_7.paid_at__extract_day + , subq_7.paid_at__extract_dow + , subq_7.paid_at__extract_doy + , subq_7.booking__ds__day + , subq_7.booking__ds__week + , subq_7.booking__ds__month + , subq_7.booking__ds__quarter + , subq_7.booking__ds__year + , subq_7.booking__ds__extract_year + , subq_7.booking__ds__extract_quarter + , subq_7.booking__ds__extract_month + , subq_7.booking__ds__extract_day + , subq_7.booking__ds__extract_dow + , subq_7.booking__ds__extract_doy + , subq_7.booking__ds_partitioned__day + , subq_7.booking__ds_partitioned__week + , subq_7.booking__ds_partitioned__month + , subq_7.booking__ds_partitioned__quarter + , subq_7.booking__ds_partitioned__year + , subq_7.booking__ds_partitioned__extract_year + , subq_7.booking__ds_partitioned__extract_quarter + , subq_7.booking__ds_partitioned__extract_month + , subq_7.booking__ds_partitioned__extract_day + , subq_7.booking__ds_partitioned__extract_dow + , subq_7.booking__ds_partitioned__extract_doy + , subq_7.booking__paid_at__day + , subq_7.booking__paid_at__week + , subq_7.booking__paid_at__month + , subq_7.booking__paid_at__quarter + , subq_7.booking__paid_at__year + , subq_7.booking__paid_at__extract_year + , subq_7.booking__paid_at__extract_quarter + , subq_7.booking__paid_at__extract_month + , subq_7.booking__paid_at__extract_day + , subq_7.booking__paid_at__extract_dow + , subq_7.booking__paid_at__extract_doy + , subq_7.metric_time__day + , subq_7.metric_time__week + , subq_7.metric_time__month + , subq_7.metric_time__quarter + , subq_7.metric_time__year + , subq_7.metric_time__extract_year + , subq_7.metric_time__extract_quarter + , subq_7.metric_time__extract_month + , subq_7.metric_time__extract_day + , subq_7.metric_time__extract_dow + , subq_7.metric_time__extract_doy + , subq_7.listing + , subq_7.guest + , subq_7.host + , subq_7.booking__listing + , subq_7.booking__guest + , subq_7.booking__host + , subq_7.is_instant + , subq_7.booking__is_instant + , subq_7.bookings + , subq_7.instant_bookings + , subq_7.booking_value + , subq_7.max_booking_value + , subq_7.min_booking_value + , subq_7.bookers + , subq_7.average_booking_value + , subq_7.referred_bookings + , subq_7.median_booking_value + , subq_7.booking_value_p99 + , subq_7.discrete_booking_value_p99 + , subq_7.approximate_continuous_booking_value_p99 + , subq_7.approximate_discrete_booking_value_p99 + 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.ds_partitioned__day + , subq_6.ds_partitioned__week + , subq_6.ds_partitioned__month + , subq_6.ds_partitioned__quarter + , subq_6.ds_partitioned__year + , subq_6.ds_partitioned__extract_year + , subq_6.ds_partitioned__extract_quarter + , subq_6.ds_partitioned__extract_month + , subq_6.ds_partitioned__extract_day + , subq_6.ds_partitioned__extract_dow + , subq_6.ds_partitioned__extract_doy + , subq_6.paid_at__day + , subq_6.paid_at__week + , subq_6.paid_at__month + , subq_6.paid_at__quarter + , subq_6.paid_at__year + , subq_6.paid_at__extract_year + , subq_6.paid_at__extract_quarter + , subq_6.paid_at__extract_month + , subq_6.paid_at__extract_day + , subq_6.paid_at__extract_dow + , subq_6.paid_at__extract_doy + , subq_6.booking__ds__day + , subq_6.booking__ds__week + , subq_6.booking__ds__month + , subq_6.booking__ds__quarter + , subq_6.booking__ds__year + , subq_6.booking__ds__extract_year + , subq_6.booking__ds__extract_quarter + , subq_6.booking__ds__extract_month + , subq_6.booking__ds__extract_day + , subq_6.booking__ds__extract_dow + , subq_6.booking__ds__extract_doy + , subq_6.booking__ds_partitioned__day + , subq_6.booking__ds_partitioned__week + , subq_6.booking__ds_partitioned__month + , subq_6.booking__ds_partitioned__quarter + , subq_6.booking__ds_partitioned__year + , subq_6.booking__ds_partitioned__extract_year + , subq_6.booking__ds_partitioned__extract_quarter + , subq_6.booking__ds_partitioned__extract_month + , subq_6.booking__ds_partitioned__extract_day + , subq_6.booking__ds_partitioned__extract_dow + , subq_6.booking__ds_partitioned__extract_doy + , subq_6.booking__paid_at__day + , subq_6.booking__paid_at__week + , subq_6.booking__paid_at__month + , subq_6.booking__paid_at__quarter + , subq_6.booking__paid_at__year + , subq_6.booking__paid_at__extract_year + , subq_6.booking__paid_at__extract_quarter + , subq_6.booking__paid_at__extract_month + , subq_6.booking__paid_at__extract_day + , subq_6.booking__paid_at__extract_dow + , subq_6.booking__paid_at__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.listing + , subq_6.guest + , subq_6.host + , subq_6.booking__listing + , subq_6.booking__guest + , subq_6.booking__host + , subq_6.is_instant + , subq_6.booking__is_instant + , subq_6.bookings + , subq_6.instant_bookings + , subq_6.booking_value + , subq_6.max_booking_value + , subq_6.min_booking_value + , subq_6.bookers + , subq_6.average_booking_value + , subq_6.referred_bookings + , subq_6.median_booking_value + , subq_6.booking_value_p99 + , subq_6.discrete_booking_value_p99 + , subq_6.approximate_continuous_booking_value_p99 + , subq_6.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 + WHERE booking__is_instant + ) subq_10 + ) subq_11 + GROUP BY + subq_11.metric_time__day + ) subq_12 + ) subq_13 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_17.metric_time__day + , subq_17.max_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_16.metric_time__day + , MAX(subq_16.max_booking_value) AS max_booking_value + FROM ( + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + SELECT + subq_15.metric_time__day + , subq_15.max_booking_value + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_14.ds__day + , subq_14.ds__week + , subq_14.ds__month + , subq_14.ds__quarter + , subq_14.ds__year + , subq_14.ds__extract_year + , subq_14.ds__extract_quarter + , subq_14.ds__extract_month + , subq_14.ds__extract_day + , subq_14.ds__extract_dow + , subq_14.ds__extract_doy + , subq_14.ds_partitioned__day + , subq_14.ds_partitioned__week + , subq_14.ds_partitioned__month + , subq_14.ds_partitioned__quarter + , subq_14.ds_partitioned__year + , subq_14.ds_partitioned__extract_year + , subq_14.ds_partitioned__extract_quarter + , subq_14.ds_partitioned__extract_month + , subq_14.ds_partitioned__extract_day + , subq_14.ds_partitioned__extract_dow + , subq_14.ds_partitioned__extract_doy + , subq_14.paid_at__day + , subq_14.paid_at__week + , subq_14.paid_at__month + , subq_14.paid_at__quarter + , subq_14.paid_at__year + , subq_14.paid_at__extract_year + , subq_14.paid_at__extract_quarter + , subq_14.paid_at__extract_month + , subq_14.paid_at__extract_day + , subq_14.paid_at__extract_dow + , subq_14.paid_at__extract_doy + , subq_14.booking__ds__day + , subq_14.booking__ds__week + , subq_14.booking__ds__month + , subq_14.booking__ds__quarter + , subq_14.booking__ds__year + , subq_14.booking__ds__extract_year + , subq_14.booking__ds__extract_quarter + , subq_14.booking__ds__extract_month + , subq_14.booking__ds__extract_day + , subq_14.booking__ds__extract_dow + , subq_14.booking__ds__extract_doy + , subq_14.booking__ds_partitioned__day + , subq_14.booking__ds_partitioned__week + , subq_14.booking__ds_partitioned__month + , subq_14.booking__ds_partitioned__quarter + , subq_14.booking__ds_partitioned__year + , subq_14.booking__ds_partitioned__extract_year + , subq_14.booking__ds_partitioned__extract_quarter + , subq_14.booking__ds_partitioned__extract_month + , subq_14.booking__ds_partitioned__extract_day + , subq_14.booking__ds_partitioned__extract_dow + , subq_14.booking__ds_partitioned__extract_doy + , subq_14.booking__paid_at__day + , subq_14.booking__paid_at__week + , subq_14.booking__paid_at__month + , subq_14.booking__paid_at__quarter + , subq_14.booking__paid_at__year + , subq_14.booking__paid_at__extract_year + , subq_14.booking__paid_at__extract_quarter + , subq_14.booking__paid_at__extract_month + , subq_14.booking__paid_at__extract_day + , subq_14.booking__paid_at__extract_dow + , subq_14.booking__paid_at__extract_doy + , subq_14.ds__day AS metric_time__day + , subq_14.ds__week AS metric_time__week + , subq_14.ds__month AS metric_time__month + , subq_14.ds__quarter AS metric_time__quarter + , subq_14.ds__year AS metric_time__year + , subq_14.ds__extract_year AS metric_time__extract_year + , subq_14.ds__extract_quarter AS metric_time__extract_quarter + , subq_14.ds__extract_month AS metric_time__extract_month + , subq_14.ds__extract_day AS metric_time__extract_day + , subq_14.ds__extract_dow AS metric_time__extract_dow + , subq_14.ds__extract_doy AS metric_time__extract_doy + , subq_14.listing + , subq_14.guest + , subq_14.host + , subq_14.booking__listing + , subq_14.booking__guest + , subq_14.booking__host + , subq_14.is_instant + , subq_14.booking__is_instant + , subq_14.bookings + , subq_14.instant_bookings + , subq_14.booking_value + , subq_14.max_booking_value + , subq_14.min_booking_value + , subq_14.bookers + , subq_14.average_booking_value + , subq_14.referred_bookings + , subq_14.median_booking_value + , subq_14.booking_value_p99 + , subq_14.discrete_booking_value_p99 + , subq_14.approximate_continuous_booking_value_p99 + , subq_14.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + GROUP BY + subq_16.metric_time__day + ) subq_17 + ) subq_18 + ON + subq_13.metric_time__day = subq_18.metric_time__day + GROUP BY + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) +) subq_19 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..8fd9bd5080 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,58 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , CAST(average_booking_value AS DOUBLE PRECISION) / CAST(NULLIF(max_booking_value, 0) AS DOUBLE PRECISION) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) AS metric_time__day + , MAX(subq_27.average_booking_value) AS average_booking_value + , MAX(subq_32.max_booking_value) AS max_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , AVG(average_booking_value) AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + metric_time__day + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_21 + WHERE booking__is_instant + ) subq_23 + WHERE booking__is_instant + GROUP BY + metric_time__day + ) subq_27 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , MAX(booking_value) AS max_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_32 + ON + subq_27.metric_time__day = subq_32.metric_time__day + GROUP BY + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) +) subq_33 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_single_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_single_categorical_dimension_pushdown__plan0.sql new file mode 100644 index 0000000000..5ef5778430 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_single_categorical_dimension_pushdown__plan0.sql @@ -0,0 +1,486 @@ +-- Compute Metrics via Expressions +SELECT + subq_17.listing__country_latest + , subq_17.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_16.listing__country_latest + , SUM(subq_16.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest'] + SELECT + subq_15.listing__country_latest + , subq_15.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_14.booking__is_instant + , subq_14.listing__country_latest + , subq_14.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] + SELECT + subq_13.booking__is_instant + , subq_13.listing__country_latest + , subq_13.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_9.listing AS listing + , subq_9.booking__is_instant AS booking__is_instant + , subq_12.country_latest AS listing__country_latest + , subq_9.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_8.listing + , subq_8.booking__is_instant + , subq_8.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__week + , subq_7.ds__month + , subq_7.ds__quarter + , subq_7.ds__year + , subq_7.ds__extract_year + , subq_7.ds__extract_quarter + , subq_7.ds__extract_month + , subq_7.ds__extract_day + , subq_7.ds__extract_dow + , subq_7.ds__extract_doy + , subq_7.ds_partitioned__day + , subq_7.ds_partitioned__week + , subq_7.ds_partitioned__month + , subq_7.ds_partitioned__quarter + , subq_7.ds_partitioned__year + , subq_7.ds_partitioned__extract_year + , subq_7.ds_partitioned__extract_quarter + , subq_7.ds_partitioned__extract_month + , subq_7.ds_partitioned__extract_day + , subq_7.ds_partitioned__extract_dow + , subq_7.ds_partitioned__extract_doy + , subq_7.paid_at__day + , subq_7.paid_at__week + , subq_7.paid_at__month + , subq_7.paid_at__quarter + , subq_7.paid_at__year + , subq_7.paid_at__extract_year + , subq_7.paid_at__extract_quarter + , subq_7.paid_at__extract_month + , subq_7.paid_at__extract_day + , subq_7.paid_at__extract_dow + , subq_7.paid_at__extract_doy + , subq_7.booking__ds__day + , subq_7.booking__ds__week + , subq_7.booking__ds__month + , subq_7.booking__ds__quarter + , subq_7.booking__ds__year + , subq_7.booking__ds__extract_year + , subq_7.booking__ds__extract_quarter + , subq_7.booking__ds__extract_month + , subq_7.booking__ds__extract_day + , subq_7.booking__ds__extract_dow + , subq_7.booking__ds__extract_doy + , subq_7.booking__ds_partitioned__day + , subq_7.booking__ds_partitioned__week + , subq_7.booking__ds_partitioned__month + , subq_7.booking__ds_partitioned__quarter + , subq_7.booking__ds_partitioned__year + , subq_7.booking__ds_partitioned__extract_year + , subq_7.booking__ds_partitioned__extract_quarter + , subq_7.booking__ds_partitioned__extract_month + , subq_7.booking__ds_partitioned__extract_day + , subq_7.booking__ds_partitioned__extract_dow + , subq_7.booking__ds_partitioned__extract_doy + , subq_7.booking__paid_at__day + , subq_7.booking__paid_at__week + , subq_7.booking__paid_at__month + , subq_7.booking__paid_at__quarter + , subq_7.booking__paid_at__year + , subq_7.booking__paid_at__extract_year + , subq_7.booking__paid_at__extract_quarter + , subq_7.booking__paid_at__extract_month + , subq_7.booking__paid_at__extract_day + , subq_7.booking__paid_at__extract_dow + , subq_7.booking__paid_at__extract_doy + , subq_7.metric_time__day + , subq_7.metric_time__week + , subq_7.metric_time__month + , subq_7.metric_time__quarter + , subq_7.metric_time__year + , subq_7.metric_time__extract_year + , subq_7.metric_time__extract_quarter + , subq_7.metric_time__extract_month + , subq_7.metric_time__extract_day + , subq_7.metric_time__extract_dow + , subq_7.metric_time__extract_doy + , subq_7.listing + , subq_7.guest + , subq_7.host + , subq_7.booking__listing + , subq_7.booking__guest + , subq_7.booking__host + , subq_7.is_instant + , subq_7.booking__is_instant + , subq_7.bookings + , subq_7.instant_bookings + , subq_7.booking_value + , subq_7.max_booking_value + , subq_7.min_booking_value + , subq_7.bookers + , subq_7.average_booking_value + , subq_7.referred_bookings + , subq_7.median_booking_value + , subq_7.booking_value_p99 + , subq_7.discrete_booking_value_p99 + , subq_7.approximate_continuous_booking_value_p99 + , subq_7.approximate_discrete_booking_value_p99 + 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.ds_partitioned__day + , subq_6.ds_partitioned__week + , subq_6.ds_partitioned__month + , subq_6.ds_partitioned__quarter + , subq_6.ds_partitioned__year + , subq_6.ds_partitioned__extract_year + , subq_6.ds_partitioned__extract_quarter + , subq_6.ds_partitioned__extract_month + , subq_6.ds_partitioned__extract_day + , subq_6.ds_partitioned__extract_dow + , subq_6.ds_partitioned__extract_doy + , subq_6.paid_at__day + , subq_6.paid_at__week + , subq_6.paid_at__month + , subq_6.paid_at__quarter + , subq_6.paid_at__year + , subq_6.paid_at__extract_year + , subq_6.paid_at__extract_quarter + , subq_6.paid_at__extract_month + , subq_6.paid_at__extract_day + , subq_6.paid_at__extract_dow + , subq_6.paid_at__extract_doy + , subq_6.booking__ds__day + , subq_6.booking__ds__week + , subq_6.booking__ds__month + , subq_6.booking__ds__quarter + , subq_6.booking__ds__year + , subq_6.booking__ds__extract_year + , subq_6.booking__ds__extract_quarter + , subq_6.booking__ds__extract_month + , subq_6.booking__ds__extract_day + , subq_6.booking__ds__extract_dow + , subq_6.booking__ds__extract_doy + , subq_6.booking__ds_partitioned__day + , subq_6.booking__ds_partitioned__week + , subq_6.booking__ds_partitioned__month + , subq_6.booking__ds_partitioned__quarter + , subq_6.booking__ds_partitioned__year + , subq_6.booking__ds_partitioned__extract_year + , subq_6.booking__ds_partitioned__extract_quarter + , subq_6.booking__ds_partitioned__extract_month + , subq_6.booking__ds_partitioned__extract_day + , subq_6.booking__ds_partitioned__extract_dow + , subq_6.booking__ds_partitioned__extract_doy + , subq_6.booking__paid_at__day + , subq_6.booking__paid_at__week + , subq_6.booking__paid_at__month + , subq_6.booking__paid_at__quarter + , subq_6.booking__paid_at__year + , subq_6.booking__paid_at__extract_year + , subq_6.booking__paid_at__extract_quarter + , subq_6.booking__paid_at__extract_month + , subq_6.booking__paid_at__extract_day + , subq_6.booking__paid_at__extract_dow + , subq_6.booking__paid_at__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.listing + , subq_6.guest + , subq_6.host + , subq_6.booking__listing + , subq_6.booking__guest + , subq_6.booking__host + , subq_6.is_instant + , subq_6.booking__is_instant + , subq_6.bookings + , subq_6.instant_bookings + , subq_6.booking_value + , subq_6.max_booking_value + , subq_6.min_booking_value + , subq_6.bookers + , subq_6.average_booking_value + , subq_6.referred_bookings + , subq_6.median_booking_value + , subq_6.booking_value_p99 + , subq_6.discrete_booking_value_p99 + , subq_6.approximate_continuous_booking_value_p99 + , subq_6.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['country_latest', 'listing'] + SELECT + subq_11.listing + , subq_11.country_latest + FROM ( + -- Metric Time Dimension 'ds' + 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.created_at__day + , subq_10.created_at__week + , subq_10.created_at__month + , subq_10.created_at__quarter + , subq_10.created_at__year + , subq_10.created_at__extract_year + , subq_10.created_at__extract_quarter + , subq_10.created_at__extract_month + , subq_10.created_at__extract_day + , subq_10.created_at__extract_dow + , subq_10.created_at__extract_doy + , subq_10.listing__ds__day + , subq_10.listing__ds__week + , subq_10.listing__ds__month + , subq_10.listing__ds__quarter + , subq_10.listing__ds__year + , subq_10.listing__ds__extract_year + , subq_10.listing__ds__extract_quarter + , subq_10.listing__ds__extract_month + , subq_10.listing__ds__extract_day + , subq_10.listing__ds__extract_dow + , subq_10.listing__ds__extract_doy + , subq_10.listing__created_at__day + , subq_10.listing__created_at__week + , subq_10.listing__created_at__month + , subq_10.listing__created_at__quarter + , subq_10.listing__created_at__year + , subq_10.listing__created_at__extract_year + , subq_10.listing__created_at__extract_quarter + , subq_10.listing__created_at__extract_month + , subq_10.listing__created_at__extract_day + , subq_10.listing__created_at__extract_dow + , subq_10.listing__created_at__extract_doy + , subq_10.ds__day AS metric_time__day + , subq_10.ds__week AS metric_time__week + , subq_10.ds__month AS metric_time__month + , subq_10.ds__quarter AS metric_time__quarter + , subq_10.ds__year AS metric_time__year + , subq_10.ds__extract_year AS metric_time__extract_year + , subq_10.ds__extract_quarter AS metric_time__extract_quarter + , subq_10.ds__extract_month AS metric_time__extract_month + , subq_10.ds__extract_day AS metric_time__extract_day + , subq_10.ds__extract_dow AS metric_time__extract_dow + , subq_10.ds__extract_doy AS metric_time__extract_doy + , subq_10.listing + , subq_10.user + , subq_10.listing__user + , subq_10.country_latest + , subq_10.is_lux_latest + , subq_10.capacity_latest + , subq_10.listing__country_latest + , subq_10.listing__is_lux_latest + , subq_10.listing__capacity_latest + , subq_10.listings + , subq_10.largest_listing + , subq_10.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_10 + ) subq_11 + ) subq_12 + ON + subq_9.listing = subq_12.listing + ) subq_13 + ) subq_14 + WHERE booking__is_instant + ) subq_15 + ) subq_16 + GROUP BY + subq_16.listing__country_latest +) subq_17 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_single_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_single_categorical_dimension_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..b0a46663de --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_single_categorical_dimension_pushdown__plan0_optimized.sql @@ -0,0 +1,40 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'listing__country_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] + SELECT + subq_21.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.country AS listing__country_latest + , subq_21.bookings AS bookings + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_19 + WHERE booking__is_instant + ) subq_21 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_21.listing = listings_latest_src_28000.listing_id +) subq_26 +WHERE booking__is_instant +GROUP BY + listing__country_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_skipped_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_skipped_pushdown__plan0.sql new file mode 100644 index 0000000000..a62b838b8c --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_skipped_pushdown__plan0.sql @@ -0,0 +1,387 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.listing__country_latest + , subq_10.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_9.listing__country_latest + , SUM(subq_9.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest'] + SELECT + subq_8.listing__country_latest + , subq_8.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.booking__is_instant + , subq_7.listing__country_latest + , subq_7.listing__is_lux_latest + , subq_7.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] + SELECT + subq_6.booking__is_instant + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_2.listing AS listing + , subq_2.booking__is_instant AS booking__is_instant + , subq_5.country_latest AS listing__country_latest + , subq_5.is_lux_latest AS listing__is_lux_latest + , subq_2.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_1.listing + , subq_1.booking__is_instant + , subq_1.bookings + 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.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.booking__paid_at__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.listing + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['country_latest', 'is_lux_latest', 'listing', 'listing'] + SELECT + subq_4.listing + , subq_4.country_latest + , subq_4.is_lux_latest + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.ds__day AS metric_time__day + , subq_3.ds__week AS metric_time__week + , subq_3.ds__month AS metric_time__month + , subq_3.ds__quarter AS metric_time__quarter + , subq_3.ds__year AS metric_time__year + , subq_3.ds__extract_year AS metric_time__extract_year + , subq_3.ds__extract_quarter AS metric_time__extract_quarter + , subq_3.ds__extract_month AS metric_time__extract_month + , subq_3.ds__extract_day AS metric_time__extract_day + , subq_3.ds__extract_dow AS metric_time__extract_dow + , subq_3.ds__extract_doy AS metric_time__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_3 + ) subq_4 + ) subq_5 + ON + subq_2.listing = subq_5.listing + ) subq_6 + ) subq_7 + WHERE booking__is_instant OR listing__is_lux_latest + ) subq_8 + ) subq_9 + GROUP BY + subq_9.listing__country_latest +) subq_10 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_skipped_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_skipped_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..be31b01767 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_skipped_pushdown__plan0_optimized.sql @@ -0,0 +1,33 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'listing__country_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] + SELECT + subq_13.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , subq_13.bookings AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_13.listing = listings_latest_src_28000.listing_id +) subq_18 +WHERE booking__is_instant OR listing__is_lux_latest +GROUP BY + listing__country_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_categorical_dimension_pushdown__plan0.sql new file mode 100644 index 0000000000..824975c8c3 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_categorical_dimension_pushdown__plan0.sql @@ -0,0 +1,387 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.booking__is_instant + , subq_10.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_9.booking__is_instant + , SUM(subq_9.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant'] + SELECT + subq_8.booking__is_instant + , subq_8.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.booking__is_instant + , subq_7.listing__is_lux_latest + , subq_7.listing__capacity_latest + , subq_7.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing__is_lux_latest', 'listing__capacity_latest'] + SELECT + subq_6.booking__is_instant + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_2.listing AS listing + , subq_2.booking__is_instant AS booking__is_instant + , subq_5.is_lux_latest AS listing__is_lux_latest + , subq_5.capacity_latest AS listing__capacity_latest + , subq_2.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_1.listing + , subq_1.booking__is_instant + , subq_1.bookings + 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.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.booking__paid_at__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.listing + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['is_lux_latest', 'capacity_latest', 'listing', 'listing'] + SELECT + subq_4.listing + , subq_4.is_lux_latest + , subq_4.capacity_latest + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.ds__day AS metric_time__day + , subq_3.ds__week AS metric_time__week + , subq_3.ds__month AS metric_time__month + , subq_3.ds__quarter AS metric_time__quarter + , subq_3.ds__year AS metric_time__year + , subq_3.ds__extract_year AS metric_time__extract_year + , subq_3.ds__extract_quarter AS metric_time__extract_quarter + , subq_3.ds__extract_month AS metric_time__extract_month + , subq_3.ds__extract_day AS metric_time__extract_day + , subq_3.ds__extract_dow AS metric_time__extract_dow + , subq_3.ds__extract_doy AS metric_time__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_3 + ) subq_4 + ) subq_5 + ON + subq_2.listing = subq_5.listing + ) subq_6 + ) subq_7 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_8 + ) subq_9 + GROUP BY + subq_9.booking__is_instant +) subq_10 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..98cc26bb70 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql @@ -0,0 +1,33 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'booking__is_instant'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + booking__is_instant + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing__is_lux_latest', 'listing__capacity_latest'] + SELECT + subq_13.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , subq_13.bookings AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_13.listing = listings_latest_src_28000.listing_id +) subq_18 +WHERE listing__is_lux_latest OR listing__capacity_latest > 4 +GROUP BY + booking__is_instant diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..d04c175116 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql @@ -0,0 +1,651 @@ +-- Compute Metrics via Expressions +SELECT + CAST(subq_28.west_coast_balance_first_day AS DOUBLE PRECISION) / CAST(NULLIF(subq_28.east_coast_balance_first_dat, 0) AS DOUBLE PRECISION) AS regional_starting_balance_ratios +FROM ( + -- Combine Aggregated Outputs + SELECT + MAX(subq_13.west_coast_balance_first_day) AS west_coast_balance_first_day + , MAX(subq_27.east_coast_balance_first_dat) AS east_coast_balance_first_dat + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_12.total_account_balance_first_day AS west_coast_balance_first_day + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_11.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_10.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_7.ds__day AS ds__day + , subq_7.user__home_state_latest AS user__home_state_latest + , subq_7.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + 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.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__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.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM accounts_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM accounts_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM accounts_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , CASE WHEN EXTRACT(dow FROM accounts_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM accounts_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM accounts_source_src_28000.ds) END AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_7 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_8.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + 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.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__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.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM accounts_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM accounts_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM accounts_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , CASE WHEN EXTRACT(dow FROM accounts_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM accounts_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM accounts_source_src_28000.ds) END AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_8 + ) subq_9 + ON + subq_7.ds__day = subq_9.ds__day__complete + ) subq_10 + ) subq_11 + ) subq_12 + ) subq_13 + CROSS JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_26.total_account_balance_first_day AS east_coast_balance_first_dat + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_25.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_24.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_21.ds__day AS ds__day + , subq_21.user__home_state_latest AS user__home_state_latest + , subq_21.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_14.ds__day + , subq_14.ds__week + , subq_14.ds__month + , subq_14.ds__quarter + , subq_14.ds__year + , subq_14.ds__extract_year + , subq_14.ds__extract_quarter + , subq_14.ds__extract_month + , subq_14.ds__extract_day + , subq_14.ds__extract_dow + , subq_14.ds__extract_doy + , subq_14.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__extract_doy + , subq_14.ds__day AS metric_time__day + , subq_14.ds__week AS metric_time__week + , subq_14.ds__month AS metric_time__month + , subq_14.ds__quarter AS metric_time__quarter + , subq_14.ds__year AS metric_time__year + , subq_14.ds__extract_year AS metric_time__extract_year + , subq_14.ds__extract_quarter AS metric_time__extract_quarter + , subq_14.ds__extract_month AS metric_time__extract_month + , subq_14.ds__extract_day AS metric_time__extract_day + , subq_14.ds__extract_dow AS metric_time__extract_dow + , subq_14.ds__extract_doy AS metric_time__extract_doy + , subq_14.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM accounts_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM accounts_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM accounts_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , CASE WHEN EXTRACT(dow FROM accounts_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM accounts_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM accounts_source_src_28000.ds) END AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_21 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_22.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_14.ds__day + , subq_14.ds__week + , subq_14.ds__month + , subq_14.ds__quarter + , subq_14.ds__year + , subq_14.ds__extract_year + , subq_14.ds__extract_quarter + , subq_14.ds__extract_month + , subq_14.ds__extract_day + , subq_14.ds__extract_dow + , subq_14.ds__extract_doy + , subq_14.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__extract_doy + , subq_14.ds__day AS metric_time__day + , subq_14.ds__week AS metric_time__week + , subq_14.ds__month AS metric_time__month + , subq_14.ds__quarter AS metric_time__quarter + , subq_14.ds__year AS metric_time__year + , subq_14.ds__extract_year AS metric_time__extract_year + , subq_14.ds__extract_quarter AS metric_time__extract_quarter + , subq_14.ds__extract_month AS metric_time__extract_month + , subq_14.ds__extract_day AS metric_time__extract_day + , subq_14.ds__extract_dow AS metric_time__extract_dow + , subq_14.ds__extract_doy AS metric_time__extract_doy + , subq_14.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM accounts_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM accounts_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM accounts_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , CASE WHEN EXTRACT(dow FROM accounts_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM accounts_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM accounts_source_src_28000.ds) END AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_22 + ) subq_23 + ON + subq_21.ds__day = subq_23.ds__day__complete + ) subq_24 + ) subq_25 + ) subq_26 + ) subq_27 +) subq_28 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..80c554f04a --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,102 @@ +-- Combine Aggregated Outputs +-- Compute Metrics via Expressions +SELECT + CAST(MAX(subq_42.west_coast_balance_first_day) AS DOUBLE PRECISION) / CAST(NULLIF(MAX(subq_56.east_coast_balance_first_dat), 0) AS DOUBLE PRECISION) AS regional_starting_balance_ratios +FROM ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_36.total_account_balance_first_day) AS west_coast_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_36 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_38 + ON + subq_36.ds__day = subq_38.ds__day__complete +) subq_42 +CROSS JOIN ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_50.total_account_balance_first_day) AS east_coast_balance_first_dat + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_50 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_52 + ON + subq_50.ds__day = subq_52.ds__day__complete +) subq_56 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..447784aa01 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql @@ -0,0 +1,563 @@ +-- Compute Metrics via Expressions +SELECT + subq_19.metric_time__day + , CAST(subq_19.average_booking_value AS DOUBLE PRECISION) / CAST(NULLIF(subq_19.max_booking_value, 0) AS DOUBLE PRECISION) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) AS metric_time__day + , MAX(subq_13.average_booking_value) AS average_booking_value + , MAX(subq_18.max_booking_value) AS max_booking_value + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_12.metric_time__day + , subq_12.average_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_11.metric_time__day + , AVG(subq_11.average_booking_value) AS average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + SELECT + subq_10.metric_time__day + , subq_10.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__week + , subq_7.ds__month + , subq_7.ds__quarter + , subq_7.ds__year + , subq_7.ds__extract_year + , subq_7.ds__extract_quarter + , subq_7.ds__extract_month + , subq_7.ds__extract_day + , subq_7.ds__extract_dow + , subq_7.ds__extract_doy + , subq_7.ds_partitioned__day + , subq_7.ds_partitioned__week + , subq_7.ds_partitioned__month + , subq_7.ds_partitioned__quarter + , subq_7.ds_partitioned__year + , subq_7.ds_partitioned__extract_year + , subq_7.ds_partitioned__extract_quarter + , subq_7.ds_partitioned__extract_month + , subq_7.ds_partitioned__extract_day + , subq_7.ds_partitioned__extract_dow + , subq_7.ds_partitioned__extract_doy + , subq_7.paid_at__day + , subq_7.paid_at__week + , subq_7.paid_at__month + , subq_7.paid_at__quarter + , subq_7.paid_at__year + , subq_7.paid_at__extract_year + , subq_7.paid_at__extract_quarter + , subq_7.paid_at__extract_month + , subq_7.paid_at__extract_day + , subq_7.paid_at__extract_dow + , subq_7.paid_at__extract_doy + , subq_7.booking__ds__day + , subq_7.booking__ds__week + , subq_7.booking__ds__month + , subq_7.booking__ds__quarter + , subq_7.booking__ds__year + , subq_7.booking__ds__extract_year + , subq_7.booking__ds__extract_quarter + , subq_7.booking__ds__extract_month + , subq_7.booking__ds__extract_day + , subq_7.booking__ds__extract_dow + , subq_7.booking__ds__extract_doy + , subq_7.booking__ds_partitioned__day + , subq_7.booking__ds_partitioned__week + , subq_7.booking__ds_partitioned__month + , subq_7.booking__ds_partitioned__quarter + , subq_7.booking__ds_partitioned__year + , subq_7.booking__ds_partitioned__extract_year + , subq_7.booking__ds_partitioned__extract_quarter + , subq_7.booking__ds_partitioned__extract_month + , subq_7.booking__ds_partitioned__extract_day + , subq_7.booking__ds_partitioned__extract_dow + , subq_7.booking__ds_partitioned__extract_doy + , subq_7.booking__paid_at__day + , subq_7.booking__paid_at__week + , subq_7.booking__paid_at__month + , subq_7.booking__paid_at__quarter + , subq_7.booking__paid_at__year + , subq_7.booking__paid_at__extract_year + , subq_7.booking__paid_at__extract_quarter + , subq_7.booking__paid_at__extract_month + , subq_7.booking__paid_at__extract_day + , subq_7.booking__paid_at__extract_dow + , subq_7.booking__paid_at__extract_doy + , subq_7.metric_time__day + , subq_7.metric_time__week + , subq_7.metric_time__month + , subq_7.metric_time__quarter + , subq_7.metric_time__year + , subq_7.metric_time__extract_year + , subq_7.metric_time__extract_quarter + , subq_7.metric_time__extract_month + , subq_7.metric_time__extract_day + , subq_7.metric_time__extract_dow + , subq_7.metric_time__extract_doy + , subq_7.listing + , subq_7.guest + , subq_7.host + , subq_7.booking__listing + , subq_7.booking__guest + , subq_7.booking__host + , subq_7.is_instant + , subq_7.booking__is_instant + , subq_7.bookings + , subq_7.instant_bookings + , subq_7.booking_value + , subq_7.max_booking_value + , subq_7.min_booking_value + , subq_7.bookers + , subq_7.average_booking_value + , subq_7.referred_bookings + , subq_7.median_booking_value + , subq_7.booking_value_p99 + , subq_7.discrete_booking_value_p99 + , subq_7.approximate_continuous_booking_value_p99 + , subq_7.approximate_discrete_booking_value_p99 + 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.ds_partitioned__day + , subq_6.ds_partitioned__week + , subq_6.ds_partitioned__month + , subq_6.ds_partitioned__quarter + , subq_6.ds_partitioned__year + , subq_6.ds_partitioned__extract_year + , subq_6.ds_partitioned__extract_quarter + , subq_6.ds_partitioned__extract_month + , subq_6.ds_partitioned__extract_day + , subq_6.ds_partitioned__extract_dow + , subq_6.ds_partitioned__extract_doy + , subq_6.paid_at__day + , subq_6.paid_at__week + , subq_6.paid_at__month + , subq_6.paid_at__quarter + , subq_6.paid_at__year + , subq_6.paid_at__extract_year + , subq_6.paid_at__extract_quarter + , subq_6.paid_at__extract_month + , subq_6.paid_at__extract_day + , subq_6.paid_at__extract_dow + , subq_6.paid_at__extract_doy + , subq_6.booking__ds__day + , subq_6.booking__ds__week + , subq_6.booking__ds__month + , subq_6.booking__ds__quarter + , subq_6.booking__ds__year + , subq_6.booking__ds__extract_year + , subq_6.booking__ds__extract_quarter + , subq_6.booking__ds__extract_month + , subq_6.booking__ds__extract_day + , subq_6.booking__ds__extract_dow + , subq_6.booking__ds__extract_doy + , subq_6.booking__ds_partitioned__day + , subq_6.booking__ds_partitioned__week + , subq_6.booking__ds_partitioned__month + , subq_6.booking__ds_partitioned__quarter + , subq_6.booking__ds_partitioned__year + , subq_6.booking__ds_partitioned__extract_year + , subq_6.booking__ds_partitioned__extract_quarter + , subq_6.booking__ds_partitioned__extract_month + , subq_6.booking__ds_partitioned__extract_day + , subq_6.booking__ds_partitioned__extract_dow + , subq_6.booking__ds_partitioned__extract_doy + , subq_6.booking__paid_at__day + , subq_6.booking__paid_at__week + , subq_6.booking__paid_at__month + , subq_6.booking__paid_at__quarter + , subq_6.booking__paid_at__year + , subq_6.booking__paid_at__extract_year + , subq_6.booking__paid_at__extract_quarter + , subq_6.booking__paid_at__extract_month + , subq_6.booking__paid_at__extract_day + , subq_6.booking__paid_at__extract_dow + , subq_6.booking__paid_at__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.listing + , subq_6.guest + , subq_6.host + , subq_6.booking__listing + , subq_6.booking__guest + , subq_6.booking__host + , subq_6.is_instant + , subq_6.booking__is_instant + , subq_6.bookings + , subq_6.instant_bookings + , subq_6.booking_value + , subq_6.max_booking_value + , subq_6.min_booking_value + , subq_6.bookers + , subq_6.average_booking_value + , subq_6.referred_bookings + , subq_6.median_booking_value + , subq_6.booking_value_p99 + , subq_6.discrete_booking_value_p99 + , subq_6.approximate_continuous_booking_value_p99 + , subq_6.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 + WHERE booking__is_instant + ) subq_10 + ) subq_11 + GROUP BY + subq_11.metric_time__day + ) subq_12 + ) subq_13 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_17.metric_time__day + , subq_17.max_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_16.metric_time__day + , MAX(subq_16.max_booking_value) AS max_booking_value + FROM ( + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + SELECT + subq_15.metric_time__day + , subq_15.max_booking_value + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_14.ds__day + , subq_14.ds__week + , subq_14.ds__month + , subq_14.ds__quarter + , subq_14.ds__year + , subq_14.ds__extract_year + , subq_14.ds__extract_quarter + , subq_14.ds__extract_month + , subq_14.ds__extract_day + , subq_14.ds__extract_dow + , subq_14.ds__extract_doy + , subq_14.ds_partitioned__day + , subq_14.ds_partitioned__week + , subq_14.ds_partitioned__month + , subq_14.ds_partitioned__quarter + , subq_14.ds_partitioned__year + , subq_14.ds_partitioned__extract_year + , subq_14.ds_partitioned__extract_quarter + , subq_14.ds_partitioned__extract_month + , subq_14.ds_partitioned__extract_day + , subq_14.ds_partitioned__extract_dow + , subq_14.ds_partitioned__extract_doy + , subq_14.paid_at__day + , subq_14.paid_at__week + , subq_14.paid_at__month + , subq_14.paid_at__quarter + , subq_14.paid_at__year + , subq_14.paid_at__extract_year + , subq_14.paid_at__extract_quarter + , subq_14.paid_at__extract_month + , subq_14.paid_at__extract_day + , subq_14.paid_at__extract_dow + , subq_14.paid_at__extract_doy + , subq_14.booking__ds__day + , subq_14.booking__ds__week + , subq_14.booking__ds__month + , subq_14.booking__ds__quarter + , subq_14.booking__ds__year + , subq_14.booking__ds__extract_year + , subq_14.booking__ds__extract_quarter + , subq_14.booking__ds__extract_month + , subq_14.booking__ds__extract_day + , subq_14.booking__ds__extract_dow + , subq_14.booking__ds__extract_doy + , subq_14.booking__ds_partitioned__day + , subq_14.booking__ds_partitioned__week + , subq_14.booking__ds_partitioned__month + , subq_14.booking__ds_partitioned__quarter + , subq_14.booking__ds_partitioned__year + , subq_14.booking__ds_partitioned__extract_year + , subq_14.booking__ds_partitioned__extract_quarter + , subq_14.booking__ds_partitioned__extract_month + , subq_14.booking__ds_partitioned__extract_day + , subq_14.booking__ds_partitioned__extract_dow + , subq_14.booking__ds_partitioned__extract_doy + , subq_14.booking__paid_at__day + , subq_14.booking__paid_at__week + , subq_14.booking__paid_at__month + , subq_14.booking__paid_at__quarter + , subq_14.booking__paid_at__year + , subq_14.booking__paid_at__extract_year + , subq_14.booking__paid_at__extract_quarter + , subq_14.booking__paid_at__extract_month + , subq_14.booking__paid_at__extract_day + , subq_14.booking__paid_at__extract_dow + , subq_14.booking__paid_at__extract_doy + , subq_14.ds__day AS metric_time__day + , subq_14.ds__week AS metric_time__week + , subq_14.ds__month AS metric_time__month + , subq_14.ds__quarter AS metric_time__quarter + , subq_14.ds__year AS metric_time__year + , subq_14.ds__extract_year AS metric_time__extract_year + , subq_14.ds__extract_quarter AS metric_time__extract_quarter + , subq_14.ds__extract_month AS metric_time__extract_month + , subq_14.ds__extract_day AS metric_time__extract_day + , subq_14.ds__extract_dow AS metric_time__extract_dow + , subq_14.ds__extract_doy AS metric_time__extract_doy + , subq_14.listing + , subq_14.guest + , subq_14.host + , subq_14.booking__listing + , subq_14.booking__guest + , subq_14.booking__host + , subq_14.is_instant + , subq_14.booking__is_instant + , subq_14.bookings + , subq_14.instant_bookings + , subq_14.booking_value + , subq_14.max_booking_value + , subq_14.min_booking_value + , subq_14.bookers + , subq_14.average_booking_value + , subq_14.referred_bookings + , subq_14.median_booking_value + , subq_14.booking_value_p99 + , subq_14.discrete_booking_value_p99 + , subq_14.approximate_continuous_booking_value_p99 + , subq_14.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + GROUP BY + subq_16.metric_time__day + ) subq_17 + ) subq_18 + ON + subq_13.metric_time__day = subq_18.metric_time__day + GROUP BY + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) +) subq_19 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..8fd9bd5080 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,58 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , CAST(average_booking_value AS DOUBLE PRECISION) / CAST(NULLIF(max_booking_value, 0) AS DOUBLE PRECISION) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) AS metric_time__day + , MAX(subq_27.average_booking_value) AS average_booking_value + , MAX(subq_32.max_booking_value) AS max_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , AVG(average_booking_value) AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + metric_time__day + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_21 + WHERE booking__is_instant + ) subq_23 + WHERE booking__is_instant + GROUP BY + metric_time__day + ) subq_27 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , MAX(booking_value) AS max_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_32 + ON + subq_27.metric_time__day = subq_32.metric_time__day + GROUP BY + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) +) subq_33 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_single_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_single_categorical_dimension_pushdown__plan0.sql new file mode 100644 index 0000000000..3a611771e1 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_single_categorical_dimension_pushdown__plan0.sql @@ -0,0 +1,486 @@ +-- Compute Metrics via Expressions +SELECT + subq_17.listing__country_latest + , subq_17.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_16.listing__country_latest + , SUM(subq_16.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest'] + SELECT + subq_15.listing__country_latest + , subq_15.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_14.booking__is_instant + , subq_14.listing__country_latest + , subq_14.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] + SELECT + subq_13.booking__is_instant + , subq_13.listing__country_latest + , subq_13.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_9.listing AS listing + , subq_9.booking__is_instant AS booking__is_instant + , subq_12.country_latest AS listing__country_latest + , subq_9.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_8.listing + , subq_8.booking__is_instant + , subq_8.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__week + , subq_7.ds__month + , subq_7.ds__quarter + , subq_7.ds__year + , subq_7.ds__extract_year + , subq_7.ds__extract_quarter + , subq_7.ds__extract_month + , subq_7.ds__extract_day + , subq_7.ds__extract_dow + , subq_7.ds__extract_doy + , subq_7.ds_partitioned__day + , subq_7.ds_partitioned__week + , subq_7.ds_partitioned__month + , subq_7.ds_partitioned__quarter + , subq_7.ds_partitioned__year + , subq_7.ds_partitioned__extract_year + , subq_7.ds_partitioned__extract_quarter + , subq_7.ds_partitioned__extract_month + , subq_7.ds_partitioned__extract_day + , subq_7.ds_partitioned__extract_dow + , subq_7.ds_partitioned__extract_doy + , subq_7.paid_at__day + , subq_7.paid_at__week + , subq_7.paid_at__month + , subq_7.paid_at__quarter + , subq_7.paid_at__year + , subq_7.paid_at__extract_year + , subq_7.paid_at__extract_quarter + , subq_7.paid_at__extract_month + , subq_7.paid_at__extract_day + , subq_7.paid_at__extract_dow + , subq_7.paid_at__extract_doy + , subq_7.booking__ds__day + , subq_7.booking__ds__week + , subq_7.booking__ds__month + , subq_7.booking__ds__quarter + , subq_7.booking__ds__year + , subq_7.booking__ds__extract_year + , subq_7.booking__ds__extract_quarter + , subq_7.booking__ds__extract_month + , subq_7.booking__ds__extract_day + , subq_7.booking__ds__extract_dow + , subq_7.booking__ds__extract_doy + , subq_7.booking__ds_partitioned__day + , subq_7.booking__ds_partitioned__week + , subq_7.booking__ds_partitioned__month + , subq_7.booking__ds_partitioned__quarter + , subq_7.booking__ds_partitioned__year + , subq_7.booking__ds_partitioned__extract_year + , subq_7.booking__ds_partitioned__extract_quarter + , subq_7.booking__ds_partitioned__extract_month + , subq_7.booking__ds_partitioned__extract_day + , subq_7.booking__ds_partitioned__extract_dow + , subq_7.booking__ds_partitioned__extract_doy + , subq_7.booking__paid_at__day + , subq_7.booking__paid_at__week + , subq_7.booking__paid_at__month + , subq_7.booking__paid_at__quarter + , subq_7.booking__paid_at__year + , subq_7.booking__paid_at__extract_year + , subq_7.booking__paid_at__extract_quarter + , subq_7.booking__paid_at__extract_month + , subq_7.booking__paid_at__extract_day + , subq_7.booking__paid_at__extract_dow + , subq_7.booking__paid_at__extract_doy + , subq_7.metric_time__day + , subq_7.metric_time__week + , subq_7.metric_time__month + , subq_7.metric_time__quarter + , subq_7.metric_time__year + , subq_7.metric_time__extract_year + , subq_7.metric_time__extract_quarter + , subq_7.metric_time__extract_month + , subq_7.metric_time__extract_day + , subq_7.metric_time__extract_dow + , subq_7.metric_time__extract_doy + , subq_7.listing + , subq_7.guest + , subq_7.host + , subq_7.booking__listing + , subq_7.booking__guest + , subq_7.booking__host + , subq_7.is_instant + , subq_7.booking__is_instant + , subq_7.bookings + , subq_7.instant_bookings + , subq_7.booking_value + , subq_7.max_booking_value + , subq_7.min_booking_value + , subq_7.bookers + , subq_7.average_booking_value + , subq_7.referred_bookings + , subq_7.median_booking_value + , subq_7.booking_value_p99 + , subq_7.discrete_booking_value_p99 + , subq_7.approximate_continuous_booking_value_p99 + , subq_7.approximate_discrete_booking_value_p99 + 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.ds_partitioned__day + , subq_6.ds_partitioned__week + , subq_6.ds_partitioned__month + , subq_6.ds_partitioned__quarter + , subq_6.ds_partitioned__year + , subq_6.ds_partitioned__extract_year + , subq_6.ds_partitioned__extract_quarter + , subq_6.ds_partitioned__extract_month + , subq_6.ds_partitioned__extract_day + , subq_6.ds_partitioned__extract_dow + , subq_6.ds_partitioned__extract_doy + , subq_6.paid_at__day + , subq_6.paid_at__week + , subq_6.paid_at__month + , subq_6.paid_at__quarter + , subq_6.paid_at__year + , subq_6.paid_at__extract_year + , subq_6.paid_at__extract_quarter + , subq_6.paid_at__extract_month + , subq_6.paid_at__extract_day + , subq_6.paid_at__extract_dow + , subq_6.paid_at__extract_doy + , subq_6.booking__ds__day + , subq_6.booking__ds__week + , subq_6.booking__ds__month + , subq_6.booking__ds__quarter + , subq_6.booking__ds__year + , subq_6.booking__ds__extract_year + , subq_6.booking__ds__extract_quarter + , subq_6.booking__ds__extract_month + , subq_6.booking__ds__extract_day + , subq_6.booking__ds__extract_dow + , subq_6.booking__ds__extract_doy + , subq_6.booking__ds_partitioned__day + , subq_6.booking__ds_partitioned__week + , subq_6.booking__ds_partitioned__month + , subq_6.booking__ds_partitioned__quarter + , subq_6.booking__ds_partitioned__year + , subq_6.booking__ds_partitioned__extract_year + , subq_6.booking__ds_partitioned__extract_quarter + , subq_6.booking__ds_partitioned__extract_month + , subq_6.booking__ds_partitioned__extract_day + , subq_6.booking__ds_partitioned__extract_dow + , subq_6.booking__ds_partitioned__extract_doy + , subq_6.booking__paid_at__day + , subq_6.booking__paid_at__week + , subq_6.booking__paid_at__month + , subq_6.booking__paid_at__quarter + , subq_6.booking__paid_at__year + , subq_6.booking__paid_at__extract_year + , subq_6.booking__paid_at__extract_quarter + , subq_6.booking__paid_at__extract_month + , subq_6.booking__paid_at__extract_day + , subq_6.booking__paid_at__extract_dow + , subq_6.booking__paid_at__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.listing + , subq_6.guest + , subq_6.host + , subq_6.booking__listing + , subq_6.booking__guest + , subq_6.booking__host + , subq_6.is_instant + , subq_6.booking__is_instant + , subq_6.bookings + , subq_6.instant_bookings + , subq_6.booking_value + , subq_6.max_booking_value + , subq_6.min_booking_value + , subq_6.bookers + , subq_6.average_booking_value + , subq_6.referred_bookings + , subq_6.median_booking_value + , subq_6.booking_value_p99 + , subq_6.discrete_booking_value_p99 + , subq_6.approximate_continuous_booking_value_p99 + , subq_6.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['country_latest', 'listing'] + SELECT + subq_11.listing + , subq_11.country_latest + FROM ( + -- Metric Time Dimension 'ds' + 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.created_at__day + , subq_10.created_at__week + , subq_10.created_at__month + , subq_10.created_at__quarter + , subq_10.created_at__year + , subq_10.created_at__extract_year + , subq_10.created_at__extract_quarter + , subq_10.created_at__extract_month + , subq_10.created_at__extract_day + , subq_10.created_at__extract_dow + , subq_10.created_at__extract_doy + , subq_10.listing__ds__day + , subq_10.listing__ds__week + , subq_10.listing__ds__month + , subq_10.listing__ds__quarter + , subq_10.listing__ds__year + , subq_10.listing__ds__extract_year + , subq_10.listing__ds__extract_quarter + , subq_10.listing__ds__extract_month + , subq_10.listing__ds__extract_day + , subq_10.listing__ds__extract_dow + , subq_10.listing__ds__extract_doy + , subq_10.listing__created_at__day + , subq_10.listing__created_at__week + , subq_10.listing__created_at__month + , subq_10.listing__created_at__quarter + , subq_10.listing__created_at__year + , subq_10.listing__created_at__extract_year + , subq_10.listing__created_at__extract_quarter + , subq_10.listing__created_at__extract_month + , subq_10.listing__created_at__extract_day + , subq_10.listing__created_at__extract_dow + , subq_10.listing__created_at__extract_doy + , subq_10.ds__day AS metric_time__day + , subq_10.ds__week AS metric_time__week + , subq_10.ds__month AS metric_time__month + , subq_10.ds__quarter AS metric_time__quarter + , subq_10.ds__year AS metric_time__year + , subq_10.ds__extract_year AS metric_time__extract_year + , subq_10.ds__extract_quarter AS metric_time__extract_quarter + , subq_10.ds__extract_month AS metric_time__extract_month + , subq_10.ds__extract_day AS metric_time__extract_day + , subq_10.ds__extract_dow AS metric_time__extract_dow + , subq_10.ds__extract_doy AS metric_time__extract_doy + , subq_10.listing + , subq_10.user + , subq_10.listing__user + , subq_10.country_latest + , subq_10.is_lux_latest + , subq_10.capacity_latest + , subq_10.listing__country_latest + , subq_10.listing__is_lux_latest + , subq_10.listing__capacity_latest + , subq_10.listings + , subq_10.largest_listing + , subq_10.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_10 + ) subq_11 + ) subq_12 + ON + subq_9.listing = subq_12.listing + ) subq_13 + ) subq_14 + WHERE booking__is_instant + ) subq_15 + ) subq_16 + GROUP BY + subq_16.listing__country_latest +) subq_17 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_single_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_single_categorical_dimension_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..b0a46663de --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_single_categorical_dimension_pushdown__plan0_optimized.sql @@ -0,0 +1,40 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'listing__country_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] + SELECT + subq_21.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.country AS listing__country_latest + , subq_21.bookings AS bookings + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_19 + WHERE booking__is_instant + ) subq_21 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_21.listing = listings_latest_src_28000.listing_id +) subq_26 +WHERE booking__is_instant +GROUP BY + listing__country_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_skipped_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_skipped_pushdown__plan0.sql new file mode 100644 index 0000000000..2c072d5394 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_skipped_pushdown__plan0.sql @@ -0,0 +1,387 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.listing__country_latest + , subq_10.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_9.listing__country_latest + , SUM(subq_9.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest'] + SELECT + subq_8.listing__country_latest + , subq_8.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.booking__is_instant + , subq_7.listing__country_latest + , subq_7.listing__is_lux_latest + , subq_7.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] + SELECT + subq_6.booking__is_instant + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_2.listing AS listing + , subq_2.booking__is_instant AS booking__is_instant + , subq_5.country_latest AS listing__country_latest + , subq_5.is_lux_latest AS listing__is_lux_latest + , subq_2.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_1.listing + , subq_1.booking__is_instant + , subq_1.bookings + 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.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.booking__paid_at__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.listing + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['country_latest', 'is_lux_latest', 'listing', 'listing'] + SELECT + subq_4.listing + , subq_4.country_latest + , subq_4.is_lux_latest + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.ds__day AS metric_time__day + , subq_3.ds__week AS metric_time__week + , subq_3.ds__month AS metric_time__month + , subq_3.ds__quarter AS metric_time__quarter + , subq_3.ds__year AS metric_time__year + , subq_3.ds__extract_year AS metric_time__extract_year + , subq_3.ds__extract_quarter AS metric_time__extract_quarter + , subq_3.ds__extract_month AS metric_time__extract_month + , subq_3.ds__extract_day AS metric_time__extract_day + , subq_3.ds__extract_dow AS metric_time__extract_dow + , subq_3.ds__extract_doy AS metric_time__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_3 + ) subq_4 + ) subq_5 + ON + subq_2.listing = subq_5.listing + ) subq_6 + ) subq_7 + WHERE booking__is_instant OR listing__is_lux_latest + ) subq_8 + ) subq_9 + GROUP BY + subq_9.listing__country_latest +) subq_10 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_skipped_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_skipped_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..be31b01767 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_skipped_pushdown__plan0_optimized.sql @@ -0,0 +1,33 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'listing__country_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] + SELECT + subq_13.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , subq_13.bookings AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_13.listing = listings_latest_src_28000.listing_id +) subq_18 +WHERE booking__is_instant OR listing__is_lux_latest +GROUP BY + listing__country_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_categorical_dimension_pushdown__plan0.sql new file mode 100644 index 0000000000..c3a78081ba --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_categorical_dimension_pushdown__plan0.sql @@ -0,0 +1,387 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.booking__is_instant + , subq_10.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_9.booking__is_instant + , SUM(subq_9.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant'] + SELECT + subq_8.booking__is_instant + , subq_8.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.booking__is_instant + , subq_7.listing__is_lux_latest + , subq_7.listing__capacity_latest + , subq_7.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing__is_lux_latest', 'listing__capacity_latest'] + SELECT + subq_6.booking__is_instant + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_2.listing AS listing + , subq_2.booking__is_instant AS booking__is_instant + , subq_5.is_lux_latest AS listing__is_lux_latest + , subq_5.capacity_latest AS listing__capacity_latest + , subq_2.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_1.listing + , subq_1.booking__is_instant + , subq_1.bookings + 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.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.booking__paid_at__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.listing + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['is_lux_latest', 'capacity_latest', 'listing', 'listing'] + SELECT + subq_4.listing + , subq_4.is_lux_latest + , subq_4.capacity_latest + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.ds__day AS metric_time__day + , subq_3.ds__week AS metric_time__week + , subq_3.ds__month AS metric_time__month + , subq_3.ds__quarter AS metric_time__quarter + , subq_3.ds__year AS metric_time__year + , subq_3.ds__extract_year AS metric_time__extract_year + , subq_3.ds__extract_quarter AS metric_time__extract_quarter + , subq_3.ds__extract_month AS metric_time__extract_month + , subq_3.ds__extract_day AS metric_time__extract_day + , subq_3.ds__extract_dow AS metric_time__extract_dow + , subq_3.ds__extract_doy AS metric_time__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_3 + ) subq_4 + ) subq_5 + ON + subq_2.listing = subq_5.listing + ) subq_6 + ) subq_7 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_8 + ) subq_9 + GROUP BY + subq_9.booking__is_instant +) subq_10 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..98cc26bb70 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql @@ -0,0 +1,33 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'booking__is_instant'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + booking__is_instant + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing__is_lux_latest', 'listing__capacity_latest'] + SELECT + subq_13.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , subq_13.bookings AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_13.listing = listings_latest_src_28000.listing_id +) subq_18 +WHERE listing__is_lux_latest OR listing__capacity_latest > 4 +GROUP BY + booking__is_instant diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..f3103e613f --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql @@ -0,0 +1,651 @@ +-- Compute Metrics via Expressions +SELECT + CAST(subq_28.west_coast_balance_first_day AS DOUBLE) / CAST(NULLIF(subq_28.east_coast_balance_first_dat, 0) AS DOUBLE) AS regional_starting_balance_ratios +FROM ( + -- Combine Aggregated Outputs + SELECT + MAX(subq_13.west_coast_balance_first_day) AS west_coast_balance_first_day + , MAX(subq_27.east_coast_balance_first_dat) AS east_coast_balance_first_dat + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_12.total_account_balance_first_day AS west_coast_balance_first_day + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_11.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_10.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_7.ds__day AS ds__day + , subq_7.user__home_state_latest AS user__home_state_latest + , subq_7.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + 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.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__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.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(dayofweekiso FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_7 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_8.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + 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.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__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.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(dayofweekiso FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_8 + ) subq_9 + ON + subq_7.ds__day = subq_9.ds__day__complete + ) subq_10 + ) subq_11 + ) subq_12 + ) subq_13 + CROSS JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_26.total_account_balance_first_day AS east_coast_balance_first_dat + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_25.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_24.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_21.ds__day AS ds__day + , subq_21.user__home_state_latest AS user__home_state_latest + , subq_21.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_14.ds__day + , subq_14.ds__week + , subq_14.ds__month + , subq_14.ds__quarter + , subq_14.ds__year + , subq_14.ds__extract_year + , subq_14.ds__extract_quarter + , subq_14.ds__extract_month + , subq_14.ds__extract_day + , subq_14.ds__extract_dow + , subq_14.ds__extract_doy + , subq_14.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__extract_doy + , subq_14.ds__day AS metric_time__day + , subq_14.ds__week AS metric_time__week + , subq_14.ds__month AS metric_time__month + , subq_14.ds__quarter AS metric_time__quarter + , subq_14.ds__year AS metric_time__year + , subq_14.ds__extract_year AS metric_time__extract_year + , subq_14.ds__extract_quarter AS metric_time__extract_quarter + , subq_14.ds__extract_month AS metric_time__extract_month + , subq_14.ds__extract_day AS metric_time__extract_day + , subq_14.ds__extract_dow AS metric_time__extract_dow + , subq_14.ds__extract_doy AS metric_time__extract_doy + , subq_14.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(dayofweekiso FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_21 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_22.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_14.ds__day + , subq_14.ds__week + , subq_14.ds__month + , subq_14.ds__quarter + , subq_14.ds__year + , subq_14.ds__extract_year + , subq_14.ds__extract_quarter + , subq_14.ds__extract_month + , subq_14.ds__extract_day + , subq_14.ds__extract_dow + , subq_14.ds__extract_doy + , subq_14.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__extract_doy + , subq_14.ds__day AS metric_time__day + , subq_14.ds__week AS metric_time__week + , subq_14.ds__month AS metric_time__month + , subq_14.ds__quarter AS metric_time__quarter + , subq_14.ds__year AS metric_time__year + , subq_14.ds__extract_year AS metric_time__extract_year + , subq_14.ds__extract_quarter AS metric_time__extract_quarter + , subq_14.ds__extract_month AS metric_time__extract_month + , subq_14.ds__extract_day AS metric_time__extract_day + , subq_14.ds__extract_dow AS metric_time__extract_dow + , subq_14.ds__extract_doy AS metric_time__extract_doy + , subq_14.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(dayofweekiso FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_22 + ) subq_23 + ON + subq_21.ds__day = subq_23.ds__day__complete + ) subq_24 + ) subq_25 + ) subq_26 + ) subq_27 +) subq_28 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..44eac537d1 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,102 @@ +-- Combine Aggregated Outputs +-- Compute Metrics via Expressions +SELECT + CAST(MAX(subq_42.west_coast_balance_first_day) AS DOUBLE) / CAST(NULLIF(MAX(subq_56.east_coast_balance_first_dat), 0) AS DOUBLE) AS regional_starting_balance_ratios +FROM ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_36.total_account_balance_first_day) AS west_coast_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_36 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_38 + ON + subq_36.ds__day = subq_38.ds__day__complete +) subq_42 +CROSS JOIN ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_50.total_account_balance_first_day) AS east_coast_balance_first_dat + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_50 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_52 + ON + subq_50.ds__day = subq_52.ds__day__complete +) subq_56 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..fac10af629 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql @@ -0,0 +1,563 @@ +-- Compute Metrics via Expressions +SELECT + subq_19.metric_time__day + , CAST(subq_19.average_booking_value AS DOUBLE) / CAST(NULLIF(subq_19.max_booking_value, 0) AS DOUBLE) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) AS metric_time__day + , MAX(subq_13.average_booking_value) AS average_booking_value + , MAX(subq_18.max_booking_value) AS max_booking_value + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_12.metric_time__day + , subq_12.average_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_11.metric_time__day + , AVG(subq_11.average_booking_value) AS average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + SELECT + subq_10.metric_time__day + , subq_10.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__week + , subq_7.ds__month + , subq_7.ds__quarter + , subq_7.ds__year + , subq_7.ds__extract_year + , subq_7.ds__extract_quarter + , subq_7.ds__extract_month + , subq_7.ds__extract_day + , subq_7.ds__extract_dow + , subq_7.ds__extract_doy + , subq_7.ds_partitioned__day + , subq_7.ds_partitioned__week + , subq_7.ds_partitioned__month + , subq_7.ds_partitioned__quarter + , subq_7.ds_partitioned__year + , subq_7.ds_partitioned__extract_year + , subq_7.ds_partitioned__extract_quarter + , subq_7.ds_partitioned__extract_month + , subq_7.ds_partitioned__extract_day + , subq_7.ds_partitioned__extract_dow + , subq_7.ds_partitioned__extract_doy + , subq_7.paid_at__day + , subq_7.paid_at__week + , subq_7.paid_at__month + , subq_7.paid_at__quarter + , subq_7.paid_at__year + , subq_7.paid_at__extract_year + , subq_7.paid_at__extract_quarter + , subq_7.paid_at__extract_month + , subq_7.paid_at__extract_day + , subq_7.paid_at__extract_dow + , subq_7.paid_at__extract_doy + , subq_7.booking__ds__day + , subq_7.booking__ds__week + , subq_7.booking__ds__month + , subq_7.booking__ds__quarter + , subq_7.booking__ds__year + , subq_7.booking__ds__extract_year + , subq_7.booking__ds__extract_quarter + , subq_7.booking__ds__extract_month + , subq_7.booking__ds__extract_day + , subq_7.booking__ds__extract_dow + , subq_7.booking__ds__extract_doy + , subq_7.booking__ds_partitioned__day + , subq_7.booking__ds_partitioned__week + , subq_7.booking__ds_partitioned__month + , subq_7.booking__ds_partitioned__quarter + , subq_7.booking__ds_partitioned__year + , subq_7.booking__ds_partitioned__extract_year + , subq_7.booking__ds_partitioned__extract_quarter + , subq_7.booking__ds_partitioned__extract_month + , subq_7.booking__ds_partitioned__extract_day + , subq_7.booking__ds_partitioned__extract_dow + , subq_7.booking__ds_partitioned__extract_doy + , subq_7.booking__paid_at__day + , subq_7.booking__paid_at__week + , subq_7.booking__paid_at__month + , subq_7.booking__paid_at__quarter + , subq_7.booking__paid_at__year + , subq_7.booking__paid_at__extract_year + , subq_7.booking__paid_at__extract_quarter + , subq_7.booking__paid_at__extract_month + , subq_7.booking__paid_at__extract_day + , subq_7.booking__paid_at__extract_dow + , subq_7.booking__paid_at__extract_doy + , subq_7.metric_time__day + , subq_7.metric_time__week + , subq_7.metric_time__month + , subq_7.metric_time__quarter + , subq_7.metric_time__year + , subq_7.metric_time__extract_year + , subq_7.metric_time__extract_quarter + , subq_7.metric_time__extract_month + , subq_7.metric_time__extract_day + , subq_7.metric_time__extract_dow + , subq_7.metric_time__extract_doy + , subq_7.listing + , subq_7.guest + , subq_7.host + , subq_7.booking__listing + , subq_7.booking__guest + , subq_7.booking__host + , subq_7.is_instant + , subq_7.booking__is_instant + , subq_7.bookings + , subq_7.instant_bookings + , subq_7.booking_value + , subq_7.max_booking_value + , subq_7.min_booking_value + , subq_7.bookers + , subq_7.average_booking_value + , subq_7.referred_bookings + , subq_7.median_booking_value + , subq_7.booking_value_p99 + , subq_7.discrete_booking_value_p99 + , subq_7.approximate_continuous_booking_value_p99 + , subq_7.approximate_discrete_booking_value_p99 + 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.ds_partitioned__day + , subq_6.ds_partitioned__week + , subq_6.ds_partitioned__month + , subq_6.ds_partitioned__quarter + , subq_6.ds_partitioned__year + , subq_6.ds_partitioned__extract_year + , subq_6.ds_partitioned__extract_quarter + , subq_6.ds_partitioned__extract_month + , subq_6.ds_partitioned__extract_day + , subq_6.ds_partitioned__extract_dow + , subq_6.ds_partitioned__extract_doy + , subq_6.paid_at__day + , subq_6.paid_at__week + , subq_6.paid_at__month + , subq_6.paid_at__quarter + , subq_6.paid_at__year + , subq_6.paid_at__extract_year + , subq_6.paid_at__extract_quarter + , subq_6.paid_at__extract_month + , subq_6.paid_at__extract_day + , subq_6.paid_at__extract_dow + , subq_6.paid_at__extract_doy + , subq_6.booking__ds__day + , subq_6.booking__ds__week + , subq_6.booking__ds__month + , subq_6.booking__ds__quarter + , subq_6.booking__ds__year + , subq_6.booking__ds__extract_year + , subq_6.booking__ds__extract_quarter + , subq_6.booking__ds__extract_month + , subq_6.booking__ds__extract_day + , subq_6.booking__ds__extract_dow + , subq_6.booking__ds__extract_doy + , subq_6.booking__ds_partitioned__day + , subq_6.booking__ds_partitioned__week + , subq_6.booking__ds_partitioned__month + , subq_6.booking__ds_partitioned__quarter + , subq_6.booking__ds_partitioned__year + , subq_6.booking__ds_partitioned__extract_year + , subq_6.booking__ds_partitioned__extract_quarter + , subq_6.booking__ds_partitioned__extract_month + , subq_6.booking__ds_partitioned__extract_day + , subq_6.booking__ds_partitioned__extract_dow + , subq_6.booking__ds_partitioned__extract_doy + , subq_6.booking__paid_at__day + , subq_6.booking__paid_at__week + , subq_6.booking__paid_at__month + , subq_6.booking__paid_at__quarter + , subq_6.booking__paid_at__year + , subq_6.booking__paid_at__extract_year + , subq_6.booking__paid_at__extract_quarter + , subq_6.booking__paid_at__extract_month + , subq_6.booking__paid_at__extract_day + , subq_6.booking__paid_at__extract_dow + , subq_6.booking__paid_at__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.listing + , subq_6.guest + , subq_6.host + , subq_6.booking__listing + , subq_6.booking__guest + , subq_6.booking__host + , subq_6.is_instant + , subq_6.booking__is_instant + , subq_6.bookings + , subq_6.instant_bookings + , subq_6.booking_value + , subq_6.max_booking_value + , subq_6.min_booking_value + , subq_6.bookers + , subq_6.average_booking_value + , subq_6.referred_bookings + , subq_6.median_booking_value + , subq_6.booking_value_p99 + , subq_6.discrete_booking_value_p99 + , subq_6.approximate_continuous_booking_value_p99 + , subq_6.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 + WHERE booking__is_instant + ) subq_10 + ) subq_11 + GROUP BY + subq_11.metric_time__day + ) subq_12 + ) subq_13 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_17.metric_time__day + , subq_17.max_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_16.metric_time__day + , MAX(subq_16.max_booking_value) AS max_booking_value + FROM ( + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + SELECT + subq_15.metric_time__day + , subq_15.max_booking_value + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_14.ds__day + , subq_14.ds__week + , subq_14.ds__month + , subq_14.ds__quarter + , subq_14.ds__year + , subq_14.ds__extract_year + , subq_14.ds__extract_quarter + , subq_14.ds__extract_month + , subq_14.ds__extract_day + , subq_14.ds__extract_dow + , subq_14.ds__extract_doy + , subq_14.ds_partitioned__day + , subq_14.ds_partitioned__week + , subq_14.ds_partitioned__month + , subq_14.ds_partitioned__quarter + , subq_14.ds_partitioned__year + , subq_14.ds_partitioned__extract_year + , subq_14.ds_partitioned__extract_quarter + , subq_14.ds_partitioned__extract_month + , subq_14.ds_partitioned__extract_day + , subq_14.ds_partitioned__extract_dow + , subq_14.ds_partitioned__extract_doy + , subq_14.paid_at__day + , subq_14.paid_at__week + , subq_14.paid_at__month + , subq_14.paid_at__quarter + , subq_14.paid_at__year + , subq_14.paid_at__extract_year + , subq_14.paid_at__extract_quarter + , subq_14.paid_at__extract_month + , subq_14.paid_at__extract_day + , subq_14.paid_at__extract_dow + , subq_14.paid_at__extract_doy + , subq_14.booking__ds__day + , subq_14.booking__ds__week + , subq_14.booking__ds__month + , subq_14.booking__ds__quarter + , subq_14.booking__ds__year + , subq_14.booking__ds__extract_year + , subq_14.booking__ds__extract_quarter + , subq_14.booking__ds__extract_month + , subq_14.booking__ds__extract_day + , subq_14.booking__ds__extract_dow + , subq_14.booking__ds__extract_doy + , subq_14.booking__ds_partitioned__day + , subq_14.booking__ds_partitioned__week + , subq_14.booking__ds_partitioned__month + , subq_14.booking__ds_partitioned__quarter + , subq_14.booking__ds_partitioned__year + , subq_14.booking__ds_partitioned__extract_year + , subq_14.booking__ds_partitioned__extract_quarter + , subq_14.booking__ds_partitioned__extract_month + , subq_14.booking__ds_partitioned__extract_day + , subq_14.booking__ds_partitioned__extract_dow + , subq_14.booking__ds_partitioned__extract_doy + , subq_14.booking__paid_at__day + , subq_14.booking__paid_at__week + , subq_14.booking__paid_at__month + , subq_14.booking__paid_at__quarter + , subq_14.booking__paid_at__year + , subq_14.booking__paid_at__extract_year + , subq_14.booking__paid_at__extract_quarter + , subq_14.booking__paid_at__extract_month + , subq_14.booking__paid_at__extract_day + , subq_14.booking__paid_at__extract_dow + , subq_14.booking__paid_at__extract_doy + , subq_14.ds__day AS metric_time__day + , subq_14.ds__week AS metric_time__week + , subq_14.ds__month AS metric_time__month + , subq_14.ds__quarter AS metric_time__quarter + , subq_14.ds__year AS metric_time__year + , subq_14.ds__extract_year AS metric_time__extract_year + , subq_14.ds__extract_quarter AS metric_time__extract_quarter + , subq_14.ds__extract_month AS metric_time__extract_month + , subq_14.ds__extract_day AS metric_time__extract_day + , subq_14.ds__extract_dow AS metric_time__extract_dow + , subq_14.ds__extract_doy AS metric_time__extract_doy + , subq_14.listing + , subq_14.guest + , subq_14.host + , subq_14.booking__listing + , subq_14.booking__guest + , subq_14.booking__host + , subq_14.is_instant + , subq_14.booking__is_instant + , subq_14.bookings + , subq_14.instant_bookings + , subq_14.booking_value + , subq_14.max_booking_value + , subq_14.min_booking_value + , subq_14.bookers + , subq_14.average_booking_value + , subq_14.referred_bookings + , subq_14.median_booking_value + , subq_14.booking_value_p99 + , subq_14.discrete_booking_value_p99 + , subq_14.approximate_continuous_booking_value_p99 + , subq_14.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + GROUP BY + subq_16.metric_time__day + ) subq_17 + ) subq_18 + ON + subq_13.metric_time__day = subq_18.metric_time__day + GROUP BY + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) +) subq_19 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..111a82caa8 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,58 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , CAST(average_booking_value AS DOUBLE) / CAST(NULLIF(max_booking_value, 0) AS DOUBLE) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) AS metric_time__day + , MAX(subq_27.average_booking_value) AS average_booking_value + , MAX(subq_32.max_booking_value) AS max_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , AVG(average_booking_value) AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + metric_time__day + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_21 + WHERE booking__is_instant + ) subq_23 + WHERE booking__is_instant + GROUP BY + metric_time__day + ) subq_27 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , MAX(booking_value) AS max_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_32 + ON + subq_27.metric_time__day = subq_32.metric_time__day + GROUP BY + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) +) subq_33 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_single_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_single_categorical_dimension_pushdown__plan0.sql new file mode 100644 index 0000000000..0b87608c26 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_single_categorical_dimension_pushdown__plan0.sql @@ -0,0 +1,486 @@ +-- Compute Metrics via Expressions +SELECT + subq_17.listing__country_latest + , subq_17.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_16.listing__country_latest + , SUM(subq_16.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest'] + SELECT + subq_15.listing__country_latest + , subq_15.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_14.booking__is_instant + , subq_14.listing__country_latest + , subq_14.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] + SELECT + subq_13.booking__is_instant + , subq_13.listing__country_latest + , subq_13.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_9.listing AS listing + , subq_9.booking__is_instant AS booking__is_instant + , subq_12.country_latest AS listing__country_latest + , subq_9.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_8.listing + , subq_8.booking__is_instant + , subq_8.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__week + , subq_7.ds__month + , subq_7.ds__quarter + , subq_7.ds__year + , subq_7.ds__extract_year + , subq_7.ds__extract_quarter + , subq_7.ds__extract_month + , subq_7.ds__extract_day + , subq_7.ds__extract_dow + , subq_7.ds__extract_doy + , subq_7.ds_partitioned__day + , subq_7.ds_partitioned__week + , subq_7.ds_partitioned__month + , subq_7.ds_partitioned__quarter + , subq_7.ds_partitioned__year + , subq_7.ds_partitioned__extract_year + , subq_7.ds_partitioned__extract_quarter + , subq_7.ds_partitioned__extract_month + , subq_7.ds_partitioned__extract_day + , subq_7.ds_partitioned__extract_dow + , subq_7.ds_partitioned__extract_doy + , subq_7.paid_at__day + , subq_7.paid_at__week + , subq_7.paid_at__month + , subq_7.paid_at__quarter + , subq_7.paid_at__year + , subq_7.paid_at__extract_year + , subq_7.paid_at__extract_quarter + , subq_7.paid_at__extract_month + , subq_7.paid_at__extract_day + , subq_7.paid_at__extract_dow + , subq_7.paid_at__extract_doy + , subq_7.booking__ds__day + , subq_7.booking__ds__week + , subq_7.booking__ds__month + , subq_7.booking__ds__quarter + , subq_7.booking__ds__year + , subq_7.booking__ds__extract_year + , subq_7.booking__ds__extract_quarter + , subq_7.booking__ds__extract_month + , subq_7.booking__ds__extract_day + , subq_7.booking__ds__extract_dow + , subq_7.booking__ds__extract_doy + , subq_7.booking__ds_partitioned__day + , subq_7.booking__ds_partitioned__week + , subq_7.booking__ds_partitioned__month + , subq_7.booking__ds_partitioned__quarter + , subq_7.booking__ds_partitioned__year + , subq_7.booking__ds_partitioned__extract_year + , subq_7.booking__ds_partitioned__extract_quarter + , subq_7.booking__ds_partitioned__extract_month + , subq_7.booking__ds_partitioned__extract_day + , subq_7.booking__ds_partitioned__extract_dow + , subq_7.booking__ds_partitioned__extract_doy + , subq_7.booking__paid_at__day + , subq_7.booking__paid_at__week + , subq_7.booking__paid_at__month + , subq_7.booking__paid_at__quarter + , subq_7.booking__paid_at__year + , subq_7.booking__paid_at__extract_year + , subq_7.booking__paid_at__extract_quarter + , subq_7.booking__paid_at__extract_month + , subq_7.booking__paid_at__extract_day + , subq_7.booking__paid_at__extract_dow + , subq_7.booking__paid_at__extract_doy + , subq_7.metric_time__day + , subq_7.metric_time__week + , subq_7.metric_time__month + , subq_7.metric_time__quarter + , subq_7.metric_time__year + , subq_7.metric_time__extract_year + , subq_7.metric_time__extract_quarter + , subq_7.metric_time__extract_month + , subq_7.metric_time__extract_day + , subq_7.metric_time__extract_dow + , subq_7.metric_time__extract_doy + , subq_7.listing + , subq_7.guest + , subq_7.host + , subq_7.booking__listing + , subq_7.booking__guest + , subq_7.booking__host + , subq_7.is_instant + , subq_7.booking__is_instant + , subq_7.bookings + , subq_7.instant_bookings + , subq_7.booking_value + , subq_7.max_booking_value + , subq_7.min_booking_value + , subq_7.bookers + , subq_7.average_booking_value + , subq_7.referred_bookings + , subq_7.median_booking_value + , subq_7.booking_value_p99 + , subq_7.discrete_booking_value_p99 + , subq_7.approximate_continuous_booking_value_p99 + , subq_7.approximate_discrete_booking_value_p99 + 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.ds_partitioned__day + , subq_6.ds_partitioned__week + , subq_6.ds_partitioned__month + , subq_6.ds_partitioned__quarter + , subq_6.ds_partitioned__year + , subq_6.ds_partitioned__extract_year + , subq_6.ds_partitioned__extract_quarter + , subq_6.ds_partitioned__extract_month + , subq_6.ds_partitioned__extract_day + , subq_6.ds_partitioned__extract_dow + , subq_6.ds_partitioned__extract_doy + , subq_6.paid_at__day + , subq_6.paid_at__week + , subq_6.paid_at__month + , subq_6.paid_at__quarter + , subq_6.paid_at__year + , subq_6.paid_at__extract_year + , subq_6.paid_at__extract_quarter + , subq_6.paid_at__extract_month + , subq_6.paid_at__extract_day + , subq_6.paid_at__extract_dow + , subq_6.paid_at__extract_doy + , subq_6.booking__ds__day + , subq_6.booking__ds__week + , subq_6.booking__ds__month + , subq_6.booking__ds__quarter + , subq_6.booking__ds__year + , subq_6.booking__ds__extract_year + , subq_6.booking__ds__extract_quarter + , subq_6.booking__ds__extract_month + , subq_6.booking__ds__extract_day + , subq_6.booking__ds__extract_dow + , subq_6.booking__ds__extract_doy + , subq_6.booking__ds_partitioned__day + , subq_6.booking__ds_partitioned__week + , subq_6.booking__ds_partitioned__month + , subq_6.booking__ds_partitioned__quarter + , subq_6.booking__ds_partitioned__year + , subq_6.booking__ds_partitioned__extract_year + , subq_6.booking__ds_partitioned__extract_quarter + , subq_6.booking__ds_partitioned__extract_month + , subq_6.booking__ds_partitioned__extract_day + , subq_6.booking__ds_partitioned__extract_dow + , subq_6.booking__ds_partitioned__extract_doy + , subq_6.booking__paid_at__day + , subq_6.booking__paid_at__week + , subq_6.booking__paid_at__month + , subq_6.booking__paid_at__quarter + , subq_6.booking__paid_at__year + , subq_6.booking__paid_at__extract_year + , subq_6.booking__paid_at__extract_quarter + , subq_6.booking__paid_at__extract_month + , subq_6.booking__paid_at__extract_day + , subq_6.booking__paid_at__extract_dow + , subq_6.booking__paid_at__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.listing + , subq_6.guest + , subq_6.host + , subq_6.booking__listing + , subq_6.booking__guest + , subq_6.booking__host + , subq_6.is_instant + , subq_6.booking__is_instant + , subq_6.bookings + , subq_6.instant_bookings + , subq_6.booking_value + , subq_6.max_booking_value + , subq_6.min_booking_value + , subq_6.bookers + , subq_6.average_booking_value + , subq_6.referred_bookings + , subq_6.median_booking_value + , subq_6.booking_value_p99 + , subq_6.discrete_booking_value_p99 + , subq_6.approximate_continuous_booking_value_p99 + , subq_6.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['country_latest', 'listing'] + SELECT + subq_11.listing + , subq_11.country_latest + FROM ( + -- Metric Time Dimension 'ds' + 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.created_at__day + , subq_10.created_at__week + , subq_10.created_at__month + , subq_10.created_at__quarter + , subq_10.created_at__year + , subq_10.created_at__extract_year + , subq_10.created_at__extract_quarter + , subq_10.created_at__extract_month + , subq_10.created_at__extract_day + , subq_10.created_at__extract_dow + , subq_10.created_at__extract_doy + , subq_10.listing__ds__day + , subq_10.listing__ds__week + , subq_10.listing__ds__month + , subq_10.listing__ds__quarter + , subq_10.listing__ds__year + , subq_10.listing__ds__extract_year + , subq_10.listing__ds__extract_quarter + , subq_10.listing__ds__extract_month + , subq_10.listing__ds__extract_day + , subq_10.listing__ds__extract_dow + , subq_10.listing__ds__extract_doy + , subq_10.listing__created_at__day + , subq_10.listing__created_at__week + , subq_10.listing__created_at__month + , subq_10.listing__created_at__quarter + , subq_10.listing__created_at__year + , subq_10.listing__created_at__extract_year + , subq_10.listing__created_at__extract_quarter + , subq_10.listing__created_at__extract_month + , subq_10.listing__created_at__extract_day + , subq_10.listing__created_at__extract_dow + , subq_10.listing__created_at__extract_doy + , subq_10.ds__day AS metric_time__day + , subq_10.ds__week AS metric_time__week + , subq_10.ds__month AS metric_time__month + , subq_10.ds__quarter AS metric_time__quarter + , subq_10.ds__year AS metric_time__year + , subq_10.ds__extract_year AS metric_time__extract_year + , subq_10.ds__extract_quarter AS metric_time__extract_quarter + , subq_10.ds__extract_month AS metric_time__extract_month + , subq_10.ds__extract_day AS metric_time__extract_day + , subq_10.ds__extract_dow AS metric_time__extract_dow + , subq_10.ds__extract_doy AS metric_time__extract_doy + , subq_10.listing + , subq_10.user + , subq_10.listing__user + , subq_10.country_latest + , subq_10.is_lux_latest + , subq_10.capacity_latest + , subq_10.listing__country_latest + , subq_10.listing__is_lux_latest + , subq_10.listing__capacity_latest + , subq_10.listings + , subq_10.largest_listing + , subq_10.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_10 + ) subq_11 + ) subq_12 + ON + subq_9.listing = subq_12.listing + ) subq_13 + ) subq_14 + WHERE booking__is_instant + ) subq_15 + ) subq_16 + GROUP BY + subq_16.listing__country_latest +) subq_17 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_single_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_single_categorical_dimension_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..b0a46663de --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_single_categorical_dimension_pushdown__plan0_optimized.sql @@ -0,0 +1,40 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'listing__country_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] + SELECT + subq_21.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.country AS listing__country_latest + , subq_21.bookings AS bookings + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_19 + WHERE booking__is_instant + ) subq_21 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_21.listing = listings_latest_src_28000.listing_id +) subq_26 +WHERE booking__is_instant +GROUP BY + listing__country_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_skipped_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_skipped_pushdown__plan0.sql new file mode 100644 index 0000000000..00cabc8f0d --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_skipped_pushdown__plan0.sql @@ -0,0 +1,387 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.listing__country_latest + , subq_10.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_9.listing__country_latest + , SUM(subq_9.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest'] + SELECT + subq_8.listing__country_latest + , subq_8.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.booking__is_instant + , subq_7.listing__country_latest + , subq_7.listing__is_lux_latest + , subq_7.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] + SELECT + subq_6.booking__is_instant + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_2.listing AS listing + , subq_2.booking__is_instant AS booking__is_instant + , subq_5.country_latest AS listing__country_latest + , subq_5.is_lux_latest AS listing__is_lux_latest + , subq_2.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_1.listing + , subq_1.booking__is_instant + , subq_1.bookings + 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.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.booking__paid_at__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.listing + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['country_latest', 'is_lux_latest', 'listing', 'listing'] + SELECT + subq_4.listing + , subq_4.country_latest + , subq_4.is_lux_latest + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.ds__day AS metric_time__day + , subq_3.ds__week AS metric_time__week + , subq_3.ds__month AS metric_time__month + , subq_3.ds__quarter AS metric_time__quarter + , subq_3.ds__year AS metric_time__year + , subq_3.ds__extract_year AS metric_time__extract_year + , subq_3.ds__extract_quarter AS metric_time__extract_quarter + , subq_3.ds__extract_month AS metric_time__extract_month + , subq_3.ds__extract_day AS metric_time__extract_day + , subq_3.ds__extract_dow AS metric_time__extract_dow + , subq_3.ds__extract_doy AS metric_time__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_3 + ) subq_4 + ) subq_5 + ON + subq_2.listing = subq_5.listing + ) subq_6 + ) subq_7 + WHERE booking__is_instant OR listing__is_lux_latest + ) subq_8 + ) subq_9 + GROUP BY + subq_9.listing__country_latest +) subq_10 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_skipped_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_skipped_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..be31b01767 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_skipped_pushdown__plan0_optimized.sql @@ -0,0 +1,33 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'listing__country_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] + SELECT + subq_13.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , subq_13.bookings AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_13.listing = listings_latest_src_28000.listing_id +) subq_18 +WHERE booking__is_instant OR listing__is_lux_latest +GROUP BY + listing__country_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_categorical_dimension_pushdown__plan0.sql new file mode 100644 index 0000000000..02f3269db7 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_categorical_dimension_pushdown__plan0.sql @@ -0,0 +1,387 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.booking__is_instant + , subq_10.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_9.booking__is_instant + , SUM(subq_9.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant'] + SELECT + subq_8.booking__is_instant + , subq_8.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.booking__is_instant + , subq_7.listing__is_lux_latest + , subq_7.listing__capacity_latest + , subq_7.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing__is_lux_latest', 'listing__capacity_latest'] + SELECT + subq_6.booking__is_instant + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_2.listing AS listing + , subq_2.booking__is_instant AS booking__is_instant + , subq_5.is_lux_latest AS listing__is_lux_latest + , subq_5.capacity_latest AS listing__capacity_latest + , subq_2.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_1.listing + , subq_1.booking__is_instant + , subq_1.bookings + 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.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.booking__paid_at__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.listing + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['is_lux_latest', 'capacity_latest', 'listing', 'listing'] + SELECT + subq_4.listing + , subq_4.is_lux_latest + , subq_4.capacity_latest + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.ds__day AS metric_time__day + , subq_3.ds__week AS metric_time__week + , subq_3.ds__month AS metric_time__month + , subq_3.ds__quarter AS metric_time__quarter + , subq_3.ds__year AS metric_time__year + , subq_3.ds__extract_year AS metric_time__extract_year + , subq_3.ds__extract_quarter AS metric_time__extract_quarter + , subq_3.ds__extract_month AS metric_time__extract_month + , subq_3.ds__extract_day AS metric_time__extract_day + , subq_3.ds__extract_dow AS metric_time__extract_dow + , subq_3.ds__extract_doy AS metric_time__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_3 + ) subq_4 + ) subq_5 + ON + subq_2.listing = subq_5.listing + ) subq_6 + ) subq_7 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_8 + ) subq_9 + GROUP BY + subq_9.booking__is_instant +) subq_10 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..98cc26bb70 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql @@ -0,0 +1,33 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'booking__is_instant'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + booking__is_instant + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing__is_lux_latest', 'listing__capacity_latest'] + SELECT + subq_13.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , subq_13.bookings AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_13.listing = listings_latest_src_28000.listing_id +) subq_18 +WHERE listing__is_lux_latest OR listing__capacity_latest > 4 +GROUP BY + booking__is_instant diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..0dee0eb985 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql @@ -0,0 +1,651 @@ +-- Compute Metrics via Expressions +SELECT + CAST(subq_28.west_coast_balance_first_day AS DOUBLE) / CAST(NULLIF(subq_28.east_coast_balance_first_dat, 0) AS DOUBLE) AS regional_starting_balance_ratios +FROM ( + -- Combine Aggregated Outputs + SELECT + MAX(subq_13.west_coast_balance_first_day) AS west_coast_balance_first_day + , MAX(subq_27.east_coast_balance_first_dat) AS east_coast_balance_first_dat + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_12.total_account_balance_first_day AS west_coast_balance_first_day + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_11.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_10.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_7.ds__day AS ds__day + , subq_7.user__home_state_latest AS user__home_state_latest + , subq_7.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + 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.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__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.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_7 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_8.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + 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.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__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.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_8 + ) subq_9 + ON + subq_7.ds__day = subq_9.ds__day__complete + ) subq_10 + ) subq_11 + ) subq_12 + ) subq_13 + CROSS JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_26.total_account_balance_first_day AS east_coast_balance_first_dat + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_25.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_24.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_21.ds__day AS ds__day + , subq_21.user__home_state_latest AS user__home_state_latest + , subq_21.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_14.ds__day + , subq_14.ds__week + , subq_14.ds__month + , subq_14.ds__quarter + , subq_14.ds__year + , subq_14.ds__extract_year + , subq_14.ds__extract_quarter + , subq_14.ds__extract_month + , subq_14.ds__extract_day + , subq_14.ds__extract_dow + , subq_14.ds__extract_doy + , subq_14.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__extract_doy + , subq_14.ds__day AS metric_time__day + , subq_14.ds__week AS metric_time__week + , subq_14.ds__month AS metric_time__month + , subq_14.ds__quarter AS metric_time__quarter + , subq_14.ds__year AS metric_time__year + , subq_14.ds__extract_year AS metric_time__extract_year + , subq_14.ds__extract_quarter AS metric_time__extract_quarter + , subq_14.ds__extract_month AS metric_time__extract_month + , subq_14.ds__extract_day AS metric_time__extract_day + , subq_14.ds__extract_dow AS metric_time__extract_dow + , subq_14.ds__extract_doy AS metric_time__extract_doy + , subq_14.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_21 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_22.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_14.ds__day + , subq_14.ds__week + , subq_14.ds__month + , subq_14.ds__quarter + , subq_14.ds__year + , subq_14.ds__extract_year + , subq_14.ds__extract_quarter + , subq_14.ds__extract_month + , subq_14.ds__extract_day + , subq_14.ds__extract_dow + , subq_14.ds__extract_doy + , subq_14.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__extract_doy + , subq_14.ds__day AS metric_time__day + , subq_14.ds__week AS metric_time__week + , subq_14.ds__month AS metric_time__month + , subq_14.ds__quarter AS metric_time__quarter + , subq_14.ds__year AS metric_time__year + , subq_14.ds__extract_year AS metric_time__extract_year + , subq_14.ds__extract_quarter AS metric_time__extract_quarter + , subq_14.ds__extract_month AS metric_time__extract_month + , subq_14.ds__extract_day AS metric_time__extract_day + , subq_14.ds__extract_dow AS metric_time__extract_dow + , subq_14.ds__extract_doy AS metric_time__extract_doy + , subq_14.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_22 + ) subq_23 + ON + subq_21.ds__day = subq_23.ds__day__complete + ) subq_24 + ) subq_25 + ) subq_26 + ) subq_27 +) subq_28 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..44eac537d1 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,102 @@ +-- Combine Aggregated Outputs +-- Compute Metrics via Expressions +SELECT + CAST(MAX(subq_42.west_coast_balance_first_day) AS DOUBLE) / CAST(NULLIF(MAX(subq_56.east_coast_balance_first_dat), 0) AS DOUBLE) AS regional_starting_balance_ratios +FROM ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_36.total_account_balance_first_day) AS west_coast_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_36 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_38 + ON + subq_36.ds__day = subq_38.ds__day__complete +) subq_42 +CROSS JOIN ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_50.total_account_balance_first_day) AS east_coast_balance_first_dat + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_50 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_52 + ON + subq_50.ds__day = subq_52.ds__day__complete +) subq_56 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..ce5e6dddef --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql @@ -0,0 +1,563 @@ +-- Compute Metrics via Expressions +SELECT + subq_19.metric_time__day + , CAST(subq_19.average_booking_value AS DOUBLE) / CAST(NULLIF(subq_19.max_booking_value, 0) AS DOUBLE) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) AS metric_time__day + , MAX(subq_13.average_booking_value) AS average_booking_value + , MAX(subq_18.max_booking_value) AS max_booking_value + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_12.metric_time__day + , subq_12.average_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_11.metric_time__day + , AVG(subq_11.average_booking_value) AS average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + SELECT + subq_10.metric_time__day + , subq_10.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__week + , subq_7.ds__month + , subq_7.ds__quarter + , subq_7.ds__year + , subq_7.ds__extract_year + , subq_7.ds__extract_quarter + , subq_7.ds__extract_month + , subq_7.ds__extract_day + , subq_7.ds__extract_dow + , subq_7.ds__extract_doy + , subq_7.ds_partitioned__day + , subq_7.ds_partitioned__week + , subq_7.ds_partitioned__month + , subq_7.ds_partitioned__quarter + , subq_7.ds_partitioned__year + , subq_7.ds_partitioned__extract_year + , subq_7.ds_partitioned__extract_quarter + , subq_7.ds_partitioned__extract_month + , subq_7.ds_partitioned__extract_day + , subq_7.ds_partitioned__extract_dow + , subq_7.ds_partitioned__extract_doy + , subq_7.paid_at__day + , subq_7.paid_at__week + , subq_7.paid_at__month + , subq_7.paid_at__quarter + , subq_7.paid_at__year + , subq_7.paid_at__extract_year + , subq_7.paid_at__extract_quarter + , subq_7.paid_at__extract_month + , subq_7.paid_at__extract_day + , subq_7.paid_at__extract_dow + , subq_7.paid_at__extract_doy + , subq_7.booking__ds__day + , subq_7.booking__ds__week + , subq_7.booking__ds__month + , subq_7.booking__ds__quarter + , subq_7.booking__ds__year + , subq_7.booking__ds__extract_year + , subq_7.booking__ds__extract_quarter + , subq_7.booking__ds__extract_month + , subq_7.booking__ds__extract_day + , subq_7.booking__ds__extract_dow + , subq_7.booking__ds__extract_doy + , subq_7.booking__ds_partitioned__day + , subq_7.booking__ds_partitioned__week + , subq_7.booking__ds_partitioned__month + , subq_7.booking__ds_partitioned__quarter + , subq_7.booking__ds_partitioned__year + , subq_7.booking__ds_partitioned__extract_year + , subq_7.booking__ds_partitioned__extract_quarter + , subq_7.booking__ds_partitioned__extract_month + , subq_7.booking__ds_partitioned__extract_day + , subq_7.booking__ds_partitioned__extract_dow + , subq_7.booking__ds_partitioned__extract_doy + , subq_7.booking__paid_at__day + , subq_7.booking__paid_at__week + , subq_7.booking__paid_at__month + , subq_7.booking__paid_at__quarter + , subq_7.booking__paid_at__year + , subq_7.booking__paid_at__extract_year + , subq_7.booking__paid_at__extract_quarter + , subq_7.booking__paid_at__extract_month + , subq_7.booking__paid_at__extract_day + , subq_7.booking__paid_at__extract_dow + , subq_7.booking__paid_at__extract_doy + , subq_7.metric_time__day + , subq_7.metric_time__week + , subq_7.metric_time__month + , subq_7.metric_time__quarter + , subq_7.metric_time__year + , subq_7.metric_time__extract_year + , subq_7.metric_time__extract_quarter + , subq_7.metric_time__extract_month + , subq_7.metric_time__extract_day + , subq_7.metric_time__extract_dow + , subq_7.metric_time__extract_doy + , subq_7.listing + , subq_7.guest + , subq_7.host + , subq_7.booking__listing + , subq_7.booking__guest + , subq_7.booking__host + , subq_7.is_instant + , subq_7.booking__is_instant + , subq_7.bookings + , subq_7.instant_bookings + , subq_7.booking_value + , subq_7.max_booking_value + , subq_7.min_booking_value + , subq_7.bookers + , subq_7.average_booking_value + , subq_7.referred_bookings + , subq_7.median_booking_value + , subq_7.booking_value_p99 + , subq_7.discrete_booking_value_p99 + , subq_7.approximate_continuous_booking_value_p99 + , subq_7.approximate_discrete_booking_value_p99 + 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.ds_partitioned__day + , subq_6.ds_partitioned__week + , subq_6.ds_partitioned__month + , subq_6.ds_partitioned__quarter + , subq_6.ds_partitioned__year + , subq_6.ds_partitioned__extract_year + , subq_6.ds_partitioned__extract_quarter + , subq_6.ds_partitioned__extract_month + , subq_6.ds_partitioned__extract_day + , subq_6.ds_partitioned__extract_dow + , subq_6.ds_partitioned__extract_doy + , subq_6.paid_at__day + , subq_6.paid_at__week + , subq_6.paid_at__month + , subq_6.paid_at__quarter + , subq_6.paid_at__year + , subq_6.paid_at__extract_year + , subq_6.paid_at__extract_quarter + , subq_6.paid_at__extract_month + , subq_6.paid_at__extract_day + , subq_6.paid_at__extract_dow + , subq_6.paid_at__extract_doy + , subq_6.booking__ds__day + , subq_6.booking__ds__week + , subq_6.booking__ds__month + , subq_6.booking__ds__quarter + , subq_6.booking__ds__year + , subq_6.booking__ds__extract_year + , subq_6.booking__ds__extract_quarter + , subq_6.booking__ds__extract_month + , subq_6.booking__ds__extract_day + , subq_6.booking__ds__extract_dow + , subq_6.booking__ds__extract_doy + , subq_6.booking__ds_partitioned__day + , subq_6.booking__ds_partitioned__week + , subq_6.booking__ds_partitioned__month + , subq_6.booking__ds_partitioned__quarter + , subq_6.booking__ds_partitioned__year + , subq_6.booking__ds_partitioned__extract_year + , subq_6.booking__ds_partitioned__extract_quarter + , subq_6.booking__ds_partitioned__extract_month + , subq_6.booking__ds_partitioned__extract_day + , subq_6.booking__ds_partitioned__extract_dow + , subq_6.booking__ds_partitioned__extract_doy + , subq_6.booking__paid_at__day + , subq_6.booking__paid_at__week + , subq_6.booking__paid_at__month + , subq_6.booking__paid_at__quarter + , subq_6.booking__paid_at__year + , subq_6.booking__paid_at__extract_year + , subq_6.booking__paid_at__extract_quarter + , subq_6.booking__paid_at__extract_month + , subq_6.booking__paid_at__extract_day + , subq_6.booking__paid_at__extract_dow + , subq_6.booking__paid_at__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.listing + , subq_6.guest + , subq_6.host + , subq_6.booking__listing + , subq_6.booking__guest + , subq_6.booking__host + , subq_6.is_instant + , subq_6.booking__is_instant + , subq_6.bookings + , subq_6.instant_bookings + , subq_6.booking_value + , subq_6.max_booking_value + , subq_6.min_booking_value + , subq_6.bookers + , subq_6.average_booking_value + , subq_6.referred_bookings + , subq_6.median_booking_value + , subq_6.booking_value_p99 + , subq_6.discrete_booking_value_p99 + , subq_6.approximate_continuous_booking_value_p99 + , subq_6.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 + WHERE booking__is_instant + ) subq_10 + ) subq_11 + GROUP BY + subq_11.metric_time__day + ) subq_12 + ) subq_13 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_17.metric_time__day + , subq_17.max_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_16.metric_time__day + , MAX(subq_16.max_booking_value) AS max_booking_value + FROM ( + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + SELECT + subq_15.metric_time__day + , subq_15.max_booking_value + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_14.ds__day + , subq_14.ds__week + , subq_14.ds__month + , subq_14.ds__quarter + , subq_14.ds__year + , subq_14.ds__extract_year + , subq_14.ds__extract_quarter + , subq_14.ds__extract_month + , subq_14.ds__extract_day + , subq_14.ds__extract_dow + , subq_14.ds__extract_doy + , subq_14.ds_partitioned__day + , subq_14.ds_partitioned__week + , subq_14.ds_partitioned__month + , subq_14.ds_partitioned__quarter + , subq_14.ds_partitioned__year + , subq_14.ds_partitioned__extract_year + , subq_14.ds_partitioned__extract_quarter + , subq_14.ds_partitioned__extract_month + , subq_14.ds_partitioned__extract_day + , subq_14.ds_partitioned__extract_dow + , subq_14.ds_partitioned__extract_doy + , subq_14.paid_at__day + , subq_14.paid_at__week + , subq_14.paid_at__month + , subq_14.paid_at__quarter + , subq_14.paid_at__year + , subq_14.paid_at__extract_year + , subq_14.paid_at__extract_quarter + , subq_14.paid_at__extract_month + , subq_14.paid_at__extract_day + , subq_14.paid_at__extract_dow + , subq_14.paid_at__extract_doy + , subq_14.booking__ds__day + , subq_14.booking__ds__week + , subq_14.booking__ds__month + , subq_14.booking__ds__quarter + , subq_14.booking__ds__year + , subq_14.booking__ds__extract_year + , subq_14.booking__ds__extract_quarter + , subq_14.booking__ds__extract_month + , subq_14.booking__ds__extract_day + , subq_14.booking__ds__extract_dow + , subq_14.booking__ds__extract_doy + , subq_14.booking__ds_partitioned__day + , subq_14.booking__ds_partitioned__week + , subq_14.booking__ds_partitioned__month + , subq_14.booking__ds_partitioned__quarter + , subq_14.booking__ds_partitioned__year + , subq_14.booking__ds_partitioned__extract_year + , subq_14.booking__ds_partitioned__extract_quarter + , subq_14.booking__ds_partitioned__extract_month + , subq_14.booking__ds_partitioned__extract_day + , subq_14.booking__ds_partitioned__extract_dow + , subq_14.booking__ds_partitioned__extract_doy + , subq_14.booking__paid_at__day + , subq_14.booking__paid_at__week + , subq_14.booking__paid_at__month + , subq_14.booking__paid_at__quarter + , subq_14.booking__paid_at__year + , subq_14.booking__paid_at__extract_year + , subq_14.booking__paid_at__extract_quarter + , subq_14.booking__paid_at__extract_month + , subq_14.booking__paid_at__extract_day + , subq_14.booking__paid_at__extract_dow + , subq_14.booking__paid_at__extract_doy + , subq_14.ds__day AS metric_time__day + , subq_14.ds__week AS metric_time__week + , subq_14.ds__month AS metric_time__month + , subq_14.ds__quarter AS metric_time__quarter + , subq_14.ds__year AS metric_time__year + , subq_14.ds__extract_year AS metric_time__extract_year + , subq_14.ds__extract_quarter AS metric_time__extract_quarter + , subq_14.ds__extract_month AS metric_time__extract_month + , subq_14.ds__extract_day AS metric_time__extract_day + , subq_14.ds__extract_dow AS metric_time__extract_dow + , subq_14.ds__extract_doy AS metric_time__extract_doy + , subq_14.listing + , subq_14.guest + , subq_14.host + , subq_14.booking__listing + , subq_14.booking__guest + , subq_14.booking__host + , subq_14.is_instant + , subq_14.booking__is_instant + , subq_14.bookings + , subq_14.instant_bookings + , subq_14.booking_value + , subq_14.max_booking_value + , subq_14.min_booking_value + , subq_14.bookers + , subq_14.average_booking_value + , subq_14.referred_bookings + , subq_14.median_booking_value + , subq_14.booking_value_p99 + , subq_14.discrete_booking_value_p99 + , subq_14.approximate_continuous_booking_value_p99 + , subq_14.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + GROUP BY + subq_16.metric_time__day + ) subq_17 + ) subq_18 + ON + subq_13.metric_time__day = subq_18.metric_time__day + GROUP BY + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) +) subq_19 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..111a82caa8 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,58 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , CAST(average_booking_value AS DOUBLE) / CAST(NULLIF(max_booking_value, 0) AS DOUBLE) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) AS metric_time__day + , MAX(subq_27.average_booking_value) AS average_booking_value + , MAX(subq_32.max_booking_value) AS max_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , AVG(average_booking_value) AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + metric_time__day + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_21 + WHERE booking__is_instant + ) subq_23 + WHERE booking__is_instant + GROUP BY + metric_time__day + ) subq_27 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , MAX(booking_value) AS max_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_32 + ON + subq_27.metric_time__day = subq_32.metric_time__day + GROUP BY + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) +) subq_33 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_single_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_single_categorical_dimension_pushdown__plan0.sql new file mode 100644 index 0000000000..1a9c203c63 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_single_categorical_dimension_pushdown__plan0.sql @@ -0,0 +1,486 @@ +-- Compute Metrics via Expressions +SELECT + subq_17.listing__country_latest + , subq_17.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_16.listing__country_latest + , SUM(subq_16.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest'] + SELECT + subq_15.listing__country_latest + , subq_15.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_14.booking__is_instant + , subq_14.listing__country_latest + , subq_14.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] + SELECT + subq_13.booking__is_instant + , subq_13.listing__country_latest + , subq_13.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_9.listing AS listing + , subq_9.booking__is_instant AS booking__is_instant + , subq_12.country_latest AS listing__country_latest + , subq_9.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_8.listing + , subq_8.booking__is_instant + , subq_8.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.ds__day + , subq_7.ds__week + , subq_7.ds__month + , subq_7.ds__quarter + , subq_7.ds__year + , subq_7.ds__extract_year + , subq_7.ds__extract_quarter + , subq_7.ds__extract_month + , subq_7.ds__extract_day + , subq_7.ds__extract_dow + , subq_7.ds__extract_doy + , subq_7.ds_partitioned__day + , subq_7.ds_partitioned__week + , subq_7.ds_partitioned__month + , subq_7.ds_partitioned__quarter + , subq_7.ds_partitioned__year + , subq_7.ds_partitioned__extract_year + , subq_7.ds_partitioned__extract_quarter + , subq_7.ds_partitioned__extract_month + , subq_7.ds_partitioned__extract_day + , subq_7.ds_partitioned__extract_dow + , subq_7.ds_partitioned__extract_doy + , subq_7.paid_at__day + , subq_7.paid_at__week + , subq_7.paid_at__month + , subq_7.paid_at__quarter + , subq_7.paid_at__year + , subq_7.paid_at__extract_year + , subq_7.paid_at__extract_quarter + , subq_7.paid_at__extract_month + , subq_7.paid_at__extract_day + , subq_7.paid_at__extract_dow + , subq_7.paid_at__extract_doy + , subq_7.booking__ds__day + , subq_7.booking__ds__week + , subq_7.booking__ds__month + , subq_7.booking__ds__quarter + , subq_7.booking__ds__year + , subq_7.booking__ds__extract_year + , subq_7.booking__ds__extract_quarter + , subq_7.booking__ds__extract_month + , subq_7.booking__ds__extract_day + , subq_7.booking__ds__extract_dow + , subq_7.booking__ds__extract_doy + , subq_7.booking__ds_partitioned__day + , subq_7.booking__ds_partitioned__week + , subq_7.booking__ds_partitioned__month + , subq_7.booking__ds_partitioned__quarter + , subq_7.booking__ds_partitioned__year + , subq_7.booking__ds_partitioned__extract_year + , subq_7.booking__ds_partitioned__extract_quarter + , subq_7.booking__ds_partitioned__extract_month + , subq_7.booking__ds_partitioned__extract_day + , subq_7.booking__ds_partitioned__extract_dow + , subq_7.booking__ds_partitioned__extract_doy + , subq_7.booking__paid_at__day + , subq_7.booking__paid_at__week + , subq_7.booking__paid_at__month + , subq_7.booking__paid_at__quarter + , subq_7.booking__paid_at__year + , subq_7.booking__paid_at__extract_year + , subq_7.booking__paid_at__extract_quarter + , subq_7.booking__paid_at__extract_month + , subq_7.booking__paid_at__extract_day + , subq_7.booking__paid_at__extract_dow + , subq_7.booking__paid_at__extract_doy + , subq_7.metric_time__day + , subq_7.metric_time__week + , subq_7.metric_time__month + , subq_7.metric_time__quarter + , subq_7.metric_time__year + , subq_7.metric_time__extract_year + , subq_7.metric_time__extract_quarter + , subq_7.metric_time__extract_month + , subq_7.metric_time__extract_day + , subq_7.metric_time__extract_dow + , subq_7.metric_time__extract_doy + , subq_7.listing + , subq_7.guest + , subq_7.host + , subq_7.booking__listing + , subq_7.booking__guest + , subq_7.booking__host + , subq_7.is_instant + , subq_7.booking__is_instant + , subq_7.bookings + , subq_7.instant_bookings + , subq_7.booking_value + , subq_7.max_booking_value + , subq_7.min_booking_value + , subq_7.bookers + , subq_7.average_booking_value + , subq_7.referred_bookings + , subq_7.median_booking_value + , subq_7.booking_value_p99 + , subq_7.discrete_booking_value_p99 + , subq_7.approximate_continuous_booking_value_p99 + , subq_7.approximate_discrete_booking_value_p99 + 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.ds_partitioned__day + , subq_6.ds_partitioned__week + , subq_6.ds_partitioned__month + , subq_6.ds_partitioned__quarter + , subq_6.ds_partitioned__year + , subq_6.ds_partitioned__extract_year + , subq_6.ds_partitioned__extract_quarter + , subq_6.ds_partitioned__extract_month + , subq_6.ds_partitioned__extract_day + , subq_6.ds_partitioned__extract_dow + , subq_6.ds_partitioned__extract_doy + , subq_6.paid_at__day + , subq_6.paid_at__week + , subq_6.paid_at__month + , subq_6.paid_at__quarter + , subq_6.paid_at__year + , subq_6.paid_at__extract_year + , subq_6.paid_at__extract_quarter + , subq_6.paid_at__extract_month + , subq_6.paid_at__extract_day + , subq_6.paid_at__extract_dow + , subq_6.paid_at__extract_doy + , subq_6.booking__ds__day + , subq_6.booking__ds__week + , subq_6.booking__ds__month + , subq_6.booking__ds__quarter + , subq_6.booking__ds__year + , subq_6.booking__ds__extract_year + , subq_6.booking__ds__extract_quarter + , subq_6.booking__ds__extract_month + , subq_6.booking__ds__extract_day + , subq_6.booking__ds__extract_dow + , subq_6.booking__ds__extract_doy + , subq_6.booking__ds_partitioned__day + , subq_6.booking__ds_partitioned__week + , subq_6.booking__ds_partitioned__month + , subq_6.booking__ds_partitioned__quarter + , subq_6.booking__ds_partitioned__year + , subq_6.booking__ds_partitioned__extract_year + , subq_6.booking__ds_partitioned__extract_quarter + , subq_6.booking__ds_partitioned__extract_month + , subq_6.booking__ds_partitioned__extract_day + , subq_6.booking__ds_partitioned__extract_dow + , subq_6.booking__ds_partitioned__extract_doy + , subq_6.booking__paid_at__day + , subq_6.booking__paid_at__week + , subq_6.booking__paid_at__month + , subq_6.booking__paid_at__quarter + , subq_6.booking__paid_at__year + , subq_6.booking__paid_at__extract_year + , subq_6.booking__paid_at__extract_quarter + , subq_6.booking__paid_at__extract_month + , subq_6.booking__paid_at__extract_day + , subq_6.booking__paid_at__extract_dow + , subq_6.booking__paid_at__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.listing + , subq_6.guest + , subq_6.host + , subq_6.booking__listing + , subq_6.booking__guest + , subq_6.booking__host + , subq_6.is_instant + , subq_6.booking__is_instant + , subq_6.bookings + , subq_6.instant_bookings + , subq_6.booking_value + , subq_6.max_booking_value + , subq_6.min_booking_value + , subq_6.bookers + , subq_6.average_booking_value + , subq_6.referred_bookings + , subq_6.median_booking_value + , subq_6.booking_value_p99 + , subq_6.discrete_booking_value_p99 + , subq_6.approximate_continuous_booking_value_p99 + , subq_6.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['country_latest', 'listing'] + SELECT + subq_11.listing + , subq_11.country_latest + FROM ( + -- Metric Time Dimension 'ds' + 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.created_at__day + , subq_10.created_at__week + , subq_10.created_at__month + , subq_10.created_at__quarter + , subq_10.created_at__year + , subq_10.created_at__extract_year + , subq_10.created_at__extract_quarter + , subq_10.created_at__extract_month + , subq_10.created_at__extract_day + , subq_10.created_at__extract_dow + , subq_10.created_at__extract_doy + , subq_10.listing__ds__day + , subq_10.listing__ds__week + , subq_10.listing__ds__month + , subq_10.listing__ds__quarter + , subq_10.listing__ds__year + , subq_10.listing__ds__extract_year + , subq_10.listing__ds__extract_quarter + , subq_10.listing__ds__extract_month + , subq_10.listing__ds__extract_day + , subq_10.listing__ds__extract_dow + , subq_10.listing__ds__extract_doy + , subq_10.listing__created_at__day + , subq_10.listing__created_at__week + , subq_10.listing__created_at__month + , subq_10.listing__created_at__quarter + , subq_10.listing__created_at__year + , subq_10.listing__created_at__extract_year + , subq_10.listing__created_at__extract_quarter + , subq_10.listing__created_at__extract_month + , subq_10.listing__created_at__extract_day + , subq_10.listing__created_at__extract_dow + , subq_10.listing__created_at__extract_doy + , subq_10.ds__day AS metric_time__day + , subq_10.ds__week AS metric_time__week + , subq_10.ds__month AS metric_time__month + , subq_10.ds__quarter AS metric_time__quarter + , subq_10.ds__year AS metric_time__year + , subq_10.ds__extract_year AS metric_time__extract_year + , subq_10.ds__extract_quarter AS metric_time__extract_quarter + , subq_10.ds__extract_month AS metric_time__extract_month + , subq_10.ds__extract_day AS metric_time__extract_day + , subq_10.ds__extract_dow AS metric_time__extract_dow + , subq_10.ds__extract_doy AS metric_time__extract_doy + , subq_10.listing + , subq_10.user + , subq_10.listing__user + , subq_10.country_latest + , subq_10.is_lux_latest + , subq_10.capacity_latest + , subq_10.listing__country_latest + , subq_10.listing__is_lux_latest + , subq_10.listing__capacity_latest + , subq_10.listings + , subq_10.largest_listing + , subq_10.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_10 + ) subq_11 + ) subq_12 + ON + subq_9.listing = subq_12.listing + ) subq_13 + ) subq_14 + WHERE booking__is_instant + ) subq_15 + ) subq_16 + GROUP BY + subq_16.listing__country_latest +) subq_17 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_single_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_single_categorical_dimension_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..b0a46663de --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_single_categorical_dimension_pushdown__plan0_optimized.sql @@ -0,0 +1,40 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'listing__country_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] + SELECT + subq_21.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.country AS listing__country_latest + , subq_21.bookings AS bookings + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_19 + WHERE booking__is_instant + ) subq_21 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_21.listing = listings_latest_src_28000.listing_id +) subq_26 +WHERE booking__is_instant +GROUP BY + listing__country_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_skipped_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_skipped_pushdown__plan0.sql new file mode 100644 index 0000000000..02b7d9119b --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_skipped_pushdown__plan0.sql @@ -0,0 +1,387 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.listing__country_latest + , subq_10.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_9.listing__country_latest + , SUM(subq_9.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest'] + SELECT + subq_8.listing__country_latest + , subq_8.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.booking__is_instant + , subq_7.listing__country_latest + , subq_7.listing__is_lux_latest + , subq_7.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] + SELECT + subq_6.booking__is_instant + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_2.listing AS listing + , subq_2.booking__is_instant AS booking__is_instant + , subq_5.country_latest AS listing__country_latest + , subq_5.is_lux_latest AS listing__is_lux_latest + , subq_2.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_1.listing + , subq_1.booking__is_instant + , subq_1.bookings + 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.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.booking__paid_at__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.listing + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['country_latest', 'is_lux_latest', 'listing', 'listing'] + SELECT + subq_4.listing + , subq_4.country_latest + , subq_4.is_lux_latest + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.ds__day AS metric_time__day + , subq_3.ds__week AS metric_time__week + , subq_3.ds__month AS metric_time__month + , subq_3.ds__quarter AS metric_time__quarter + , subq_3.ds__year AS metric_time__year + , subq_3.ds__extract_year AS metric_time__extract_year + , subq_3.ds__extract_quarter AS metric_time__extract_quarter + , subq_3.ds__extract_month AS metric_time__extract_month + , subq_3.ds__extract_day AS metric_time__extract_day + , subq_3.ds__extract_dow AS metric_time__extract_dow + , subq_3.ds__extract_doy AS metric_time__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_3 + ) subq_4 + ) subq_5 + ON + subq_2.listing = subq_5.listing + ) subq_6 + ) subq_7 + WHERE booking__is_instant OR listing__is_lux_latest + ) subq_8 + ) subq_9 + GROUP BY + subq_9.listing__country_latest +) subq_10 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_skipped_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_skipped_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..be31b01767 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_skipped_pushdown__plan0_optimized.sql @@ -0,0 +1,33 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'listing__country_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] + SELECT + subq_13.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , subq_13.bookings AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_13.listing = listings_latest_src_28000.listing_id +) subq_18 +WHERE booking__is_instant OR listing__is_lux_latest +GROUP BY + listing__country_latest diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_distinct_values__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_distinct_values__plan0.sql index 64eedb3232..f699c35c7d 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_distinct_values__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_distinct_values__plan0.sql @@ -1,134 +1,195 @@ -- Order By ['listing__country_latest'] Limit 100 SELECT - subq_2.listing__country_latest + subq_5.listing__country_latest FROM ( -- Pass Only Elements: ['listing__country_latest',] SELECT - subq_1.listing__country_latest + subq_4.listing__country_latest FROM ( -- Constrain Output with WHERE 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.created_at__day - , subq_0.created_at__week - , subq_0.created_at__month - , subq_0.created_at__quarter - , subq_0.created_at__year - , subq_0.created_at__extract_year - , subq_0.created_at__extract_quarter - , subq_0.created_at__extract_month - , subq_0.created_at__extract_day - , subq_0.created_at__extract_dow - , subq_0.created_at__extract_doy - , subq_0.listing__ds__day - , subq_0.listing__ds__week - , subq_0.listing__ds__month - , subq_0.listing__ds__quarter - , subq_0.listing__ds__year - , subq_0.listing__ds__extract_year - , subq_0.listing__ds__extract_quarter - , subq_0.listing__ds__extract_month - , subq_0.listing__ds__extract_day - , subq_0.listing__ds__extract_dow - , subq_0.listing__ds__extract_doy - , subq_0.listing__created_at__day - , subq_0.listing__created_at__week - , subq_0.listing__created_at__month - , subq_0.listing__created_at__quarter - , subq_0.listing__created_at__year - , subq_0.listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month - , subq_0.listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow - , subq_0.listing__created_at__extract_doy - , subq_0.listing - , subq_0.user - , subq_0.listing__user - , subq_0.country_latest - , subq_0.is_lux_latest - , subq_0.capacity_latest - , subq_0.listing__country_latest - , subq_0.listing__is_lux_latest - , subq_0.listing__capacity_latest - , subq_0.listings - , subq_0.largest_listing - , subq_0.smallest_listing + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing FROM ( - -- Read Elements From Semantic Model 'listings_latest' + -- Constrain Output with WHERE SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS ds__day - , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS ds__week - , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS ds__month - , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS ds__quarter - , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS ds__extract_dow - , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS created_at__day - , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS created_at__week - , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS created_at__month - , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS created_at__quarter - , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS created_at__extract_dow - , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS listing__ds__day - , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS listing__ds__week - , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS listing__ds__month - , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS listing__ds__quarter - , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS listing__ds__extract_dow - , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS listing__created_at__day - , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS listing__created_at__week - , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS listing__created_at__month - , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS listing__created_at__quarter - , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS listing__created_at__extract_dow - , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , listings_latest_src_28000.user_id AS user - , listings_latest_src_28000.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_0 + subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.created_at__day + , subq_2.created_at__week + , subq_2.created_at__month + , subq_2.created_at__quarter + , subq_2.created_at__year + , subq_2.created_at__extract_year + , subq_2.created_at__extract_quarter + , subq_2.created_at__extract_month + , subq_2.created_at__extract_day + , subq_2.created_at__extract_dow + , subq_2.created_at__extract_doy + , subq_2.listing__ds__day + , subq_2.listing__ds__week + , subq_2.listing__ds__month + , subq_2.listing__ds__quarter + , subq_2.listing__ds__year + , subq_2.listing__ds__extract_year + , subq_2.listing__ds__extract_quarter + , subq_2.listing__ds__extract_month + , subq_2.listing__ds__extract_day + , subq_2.listing__ds__extract_dow + , subq_2.listing__ds__extract_doy + , subq_2.listing__created_at__day + , subq_2.listing__created_at__week + , subq_2.listing__created_at__month + , subq_2.listing__created_at__quarter + , subq_2.listing__created_at__year + , subq_2.listing__created_at__extract_year + , subq_2.listing__created_at__extract_quarter + , subq_2.listing__created_at__extract_month + , subq_2.listing__created_at__extract_day + , subq_2.listing__created_at__extract_dow + , subq_2.listing__created_at__extract_doy + , subq_2.listing + , subq_2.user + , subq_2.listing__user + , subq_2.country_latest + , subq_2.is_lux_latest + , subq_2.capacity_latest + , subq_2.listing__country_latest + , subq_2.listing__is_lux_latest + , subq_2.listing__capacity_latest + , subq_2.listings + , subq_2.largest_listing + , subq_2.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS ds__day + , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS ds__week + , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS ds__month + , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS ds__quarter + , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS created_at__day + , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS created_at__week + , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS created_at__month + , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS created_at__quarter + , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS created_at__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS listing__ds__day + , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS listing__ds__week + , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS listing__ds__month + , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS listing__ds__quarter + , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS listing__ds__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC(listings_latest_src_28000.created_at, day) AS listing__created_at__day + , DATE_TRUNC(listings_latest_src_28000.created_at, isoweek) AS listing__created_at__week + , DATE_TRUNC(listings_latest_src_28000.created_at, month) AS listing__created_at__month + , DATE_TRUNC(listings_latest_src_28000.created_at, quarter) AS listing__created_at__quarter + , DATE_TRUNC(listings_latest_src_28000.created_at, year) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS listing__created_at__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_2 + WHERE listing__country_latest = 'us' + ) subq_3 WHERE listing__country_latest = 'us' - ) subq_1 + ) subq_4 GROUP BY listing__country_latest -) subq_2 -ORDER BY subq_2.listing__country_latest DESC +) subq_5 +ORDER BY subq_5.listing__country_latest DESC LIMIT 100 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_distinct_values__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_distinct_values__plan0_optimized.sql index 1653ada5bd..76e6591b6c 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_distinct_values__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_distinct_values__plan0_optimized.sql @@ -4,11 +4,17 @@ SELECT listing__country_latest FROM ( - -- Read Elements From Semantic Model 'listings_latest' + -- Constrain Output with WHERE SELECT - country AS listing__country_latest - FROM ***************************.dim_listings_latest listings_latest_src_28000 -) subq_3 + listing__country_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + country AS listing__country_latest + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_6 + WHERE listing__country_latest = 'us' +) subq_7 WHERE listing__country_latest = 'us' GROUP BY listing__country_latest diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_reused_measure__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_reused_measure__plan0.sql index 548a1b6a4b..405416b013 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_reused_measure__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_reused_measure__plan0.sql @@ -1,359 +1,462 @@ -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day - , CAST(subq_12.booking_value_with_is_instant_constraint AS FLOAT64) / CAST(NULLIF(subq_12.booking_value, 0) AS FLOAT64) AS instant_booking_value_ratio + subq_19.metric_time__day + , CAST(subq_19.booking_value_with_is_instant_constraint AS FLOAT64) / CAST(NULLIF(subq_19.booking_value, 0) AS FLOAT64) AS instant_booking_value_ratio FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) AS metric_time__day - , MAX(subq_6.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_11.booking_value) AS booking_value + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) AS metric_time__day + , MAX(subq_13.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_18.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.booking_value AS booking_value_with_is_instant_constraint + subq_12.metric_time__day + , subq_12.booking_value AS booking_value_with_is_instant_constraint FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.booking_value) AS booking_value + subq_11.metric_time__day + , SUM(subq_11.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.booking_value + subq_10.metric_time__day + , subq_10.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.booking_value + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.booking_value + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE 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.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.booking__paid_at__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.listing - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_7.ds__day + , subq_7.ds__week + , subq_7.ds__month + , subq_7.ds__quarter + , subq_7.ds__year + , subq_7.ds__extract_year + , subq_7.ds__extract_quarter + , subq_7.ds__extract_month + , subq_7.ds__extract_day + , subq_7.ds__extract_dow + , subq_7.ds__extract_doy + , subq_7.ds_partitioned__day + , subq_7.ds_partitioned__week + , subq_7.ds_partitioned__month + , subq_7.ds_partitioned__quarter + , subq_7.ds_partitioned__year + , subq_7.ds_partitioned__extract_year + , subq_7.ds_partitioned__extract_quarter + , subq_7.ds_partitioned__extract_month + , subq_7.ds_partitioned__extract_day + , subq_7.ds_partitioned__extract_dow + , subq_7.ds_partitioned__extract_doy + , subq_7.paid_at__day + , subq_7.paid_at__week + , subq_7.paid_at__month + , subq_7.paid_at__quarter + , subq_7.paid_at__year + , subq_7.paid_at__extract_year + , subq_7.paid_at__extract_quarter + , subq_7.paid_at__extract_month + , subq_7.paid_at__extract_day + , subq_7.paid_at__extract_dow + , subq_7.paid_at__extract_doy + , subq_7.booking__ds__day + , subq_7.booking__ds__week + , subq_7.booking__ds__month + , subq_7.booking__ds__quarter + , subq_7.booking__ds__year + , subq_7.booking__ds__extract_year + , subq_7.booking__ds__extract_quarter + , subq_7.booking__ds__extract_month + , subq_7.booking__ds__extract_day + , subq_7.booking__ds__extract_dow + , subq_7.booking__ds__extract_doy + , subq_7.booking__ds_partitioned__day + , subq_7.booking__ds_partitioned__week + , subq_7.booking__ds_partitioned__month + , subq_7.booking__ds_partitioned__quarter + , subq_7.booking__ds_partitioned__year + , subq_7.booking__ds_partitioned__extract_year + , subq_7.booking__ds_partitioned__extract_quarter + , subq_7.booking__ds_partitioned__extract_month + , subq_7.booking__ds_partitioned__extract_day + , subq_7.booking__ds_partitioned__extract_dow + , subq_7.booking__ds_partitioned__extract_doy + , subq_7.booking__paid_at__day + , subq_7.booking__paid_at__week + , subq_7.booking__paid_at__month + , subq_7.booking__paid_at__quarter + , subq_7.booking__paid_at__year + , subq_7.booking__paid_at__extract_year + , subq_7.booking__paid_at__extract_quarter + , subq_7.booking__paid_at__extract_month + , subq_7.booking__paid_at__extract_day + , subq_7.booking__paid_at__extract_dow + , subq_7.booking__paid_at__extract_doy + , subq_7.metric_time__day + , subq_7.metric_time__week + , subq_7.metric_time__month + , subq_7.metric_time__quarter + , subq_7.metric_time__year + , subq_7.metric_time__extract_year + , subq_7.metric_time__extract_quarter + , subq_7.metric_time__extract_month + , subq_7.metric_time__extract_day + , subq_7.metric_time__extract_dow + , subq_7.metric_time__extract_doy + , subq_7.listing + , subq_7.guest + , subq_7.host + , subq_7.booking__listing + , subq_7.booking__guest + , subq_7.booking__host + , subq_7.is_instant + , subq_7.booking__is_instant + , subq_7.bookings + , subq_7.instant_bookings + , subq_7.booking_value + , subq_7.max_booking_value + , subq_7.min_booking_value + , subq_7.bookers + , subq_7.average_booking_value + , subq_7.referred_bookings + , subq_7.median_booking_value + , subq_7.booking_value_p99 + , subq_7.discrete_booking_value_p99 + , subq_7.approximate_continuous_booking_value_p99 + , subq_7.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC(bookings_source_src_28000.ds, day) AS ds__day - , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS ds__week - , DATE_TRUNC(bookings_source_src_28000.ds, month) AS ds__month - , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS ds__quarter - , DATE_TRUNC(bookings_source_src_28000.ds, year) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS ds__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS ds_partitioned__day - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS ds_partitioned__week - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS ds_partitioned__month - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS ds_partitioned__quarter - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS ds_partitioned__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS paid_at__day - , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS paid_at__week - , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS paid_at__month - , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS paid_at__quarter - , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS paid_at__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC(bookings_source_src_28000.ds, day) AS booking__ds__day - , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS booking__ds__week - , DATE_TRUNC(bookings_source_src_28000.ds, month) AS booking__ds__month - , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS booking__ds__quarter - , DATE_TRUNC(bookings_source_src_28000.ds, year) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS booking__ds__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS booking__ds_partitioned__day - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS booking__ds_partitioned__week - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS booking__ds_partitioned__month - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS booking__ds_partitioned__quarter - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS booking__ds_partitioned__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS booking__paid_at__day - , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS booking__paid_at__week - , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS booking__paid_at__month - , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS booking__paid_at__quarter - , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS booking__paid_at__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + 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.ds_partitioned__day + , subq_6.ds_partitioned__week + , subq_6.ds_partitioned__month + , subq_6.ds_partitioned__quarter + , subq_6.ds_partitioned__year + , subq_6.ds_partitioned__extract_year + , subq_6.ds_partitioned__extract_quarter + , subq_6.ds_partitioned__extract_month + , subq_6.ds_partitioned__extract_day + , subq_6.ds_partitioned__extract_dow + , subq_6.ds_partitioned__extract_doy + , subq_6.paid_at__day + , subq_6.paid_at__week + , subq_6.paid_at__month + , subq_6.paid_at__quarter + , subq_6.paid_at__year + , subq_6.paid_at__extract_year + , subq_6.paid_at__extract_quarter + , subq_6.paid_at__extract_month + , subq_6.paid_at__extract_day + , subq_6.paid_at__extract_dow + , subq_6.paid_at__extract_doy + , subq_6.booking__ds__day + , subq_6.booking__ds__week + , subq_6.booking__ds__month + , subq_6.booking__ds__quarter + , subq_6.booking__ds__year + , subq_6.booking__ds__extract_year + , subq_6.booking__ds__extract_quarter + , subq_6.booking__ds__extract_month + , subq_6.booking__ds__extract_day + , subq_6.booking__ds__extract_dow + , subq_6.booking__ds__extract_doy + , subq_6.booking__ds_partitioned__day + , subq_6.booking__ds_partitioned__week + , subq_6.booking__ds_partitioned__month + , subq_6.booking__ds_partitioned__quarter + , subq_6.booking__ds_partitioned__year + , subq_6.booking__ds_partitioned__extract_year + , subq_6.booking__ds_partitioned__extract_quarter + , subq_6.booking__ds_partitioned__extract_month + , subq_6.booking__ds_partitioned__extract_day + , subq_6.booking__ds_partitioned__extract_dow + , subq_6.booking__ds_partitioned__extract_doy + , subq_6.booking__paid_at__day + , subq_6.booking__paid_at__week + , subq_6.booking__paid_at__month + , subq_6.booking__paid_at__quarter + , subq_6.booking__paid_at__year + , subq_6.booking__paid_at__extract_year + , subq_6.booking__paid_at__extract_quarter + , subq_6.booking__paid_at__extract_month + , subq_6.booking__paid_at__extract_day + , subq_6.booking__paid_at__extract_dow + , subq_6.booking__paid_at__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.listing + , subq_6.guest + , subq_6.host + , subq_6.booking__listing + , subq_6.booking__guest + , subq_6.booking__host + , subq_6.is_instant + , subq_6.booking__is_instant + , subq_6.bookings + , subq_6.instant_bookings + , subq_6.booking_value + , subq_6.max_booking_value + , subq_6.min_booking_value + , subq_6.bookers + , subq_6.average_booking_value + , subq_6.referred_bookings + , subq_6.median_booking_value + , subq_6.booking_value_p99 + , subq_6.discrete_booking_value_p99 + , subq_6.approximate_continuous_booking_value_p99 + , subq_6.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC(bookings_source_src_28000.ds, day) AS ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC(bookings_source_src_28000.ds, day) AS booking__ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS booking__ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS booking__ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS booking__ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS booking__ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS booking__ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS booking__ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS booking__ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS booking__ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS booking__ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS booking__paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS booking__paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS booking__paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS booking__paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS booking__paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 WHERE booking__is_instant - ) subq_3 - ) subq_4 + ) subq_10 + ) subq_11 GROUP BY metric_time__day - ) subq_5 - ) subq_6 + ) subq_12 + ) subq_13 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day - , subq_10.booking_value + subq_17.metric_time__day + , subq_17.booking_value FROM ( -- Aggregate Measures SELECT - subq_9.metric_time__day - , SUM(subq_9.booking_value) AS booking_value + subq_16.metric_time__day + , SUM(subq_16.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'metric_time__day'] SELECT - subq_8.metric_time__day - , subq_8.booking_value + subq_15.metric_time__day + , subq_15.booking_value FROM ( -- Metric Time Dimension 'ds' SELECT - subq_7.ds__day - , subq_7.ds__week - , subq_7.ds__month - , subq_7.ds__quarter - , subq_7.ds__year - , subq_7.ds__extract_year - , subq_7.ds__extract_quarter - , subq_7.ds__extract_month - , subq_7.ds__extract_day - , subq_7.ds__extract_dow - , subq_7.ds__extract_doy - , subq_7.ds_partitioned__day - , subq_7.ds_partitioned__week - , subq_7.ds_partitioned__month - , subq_7.ds_partitioned__quarter - , subq_7.ds_partitioned__year - , subq_7.ds_partitioned__extract_year - , subq_7.ds_partitioned__extract_quarter - , subq_7.ds_partitioned__extract_month - , subq_7.ds_partitioned__extract_day - , subq_7.ds_partitioned__extract_dow - , subq_7.ds_partitioned__extract_doy - , subq_7.paid_at__day - , subq_7.paid_at__week - , subq_7.paid_at__month - , subq_7.paid_at__quarter - , subq_7.paid_at__year - , subq_7.paid_at__extract_year - , subq_7.paid_at__extract_quarter - , subq_7.paid_at__extract_month - , subq_7.paid_at__extract_day - , subq_7.paid_at__extract_dow - , subq_7.paid_at__extract_doy - , subq_7.booking__ds__day - , subq_7.booking__ds__week - , subq_7.booking__ds__month - , subq_7.booking__ds__quarter - , subq_7.booking__ds__year - , subq_7.booking__ds__extract_year - , subq_7.booking__ds__extract_quarter - , subq_7.booking__ds__extract_month - , subq_7.booking__ds__extract_day - , subq_7.booking__ds__extract_dow - , subq_7.booking__ds__extract_doy - , subq_7.booking__ds_partitioned__day - , subq_7.booking__ds_partitioned__week - , subq_7.booking__ds_partitioned__month - , subq_7.booking__ds_partitioned__quarter - , subq_7.booking__ds_partitioned__year - , subq_7.booking__ds_partitioned__extract_year - , subq_7.booking__ds_partitioned__extract_quarter - , subq_7.booking__ds_partitioned__extract_month - , subq_7.booking__ds_partitioned__extract_day - , subq_7.booking__ds_partitioned__extract_dow - , subq_7.booking__ds_partitioned__extract_doy - , subq_7.booking__paid_at__day - , subq_7.booking__paid_at__week - , subq_7.booking__paid_at__month - , subq_7.booking__paid_at__quarter - , subq_7.booking__paid_at__year - , subq_7.booking__paid_at__extract_year - , subq_7.booking__paid_at__extract_quarter - , subq_7.booking__paid_at__extract_month - , subq_7.booking__paid_at__extract_day - , subq_7.booking__paid_at__extract_dow - , subq_7.booking__paid_at__extract_doy - , subq_7.ds__day AS metric_time__day - , subq_7.ds__week AS metric_time__week - , subq_7.ds__month AS metric_time__month - , subq_7.ds__quarter AS metric_time__quarter - , subq_7.ds__year AS metric_time__year - , subq_7.ds__extract_year AS metric_time__extract_year - , subq_7.ds__extract_quarter AS metric_time__extract_quarter - , subq_7.ds__extract_month AS metric_time__extract_month - , subq_7.ds__extract_day AS metric_time__extract_day - , subq_7.ds__extract_dow AS metric_time__extract_dow - , subq_7.ds__extract_doy AS metric_time__extract_doy - , subq_7.listing - , subq_7.guest - , subq_7.host - , subq_7.booking__listing - , subq_7.booking__guest - , subq_7.booking__host - , subq_7.is_instant - , subq_7.booking__is_instant - , subq_7.bookings - , subq_7.instant_bookings - , subq_7.booking_value - , subq_7.max_booking_value - , subq_7.min_booking_value - , subq_7.bookers - , subq_7.average_booking_value - , subq_7.referred_bookings - , subq_7.median_booking_value - , subq_7.booking_value_p99 - , subq_7.discrete_booking_value_p99 - , subq_7.approximate_continuous_booking_value_p99 - , subq_7.approximate_discrete_booking_value_p99 + subq_14.ds__day + , subq_14.ds__week + , subq_14.ds__month + , subq_14.ds__quarter + , subq_14.ds__year + , subq_14.ds__extract_year + , subq_14.ds__extract_quarter + , subq_14.ds__extract_month + , subq_14.ds__extract_day + , subq_14.ds__extract_dow + , subq_14.ds__extract_doy + , subq_14.ds_partitioned__day + , subq_14.ds_partitioned__week + , subq_14.ds_partitioned__month + , subq_14.ds_partitioned__quarter + , subq_14.ds_partitioned__year + , subq_14.ds_partitioned__extract_year + , subq_14.ds_partitioned__extract_quarter + , subq_14.ds_partitioned__extract_month + , subq_14.ds_partitioned__extract_day + , subq_14.ds_partitioned__extract_dow + , subq_14.ds_partitioned__extract_doy + , subq_14.paid_at__day + , subq_14.paid_at__week + , subq_14.paid_at__month + , subq_14.paid_at__quarter + , subq_14.paid_at__year + , subq_14.paid_at__extract_year + , subq_14.paid_at__extract_quarter + , subq_14.paid_at__extract_month + , subq_14.paid_at__extract_day + , subq_14.paid_at__extract_dow + , subq_14.paid_at__extract_doy + , subq_14.booking__ds__day + , subq_14.booking__ds__week + , subq_14.booking__ds__month + , subq_14.booking__ds__quarter + , subq_14.booking__ds__year + , subq_14.booking__ds__extract_year + , subq_14.booking__ds__extract_quarter + , subq_14.booking__ds__extract_month + , subq_14.booking__ds__extract_day + , subq_14.booking__ds__extract_dow + , subq_14.booking__ds__extract_doy + , subq_14.booking__ds_partitioned__day + , subq_14.booking__ds_partitioned__week + , subq_14.booking__ds_partitioned__month + , subq_14.booking__ds_partitioned__quarter + , subq_14.booking__ds_partitioned__year + , subq_14.booking__ds_partitioned__extract_year + , subq_14.booking__ds_partitioned__extract_quarter + , subq_14.booking__ds_partitioned__extract_month + , subq_14.booking__ds_partitioned__extract_day + , subq_14.booking__ds_partitioned__extract_dow + , subq_14.booking__ds_partitioned__extract_doy + , subq_14.booking__paid_at__day + , subq_14.booking__paid_at__week + , subq_14.booking__paid_at__month + , subq_14.booking__paid_at__quarter + , subq_14.booking__paid_at__year + , subq_14.booking__paid_at__extract_year + , subq_14.booking__paid_at__extract_quarter + , subq_14.booking__paid_at__extract_month + , subq_14.booking__paid_at__extract_day + , subq_14.booking__paid_at__extract_dow + , subq_14.booking__paid_at__extract_doy + , subq_14.ds__day AS metric_time__day + , subq_14.ds__week AS metric_time__week + , subq_14.ds__month AS metric_time__month + , subq_14.ds__quarter AS metric_time__quarter + , subq_14.ds__year AS metric_time__year + , subq_14.ds__extract_year AS metric_time__extract_year + , subq_14.ds__extract_quarter AS metric_time__extract_quarter + , subq_14.ds__extract_month AS metric_time__extract_month + , subq_14.ds__extract_day AS metric_time__extract_day + , subq_14.ds__extract_dow AS metric_time__extract_dow + , subq_14.ds__extract_doy AS metric_time__extract_doy + , subq_14.listing + , subq_14.guest + , subq_14.host + , subq_14.booking__listing + , subq_14.booking__guest + , subq_14.booking__host + , subq_14.is_instant + , subq_14.booking__is_instant + , subq_14.bookings + , subq_14.instant_bookings + , subq_14.booking_value + , subq_14.max_booking_value + , subq_14.min_booking_value + , subq_14.bookers + , subq_14.average_booking_value + , subq_14.referred_bookings + , subq_14.median_booking_value + , subq_14.booking_value_p99 + , subq_14.discrete_booking_value_p99 + , subq_14.approximate_continuous_booking_value_p99 + , subq_14.approximate_discrete_booking_value_p99 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -446,15 +549,15 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_7 - ) subq_8 - ) subq_9 + ) subq_14 + ) subq_15 + ) subq_16 GROUP BY metric_time__day - ) subq_10 - ) subq_11 + ) subq_17 + ) subq_18 ON - subq_6.metric_time__day = subq_11.metric_time__day + subq_13.metric_time__day = subq_18.metric_time__day GROUP BY metric_time__day -) subq_12 +) subq_19 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_reused_measure__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_reused_measure__plan0_optimized.sql index fd149da3a6..899f5800d3 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_reused_measure__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_reused_measure__plan0_optimized.sql @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) AS metric_time__day - , MAX(subq_19.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_24.booking_value) AS booking_value + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) AS metric_time__day + , MAX(subq_27.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_32.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'metric_time__day'] @@ -17,19 +17,27 @@ FROM ( metric_time__day , SUM(booking_value) AS booking_value_with_is_instant_constraint FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC(ds, day) AS metric_time__day - , is_instant AS booking__is_instant + metric_time__day + , booking__is_instant , booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_15 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC(ds, day) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_21 + WHERE booking__is_instant + ) subq_23 WHERE booking__is_instant GROUP BY metric_time__day - ) subq_19 + ) subq_27 FULL OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -42,9 +50,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY metric_time__day - ) subq_24 + ) subq_32 ON - subq_19.metric_time__day = subq_24.metric_time__day + subq_27.metric_time__day = subq_32.metric_time__day GROUP BY metric_time__day -) subq_25 +) subq_33 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_single_expr_and_alias__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_single_expr_and_alias__plan0.sql index ad8431c956..a27d1af961 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_single_expr_and_alias__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_single_expr_and_alias__plan0.sql @@ -1,234 +1,337 @@ -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day + subq_13.metric_time__day , delayed_bookings * 2 AS double_counted_delayed_bookings FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.bookings AS delayed_bookings + subq_12.metric_time__day + , subq_12.bookings AS delayed_bookings FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.bookings) AS bookings + subq_11.metric_time__day + , SUM(subq_11.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.bookings + subq_10.metric_time__day + , subq_10.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE 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.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.booking__paid_at__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.listing - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_7.ds__day + , subq_7.ds__week + , subq_7.ds__month + , subq_7.ds__quarter + , subq_7.ds__year + , subq_7.ds__extract_year + , subq_7.ds__extract_quarter + , subq_7.ds__extract_month + , subq_7.ds__extract_day + , subq_7.ds__extract_dow + , subq_7.ds__extract_doy + , subq_7.ds_partitioned__day + , subq_7.ds_partitioned__week + , subq_7.ds_partitioned__month + , subq_7.ds_partitioned__quarter + , subq_7.ds_partitioned__year + , subq_7.ds_partitioned__extract_year + , subq_7.ds_partitioned__extract_quarter + , subq_7.ds_partitioned__extract_month + , subq_7.ds_partitioned__extract_day + , subq_7.ds_partitioned__extract_dow + , subq_7.ds_partitioned__extract_doy + , subq_7.paid_at__day + , subq_7.paid_at__week + , subq_7.paid_at__month + , subq_7.paid_at__quarter + , subq_7.paid_at__year + , subq_7.paid_at__extract_year + , subq_7.paid_at__extract_quarter + , subq_7.paid_at__extract_month + , subq_7.paid_at__extract_day + , subq_7.paid_at__extract_dow + , subq_7.paid_at__extract_doy + , subq_7.booking__ds__day + , subq_7.booking__ds__week + , subq_7.booking__ds__month + , subq_7.booking__ds__quarter + , subq_7.booking__ds__year + , subq_7.booking__ds__extract_year + , subq_7.booking__ds__extract_quarter + , subq_7.booking__ds__extract_month + , subq_7.booking__ds__extract_day + , subq_7.booking__ds__extract_dow + , subq_7.booking__ds__extract_doy + , subq_7.booking__ds_partitioned__day + , subq_7.booking__ds_partitioned__week + , subq_7.booking__ds_partitioned__month + , subq_7.booking__ds_partitioned__quarter + , subq_7.booking__ds_partitioned__year + , subq_7.booking__ds_partitioned__extract_year + , subq_7.booking__ds_partitioned__extract_quarter + , subq_7.booking__ds_partitioned__extract_month + , subq_7.booking__ds_partitioned__extract_day + , subq_7.booking__ds_partitioned__extract_dow + , subq_7.booking__ds_partitioned__extract_doy + , subq_7.booking__paid_at__day + , subq_7.booking__paid_at__week + , subq_7.booking__paid_at__month + , subq_7.booking__paid_at__quarter + , subq_7.booking__paid_at__year + , subq_7.booking__paid_at__extract_year + , subq_7.booking__paid_at__extract_quarter + , subq_7.booking__paid_at__extract_month + , subq_7.booking__paid_at__extract_day + , subq_7.booking__paid_at__extract_dow + , subq_7.booking__paid_at__extract_doy + , subq_7.metric_time__day + , subq_7.metric_time__week + , subq_7.metric_time__month + , subq_7.metric_time__quarter + , subq_7.metric_time__year + , subq_7.metric_time__extract_year + , subq_7.metric_time__extract_quarter + , subq_7.metric_time__extract_month + , subq_7.metric_time__extract_day + , subq_7.metric_time__extract_dow + , subq_7.metric_time__extract_doy + , subq_7.listing + , subq_7.guest + , subq_7.host + , subq_7.booking__listing + , subq_7.booking__guest + , subq_7.booking__host + , subq_7.is_instant + , subq_7.booking__is_instant + , subq_7.bookings + , subq_7.instant_bookings + , subq_7.booking_value + , subq_7.max_booking_value + , subq_7.min_booking_value + , subq_7.bookers + , subq_7.average_booking_value + , subq_7.referred_bookings + , subq_7.median_booking_value + , subq_7.booking_value_p99 + , subq_7.discrete_booking_value_p99 + , subq_7.approximate_continuous_booking_value_p99 + , subq_7.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC(bookings_source_src_28000.ds, day) AS ds__day - , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS ds__week - , DATE_TRUNC(bookings_source_src_28000.ds, month) AS ds__month - , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS ds__quarter - , DATE_TRUNC(bookings_source_src_28000.ds, year) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS ds__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS ds_partitioned__day - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS ds_partitioned__week - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS ds_partitioned__month - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS ds_partitioned__quarter - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS ds_partitioned__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS paid_at__day - , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS paid_at__week - , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS paid_at__month - , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS paid_at__quarter - , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS paid_at__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC(bookings_source_src_28000.ds, day) AS booking__ds__day - , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS booking__ds__week - , DATE_TRUNC(bookings_source_src_28000.ds, month) AS booking__ds__month - , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS booking__ds__quarter - , DATE_TRUNC(bookings_source_src_28000.ds, year) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS booking__ds__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS booking__ds_partitioned__day - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS booking__ds_partitioned__week - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS booking__ds_partitioned__month - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS booking__ds_partitioned__quarter - , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS booking__ds_partitioned__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS booking__paid_at__day - , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS booking__paid_at__week - , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS booking__paid_at__month - , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS booking__paid_at__quarter - , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS booking__paid_at__extract_dow - , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + 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.ds_partitioned__day + , subq_6.ds_partitioned__week + , subq_6.ds_partitioned__month + , subq_6.ds_partitioned__quarter + , subq_6.ds_partitioned__year + , subq_6.ds_partitioned__extract_year + , subq_6.ds_partitioned__extract_quarter + , subq_6.ds_partitioned__extract_month + , subq_6.ds_partitioned__extract_day + , subq_6.ds_partitioned__extract_dow + , subq_6.ds_partitioned__extract_doy + , subq_6.paid_at__day + , subq_6.paid_at__week + , subq_6.paid_at__month + , subq_6.paid_at__quarter + , subq_6.paid_at__year + , subq_6.paid_at__extract_year + , subq_6.paid_at__extract_quarter + , subq_6.paid_at__extract_month + , subq_6.paid_at__extract_day + , subq_6.paid_at__extract_dow + , subq_6.paid_at__extract_doy + , subq_6.booking__ds__day + , subq_6.booking__ds__week + , subq_6.booking__ds__month + , subq_6.booking__ds__quarter + , subq_6.booking__ds__year + , subq_6.booking__ds__extract_year + , subq_6.booking__ds__extract_quarter + , subq_6.booking__ds__extract_month + , subq_6.booking__ds__extract_day + , subq_6.booking__ds__extract_dow + , subq_6.booking__ds__extract_doy + , subq_6.booking__ds_partitioned__day + , subq_6.booking__ds_partitioned__week + , subq_6.booking__ds_partitioned__month + , subq_6.booking__ds_partitioned__quarter + , subq_6.booking__ds_partitioned__year + , subq_6.booking__ds_partitioned__extract_year + , subq_6.booking__ds_partitioned__extract_quarter + , subq_6.booking__ds_partitioned__extract_month + , subq_6.booking__ds_partitioned__extract_day + , subq_6.booking__ds_partitioned__extract_dow + , subq_6.booking__ds_partitioned__extract_doy + , subq_6.booking__paid_at__day + , subq_6.booking__paid_at__week + , subq_6.booking__paid_at__month + , subq_6.booking__paid_at__quarter + , subq_6.booking__paid_at__year + , subq_6.booking__paid_at__extract_year + , subq_6.booking__paid_at__extract_quarter + , subq_6.booking__paid_at__extract_month + , subq_6.booking__paid_at__extract_day + , subq_6.booking__paid_at__extract_dow + , subq_6.booking__paid_at__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.listing + , subq_6.guest + , subq_6.host + , subq_6.booking__listing + , subq_6.booking__guest + , subq_6.booking__host + , subq_6.is_instant + , subq_6.booking__is_instant + , subq_6.bookings + , subq_6.instant_bookings + , subq_6.booking_value + , subq_6.max_booking_value + , subq_6.min_booking_value + , subq_6.bookers + , subq_6.average_booking_value + , subq_6.referred_bookings + , subq_6.median_booking_value + , subq_6.booking_value_p99 + , subq_6.discrete_booking_value_p99 + , subq_6.approximate_continuous_booking_value_p99 + , subq_6.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC(bookings_source_src_28000.ds, day) AS ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC(bookings_source_src_28000.ds, day) AS booking__ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS booking__ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS booking__ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS booking__ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS booking__ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS booking__ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS booking__ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS booking__ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS booking__ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS booking__ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS booking__paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS booking__paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS booking__paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS booking__paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS booking__paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_6 + ) subq_7 + WHERE NOT booking__is_instant + ) subq_8 + ) subq_9 WHERE NOT booking__is_instant - ) subq_3 - ) subq_4 + ) subq_10 + ) subq_11 GROUP BY metric_time__day - ) subq_5 -) subq_6 + ) subq_12 +) subq_13 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql index c4d1b2bf47..f383ad08b9 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql @@ -11,16 +11,24 @@ FROM ( metric_time__day , SUM(bookings) AS delayed_bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC(ds, day) AS metric_time__day - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + metric_time__day + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC(ds, day) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_15 + WHERE NOT booking__is_instant + ) subq_17 WHERE NOT booking__is_instant GROUP BY metric_time__day -) subq_13 +) subq_21 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_distinct_values__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_distinct_values__plan0.sql index e9ee0c5d30..ec223f9e50 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_distinct_values__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_distinct_values__plan0.sql @@ -1,134 +1,195 @@ -- Order By ['listing__country_latest'] Limit 100 SELECT - subq_2.listing__country_latest + subq_5.listing__country_latest FROM ( -- Pass Only Elements: ['listing__country_latest',] SELECT - subq_1.listing__country_latest + subq_4.listing__country_latest FROM ( -- Constrain Output with WHERE 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.created_at__day - , subq_0.created_at__week - , subq_0.created_at__month - , subq_0.created_at__quarter - , subq_0.created_at__year - , subq_0.created_at__extract_year - , subq_0.created_at__extract_quarter - , subq_0.created_at__extract_month - , subq_0.created_at__extract_day - , subq_0.created_at__extract_dow - , subq_0.created_at__extract_doy - , subq_0.listing__ds__day - , subq_0.listing__ds__week - , subq_0.listing__ds__month - , subq_0.listing__ds__quarter - , subq_0.listing__ds__year - , subq_0.listing__ds__extract_year - , subq_0.listing__ds__extract_quarter - , subq_0.listing__ds__extract_month - , subq_0.listing__ds__extract_day - , subq_0.listing__ds__extract_dow - , subq_0.listing__ds__extract_doy - , subq_0.listing__created_at__day - , subq_0.listing__created_at__week - , subq_0.listing__created_at__month - , subq_0.listing__created_at__quarter - , subq_0.listing__created_at__year - , subq_0.listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month - , subq_0.listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow - , subq_0.listing__created_at__extract_doy - , subq_0.listing - , subq_0.user - , subq_0.listing__user - , subq_0.country_latest - , subq_0.is_lux_latest - , subq_0.capacity_latest - , subq_0.listing__country_latest - , subq_0.listing__is_lux_latest - , subq_0.listing__capacity_latest - , subq_0.listings - , subq_0.largest_listing - , subq_0.smallest_listing + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing FROM ( - -- Read Elements From Semantic Model 'listings_latest' + -- Constrain Output with WHERE SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , listings_latest_src_28000.user_id AS user - , listings_latest_src_28000.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_0 + subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.created_at__day + , subq_2.created_at__week + , subq_2.created_at__month + , subq_2.created_at__quarter + , subq_2.created_at__year + , subq_2.created_at__extract_year + , subq_2.created_at__extract_quarter + , subq_2.created_at__extract_month + , subq_2.created_at__extract_day + , subq_2.created_at__extract_dow + , subq_2.created_at__extract_doy + , subq_2.listing__ds__day + , subq_2.listing__ds__week + , subq_2.listing__ds__month + , subq_2.listing__ds__quarter + , subq_2.listing__ds__year + , subq_2.listing__ds__extract_year + , subq_2.listing__ds__extract_quarter + , subq_2.listing__ds__extract_month + , subq_2.listing__ds__extract_day + , subq_2.listing__ds__extract_dow + , subq_2.listing__ds__extract_doy + , subq_2.listing__created_at__day + , subq_2.listing__created_at__week + , subq_2.listing__created_at__month + , subq_2.listing__created_at__quarter + , subq_2.listing__created_at__year + , subq_2.listing__created_at__extract_year + , subq_2.listing__created_at__extract_quarter + , subq_2.listing__created_at__extract_month + , subq_2.listing__created_at__extract_day + , subq_2.listing__created_at__extract_dow + , subq_2.listing__created_at__extract_doy + , subq_2.listing + , subq_2.user + , subq_2.listing__user + , subq_2.country_latest + , subq_2.is_lux_latest + , subq_2.capacity_latest + , subq_2.listing__country_latest + , subq_2.listing__is_lux_latest + , subq_2.listing__capacity_latest + , subq_2.listings + , subq_2.largest_listing + , subq_2.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_2 + WHERE listing__country_latest = 'us' + ) subq_3 WHERE listing__country_latest = 'us' - ) subq_1 + ) subq_4 GROUP BY - subq_1.listing__country_latest -) subq_2 -ORDER BY subq_2.listing__country_latest DESC + subq_4.listing__country_latest +) subq_5 +ORDER BY subq_5.listing__country_latest DESC LIMIT 100 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_distinct_values__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_distinct_values__plan0_optimized.sql index 1653ada5bd..76e6591b6c 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_distinct_values__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_distinct_values__plan0_optimized.sql @@ -4,11 +4,17 @@ SELECT listing__country_latest FROM ( - -- Read Elements From Semantic Model 'listings_latest' + -- Constrain Output with WHERE SELECT - country AS listing__country_latest - FROM ***************************.dim_listings_latest listings_latest_src_28000 -) subq_3 + listing__country_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + country AS listing__country_latest + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_6 + WHERE listing__country_latest = 'us' +) subq_7 WHERE listing__country_latest = 'us' GROUP BY listing__country_latest diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_reused_measure__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_reused_measure__plan0.sql index 4f2cd9819b..ddc3216f51 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_reused_measure__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_reused_measure__plan0.sql @@ -1,359 +1,462 @@ -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day - , CAST(subq_12.booking_value_with_is_instant_constraint AS DOUBLE) / CAST(NULLIF(subq_12.booking_value, 0) AS DOUBLE) AS instant_booking_value_ratio + subq_19.metric_time__day + , CAST(subq_19.booking_value_with_is_instant_constraint AS DOUBLE) / CAST(NULLIF(subq_19.booking_value, 0) AS DOUBLE) AS instant_booking_value_ratio FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) AS metric_time__day - , MAX(subq_6.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_11.booking_value) AS booking_value + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) AS metric_time__day + , MAX(subq_13.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_18.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.booking_value AS booking_value_with_is_instant_constraint + subq_12.metric_time__day + , subq_12.booking_value AS booking_value_with_is_instant_constraint FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.booking_value) AS booking_value + subq_11.metric_time__day + , SUM(subq_11.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.booking_value + subq_10.metric_time__day + , subq_10.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.booking_value + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.booking_value + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE 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.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.booking__paid_at__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.listing - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_7.ds__day + , subq_7.ds__week + , subq_7.ds__month + , subq_7.ds__quarter + , subq_7.ds__year + , subq_7.ds__extract_year + , subq_7.ds__extract_quarter + , subq_7.ds__extract_month + , subq_7.ds__extract_day + , subq_7.ds__extract_dow + , subq_7.ds__extract_doy + , subq_7.ds_partitioned__day + , subq_7.ds_partitioned__week + , subq_7.ds_partitioned__month + , subq_7.ds_partitioned__quarter + , subq_7.ds_partitioned__year + , subq_7.ds_partitioned__extract_year + , subq_7.ds_partitioned__extract_quarter + , subq_7.ds_partitioned__extract_month + , subq_7.ds_partitioned__extract_day + , subq_7.ds_partitioned__extract_dow + , subq_7.ds_partitioned__extract_doy + , subq_7.paid_at__day + , subq_7.paid_at__week + , subq_7.paid_at__month + , subq_7.paid_at__quarter + , subq_7.paid_at__year + , subq_7.paid_at__extract_year + , subq_7.paid_at__extract_quarter + , subq_7.paid_at__extract_month + , subq_7.paid_at__extract_day + , subq_7.paid_at__extract_dow + , subq_7.paid_at__extract_doy + , subq_7.booking__ds__day + , subq_7.booking__ds__week + , subq_7.booking__ds__month + , subq_7.booking__ds__quarter + , subq_7.booking__ds__year + , subq_7.booking__ds__extract_year + , subq_7.booking__ds__extract_quarter + , subq_7.booking__ds__extract_month + , subq_7.booking__ds__extract_day + , subq_7.booking__ds__extract_dow + , subq_7.booking__ds__extract_doy + , subq_7.booking__ds_partitioned__day + , subq_7.booking__ds_partitioned__week + , subq_7.booking__ds_partitioned__month + , subq_7.booking__ds_partitioned__quarter + , subq_7.booking__ds_partitioned__year + , subq_7.booking__ds_partitioned__extract_year + , subq_7.booking__ds_partitioned__extract_quarter + , subq_7.booking__ds_partitioned__extract_month + , subq_7.booking__ds_partitioned__extract_day + , subq_7.booking__ds_partitioned__extract_dow + , subq_7.booking__ds_partitioned__extract_doy + , subq_7.booking__paid_at__day + , subq_7.booking__paid_at__week + , subq_7.booking__paid_at__month + , subq_7.booking__paid_at__quarter + , subq_7.booking__paid_at__year + , subq_7.booking__paid_at__extract_year + , subq_7.booking__paid_at__extract_quarter + , subq_7.booking__paid_at__extract_month + , subq_7.booking__paid_at__extract_day + , subq_7.booking__paid_at__extract_dow + , subq_7.booking__paid_at__extract_doy + , subq_7.metric_time__day + , subq_7.metric_time__week + , subq_7.metric_time__month + , subq_7.metric_time__quarter + , subq_7.metric_time__year + , subq_7.metric_time__extract_year + , subq_7.metric_time__extract_quarter + , subq_7.metric_time__extract_month + , subq_7.metric_time__extract_day + , subq_7.metric_time__extract_dow + , subq_7.metric_time__extract_doy + , subq_7.listing + , subq_7.guest + , subq_7.host + , subq_7.booking__listing + , subq_7.booking__guest + , subq_7.booking__host + , subq_7.is_instant + , subq_7.booking__is_instant + , subq_7.bookings + , subq_7.instant_bookings + , subq_7.booking_value + , subq_7.max_booking_value + , subq_7.min_booking_value + , subq_7.bookers + , subq_7.average_booking_value + , subq_7.referred_bookings + , subq_7.median_booking_value + , subq_7.booking_value_p99 + , subq_7.discrete_booking_value_p99 + , subq_7.approximate_continuous_booking_value_p99 + , subq_7.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + 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.ds_partitioned__day + , subq_6.ds_partitioned__week + , subq_6.ds_partitioned__month + , subq_6.ds_partitioned__quarter + , subq_6.ds_partitioned__year + , subq_6.ds_partitioned__extract_year + , subq_6.ds_partitioned__extract_quarter + , subq_6.ds_partitioned__extract_month + , subq_6.ds_partitioned__extract_day + , subq_6.ds_partitioned__extract_dow + , subq_6.ds_partitioned__extract_doy + , subq_6.paid_at__day + , subq_6.paid_at__week + , subq_6.paid_at__month + , subq_6.paid_at__quarter + , subq_6.paid_at__year + , subq_6.paid_at__extract_year + , subq_6.paid_at__extract_quarter + , subq_6.paid_at__extract_month + , subq_6.paid_at__extract_day + , subq_6.paid_at__extract_dow + , subq_6.paid_at__extract_doy + , subq_6.booking__ds__day + , subq_6.booking__ds__week + , subq_6.booking__ds__month + , subq_6.booking__ds__quarter + , subq_6.booking__ds__year + , subq_6.booking__ds__extract_year + , subq_6.booking__ds__extract_quarter + , subq_6.booking__ds__extract_month + , subq_6.booking__ds__extract_day + , subq_6.booking__ds__extract_dow + , subq_6.booking__ds__extract_doy + , subq_6.booking__ds_partitioned__day + , subq_6.booking__ds_partitioned__week + , subq_6.booking__ds_partitioned__month + , subq_6.booking__ds_partitioned__quarter + , subq_6.booking__ds_partitioned__year + , subq_6.booking__ds_partitioned__extract_year + , subq_6.booking__ds_partitioned__extract_quarter + , subq_6.booking__ds_partitioned__extract_month + , subq_6.booking__ds_partitioned__extract_day + , subq_6.booking__ds_partitioned__extract_dow + , subq_6.booking__ds_partitioned__extract_doy + , subq_6.booking__paid_at__day + , subq_6.booking__paid_at__week + , subq_6.booking__paid_at__month + , subq_6.booking__paid_at__quarter + , subq_6.booking__paid_at__year + , subq_6.booking__paid_at__extract_year + , subq_6.booking__paid_at__extract_quarter + , subq_6.booking__paid_at__extract_month + , subq_6.booking__paid_at__extract_day + , subq_6.booking__paid_at__extract_dow + , subq_6.booking__paid_at__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.listing + , subq_6.guest + , subq_6.host + , subq_6.booking__listing + , subq_6.booking__guest + , subq_6.booking__host + , subq_6.is_instant + , subq_6.booking__is_instant + , subq_6.bookings + , subq_6.instant_bookings + , subq_6.booking_value + , subq_6.max_booking_value + , subq_6.min_booking_value + , subq_6.bookers + , subq_6.average_booking_value + , subq_6.referred_bookings + , subq_6.median_booking_value + , subq_6.booking_value_p99 + , subq_6.discrete_booking_value_p99 + , subq_6.approximate_continuous_booking_value_p99 + , subq_6.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 WHERE booking__is_instant - ) subq_3 - ) subq_4 + ) subq_10 + ) subq_11 GROUP BY - subq_4.metric_time__day - ) subq_5 - ) subq_6 + subq_11.metric_time__day + ) subq_12 + ) subq_13 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day - , subq_10.booking_value + subq_17.metric_time__day + , subq_17.booking_value FROM ( -- Aggregate Measures SELECT - subq_9.metric_time__day - , SUM(subq_9.booking_value) AS booking_value + subq_16.metric_time__day + , SUM(subq_16.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'metric_time__day'] SELECT - subq_8.metric_time__day - , subq_8.booking_value + subq_15.metric_time__day + , subq_15.booking_value FROM ( -- Metric Time Dimension 'ds' SELECT - subq_7.ds__day - , subq_7.ds__week - , subq_7.ds__month - , subq_7.ds__quarter - , subq_7.ds__year - , subq_7.ds__extract_year - , subq_7.ds__extract_quarter - , subq_7.ds__extract_month - , subq_7.ds__extract_day - , subq_7.ds__extract_dow - , subq_7.ds__extract_doy - , subq_7.ds_partitioned__day - , subq_7.ds_partitioned__week - , subq_7.ds_partitioned__month - , subq_7.ds_partitioned__quarter - , subq_7.ds_partitioned__year - , subq_7.ds_partitioned__extract_year - , subq_7.ds_partitioned__extract_quarter - , subq_7.ds_partitioned__extract_month - , subq_7.ds_partitioned__extract_day - , subq_7.ds_partitioned__extract_dow - , subq_7.ds_partitioned__extract_doy - , subq_7.paid_at__day - , subq_7.paid_at__week - , subq_7.paid_at__month - , subq_7.paid_at__quarter - , subq_7.paid_at__year - , subq_7.paid_at__extract_year - , subq_7.paid_at__extract_quarter - , subq_7.paid_at__extract_month - , subq_7.paid_at__extract_day - , subq_7.paid_at__extract_dow - , subq_7.paid_at__extract_doy - , subq_7.booking__ds__day - , subq_7.booking__ds__week - , subq_7.booking__ds__month - , subq_7.booking__ds__quarter - , subq_7.booking__ds__year - , subq_7.booking__ds__extract_year - , subq_7.booking__ds__extract_quarter - , subq_7.booking__ds__extract_month - , subq_7.booking__ds__extract_day - , subq_7.booking__ds__extract_dow - , subq_7.booking__ds__extract_doy - , subq_7.booking__ds_partitioned__day - , subq_7.booking__ds_partitioned__week - , subq_7.booking__ds_partitioned__month - , subq_7.booking__ds_partitioned__quarter - , subq_7.booking__ds_partitioned__year - , subq_7.booking__ds_partitioned__extract_year - , subq_7.booking__ds_partitioned__extract_quarter - , subq_7.booking__ds_partitioned__extract_month - , subq_7.booking__ds_partitioned__extract_day - , subq_7.booking__ds_partitioned__extract_dow - , subq_7.booking__ds_partitioned__extract_doy - , subq_7.booking__paid_at__day - , subq_7.booking__paid_at__week - , subq_7.booking__paid_at__month - , subq_7.booking__paid_at__quarter - , subq_7.booking__paid_at__year - , subq_7.booking__paid_at__extract_year - , subq_7.booking__paid_at__extract_quarter - , subq_7.booking__paid_at__extract_month - , subq_7.booking__paid_at__extract_day - , subq_7.booking__paid_at__extract_dow - , subq_7.booking__paid_at__extract_doy - , subq_7.ds__day AS metric_time__day - , subq_7.ds__week AS metric_time__week - , subq_7.ds__month AS metric_time__month - , subq_7.ds__quarter AS metric_time__quarter - , subq_7.ds__year AS metric_time__year - , subq_7.ds__extract_year AS metric_time__extract_year - , subq_7.ds__extract_quarter AS metric_time__extract_quarter - , subq_7.ds__extract_month AS metric_time__extract_month - , subq_7.ds__extract_day AS metric_time__extract_day - , subq_7.ds__extract_dow AS metric_time__extract_dow - , subq_7.ds__extract_doy AS metric_time__extract_doy - , subq_7.listing - , subq_7.guest - , subq_7.host - , subq_7.booking__listing - , subq_7.booking__guest - , subq_7.booking__host - , subq_7.is_instant - , subq_7.booking__is_instant - , subq_7.bookings - , subq_7.instant_bookings - , subq_7.booking_value - , subq_7.max_booking_value - , subq_7.min_booking_value - , subq_7.bookers - , subq_7.average_booking_value - , subq_7.referred_bookings - , subq_7.median_booking_value - , subq_7.booking_value_p99 - , subq_7.discrete_booking_value_p99 - , subq_7.approximate_continuous_booking_value_p99 - , subq_7.approximate_discrete_booking_value_p99 + subq_14.ds__day + , subq_14.ds__week + , subq_14.ds__month + , subq_14.ds__quarter + , subq_14.ds__year + , subq_14.ds__extract_year + , subq_14.ds__extract_quarter + , subq_14.ds__extract_month + , subq_14.ds__extract_day + , subq_14.ds__extract_dow + , subq_14.ds__extract_doy + , subq_14.ds_partitioned__day + , subq_14.ds_partitioned__week + , subq_14.ds_partitioned__month + , subq_14.ds_partitioned__quarter + , subq_14.ds_partitioned__year + , subq_14.ds_partitioned__extract_year + , subq_14.ds_partitioned__extract_quarter + , subq_14.ds_partitioned__extract_month + , subq_14.ds_partitioned__extract_day + , subq_14.ds_partitioned__extract_dow + , subq_14.ds_partitioned__extract_doy + , subq_14.paid_at__day + , subq_14.paid_at__week + , subq_14.paid_at__month + , subq_14.paid_at__quarter + , subq_14.paid_at__year + , subq_14.paid_at__extract_year + , subq_14.paid_at__extract_quarter + , subq_14.paid_at__extract_month + , subq_14.paid_at__extract_day + , subq_14.paid_at__extract_dow + , subq_14.paid_at__extract_doy + , subq_14.booking__ds__day + , subq_14.booking__ds__week + , subq_14.booking__ds__month + , subq_14.booking__ds__quarter + , subq_14.booking__ds__year + , subq_14.booking__ds__extract_year + , subq_14.booking__ds__extract_quarter + , subq_14.booking__ds__extract_month + , subq_14.booking__ds__extract_day + , subq_14.booking__ds__extract_dow + , subq_14.booking__ds__extract_doy + , subq_14.booking__ds_partitioned__day + , subq_14.booking__ds_partitioned__week + , subq_14.booking__ds_partitioned__month + , subq_14.booking__ds_partitioned__quarter + , subq_14.booking__ds_partitioned__year + , subq_14.booking__ds_partitioned__extract_year + , subq_14.booking__ds_partitioned__extract_quarter + , subq_14.booking__ds_partitioned__extract_month + , subq_14.booking__ds_partitioned__extract_day + , subq_14.booking__ds_partitioned__extract_dow + , subq_14.booking__ds_partitioned__extract_doy + , subq_14.booking__paid_at__day + , subq_14.booking__paid_at__week + , subq_14.booking__paid_at__month + , subq_14.booking__paid_at__quarter + , subq_14.booking__paid_at__year + , subq_14.booking__paid_at__extract_year + , subq_14.booking__paid_at__extract_quarter + , subq_14.booking__paid_at__extract_month + , subq_14.booking__paid_at__extract_day + , subq_14.booking__paid_at__extract_dow + , subq_14.booking__paid_at__extract_doy + , subq_14.ds__day AS metric_time__day + , subq_14.ds__week AS metric_time__week + , subq_14.ds__month AS metric_time__month + , subq_14.ds__quarter AS metric_time__quarter + , subq_14.ds__year AS metric_time__year + , subq_14.ds__extract_year AS metric_time__extract_year + , subq_14.ds__extract_quarter AS metric_time__extract_quarter + , subq_14.ds__extract_month AS metric_time__extract_month + , subq_14.ds__extract_day AS metric_time__extract_day + , subq_14.ds__extract_dow AS metric_time__extract_dow + , subq_14.ds__extract_doy AS metric_time__extract_doy + , subq_14.listing + , subq_14.guest + , subq_14.host + , subq_14.booking__listing + , subq_14.booking__guest + , subq_14.booking__host + , subq_14.is_instant + , subq_14.booking__is_instant + , subq_14.bookings + , subq_14.instant_bookings + , subq_14.booking_value + , subq_14.max_booking_value + , subq_14.min_booking_value + , subq_14.bookers + , subq_14.average_booking_value + , subq_14.referred_bookings + , subq_14.median_booking_value + , subq_14.booking_value_p99 + , subq_14.discrete_booking_value_p99 + , subq_14.approximate_continuous_booking_value_p99 + , subq_14.approximate_discrete_booking_value_p99 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -446,15 +549,15 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_7 - ) subq_8 - ) subq_9 + ) subq_14 + ) subq_15 + ) subq_16 GROUP BY - subq_9.metric_time__day - ) subq_10 - ) subq_11 + subq_16.metric_time__day + ) subq_17 + ) subq_18 ON - subq_6.metric_time__day = subq_11.metric_time__day + subq_13.metric_time__day = subq_18.metric_time__day GROUP BY - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) -) subq_12 + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) +) subq_19 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_reused_measure__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_reused_measure__plan0_optimized.sql index a465dac6f6..f0def82955 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_reused_measure__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_reused_measure__plan0_optimized.sql @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) AS metric_time__day - , MAX(subq_19.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_24.booking_value) AS booking_value + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) AS metric_time__day + , MAX(subq_27.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_32.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'metric_time__day'] @@ -17,19 +17,27 @@ FROM ( metric_time__day , SUM(booking_value) AS booking_value_with_is_instant_constraint FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant + metric_time__day + , booking__is_instant , booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_15 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_21 + WHERE booking__is_instant + ) subq_23 WHERE booking__is_instant GROUP BY metric_time__day - ) subq_19 + ) subq_27 FULL OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -42,9 +50,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY DATE_TRUNC('day', ds) - ) subq_24 + ) subq_32 ON - subq_19.metric_time__day = subq_24.metric_time__day + subq_27.metric_time__day = subq_32.metric_time__day GROUP BY - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) -) subq_25 + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) +) subq_33 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_single_expr_and_alias__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_single_expr_and_alias__plan0.sql index 87a8c39f99..2e4a2b5d0a 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_single_expr_and_alias__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_single_expr_and_alias__plan0.sql @@ -1,234 +1,337 @@ -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day + subq_13.metric_time__day , delayed_bookings * 2 AS double_counted_delayed_bookings FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.bookings AS delayed_bookings + subq_12.metric_time__day + , subq_12.bookings AS delayed_bookings FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.bookings) AS bookings + subq_11.metric_time__day + , SUM(subq_11.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.bookings + subq_10.metric_time__day + , subq_10.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE 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.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.booking__paid_at__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.listing - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_7.ds__day + , subq_7.ds__week + , subq_7.ds__month + , subq_7.ds__quarter + , subq_7.ds__year + , subq_7.ds__extract_year + , subq_7.ds__extract_quarter + , subq_7.ds__extract_month + , subq_7.ds__extract_day + , subq_7.ds__extract_dow + , subq_7.ds__extract_doy + , subq_7.ds_partitioned__day + , subq_7.ds_partitioned__week + , subq_7.ds_partitioned__month + , subq_7.ds_partitioned__quarter + , subq_7.ds_partitioned__year + , subq_7.ds_partitioned__extract_year + , subq_7.ds_partitioned__extract_quarter + , subq_7.ds_partitioned__extract_month + , subq_7.ds_partitioned__extract_day + , subq_7.ds_partitioned__extract_dow + , subq_7.ds_partitioned__extract_doy + , subq_7.paid_at__day + , subq_7.paid_at__week + , subq_7.paid_at__month + , subq_7.paid_at__quarter + , subq_7.paid_at__year + , subq_7.paid_at__extract_year + , subq_7.paid_at__extract_quarter + , subq_7.paid_at__extract_month + , subq_7.paid_at__extract_day + , subq_7.paid_at__extract_dow + , subq_7.paid_at__extract_doy + , subq_7.booking__ds__day + , subq_7.booking__ds__week + , subq_7.booking__ds__month + , subq_7.booking__ds__quarter + , subq_7.booking__ds__year + , subq_7.booking__ds__extract_year + , subq_7.booking__ds__extract_quarter + , subq_7.booking__ds__extract_month + , subq_7.booking__ds__extract_day + , subq_7.booking__ds__extract_dow + , subq_7.booking__ds__extract_doy + , subq_7.booking__ds_partitioned__day + , subq_7.booking__ds_partitioned__week + , subq_7.booking__ds_partitioned__month + , subq_7.booking__ds_partitioned__quarter + , subq_7.booking__ds_partitioned__year + , subq_7.booking__ds_partitioned__extract_year + , subq_7.booking__ds_partitioned__extract_quarter + , subq_7.booking__ds_partitioned__extract_month + , subq_7.booking__ds_partitioned__extract_day + , subq_7.booking__ds_partitioned__extract_dow + , subq_7.booking__ds_partitioned__extract_doy + , subq_7.booking__paid_at__day + , subq_7.booking__paid_at__week + , subq_7.booking__paid_at__month + , subq_7.booking__paid_at__quarter + , subq_7.booking__paid_at__year + , subq_7.booking__paid_at__extract_year + , subq_7.booking__paid_at__extract_quarter + , subq_7.booking__paid_at__extract_month + , subq_7.booking__paid_at__extract_day + , subq_7.booking__paid_at__extract_dow + , subq_7.booking__paid_at__extract_doy + , subq_7.metric_time__day + , subq_7.metric_time__week + , subq_7.metric_time__month + , subq_7.metric_time__quarter + , subq_7.metric_time__year + , subq_7.metric_time__extract_year + , subq_7.metric_time__extract_quarter + , subq_7.metric_time__extract_month + , subq_7.metric_time__extract_day + , subq_7.metric_time__extract_dow + , subq_7.metric_time__extract_doy + , subq_7.listing + , subq_7.guest + , subq_7.host + , subq_7.booking__listing + , subq_7.booking__guest + , subq_7.booking__host + , subq_7.is_instant + , subq_7.booking__is_instant + , subq_7.bookings + , subq_7.instant_bookings + , subq_7.booking_value + , subq_7.max_booking_value + , subq_7.min_booking_value + , subq_7.bookers + , subq_7.average_booking_value + , subq_7.referred_bookings + , subq_7.median_booking_value + , subq_7.booking_value_p99 + , subq_7.discrete_booking_value_p99 + , subq_7.approximate_continuous_booking_value_p99 + , subq_7.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + 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.ds_partitioned__day + , subq_6.ds_partitioned__week + , subq_6.ds_partitioned__month + , subq_6.ds_partitioned__quarter + , subq_6.ds_partitioned__year + , subq_6.ds_partitioned__extract_year + , subq_6.ds_partitioned__extract_quarter + , subq_6.ds_partitioned__extract_month + , subq_6.ds_partitioned__extract_day + , subq_6.ds_partitioned__extract_dow + , subq_6.ds_partitioned__extract_doy + , subq_6.paid_at__day + , subq_6.paid_at__week + , subq_6.paid_at__month + , subq_6.paid_at__quarter + , subq_6.paid_at__year + , subq_6.paid_at__extract_year + , subq_6.paid_at__extract_quarter + , subq_6.paid_at__extract_month + , subq_6.paid_at__extract_day + , subq_6.paid_at__extract_dow + , subq_6.paid_at__extract_doy + , subq_6.booking__ds__day + , subq_6.booking__ds__week + , subq_6.booking__ds__month + , subq_6.booking__ds__quarter + , subq_6.booking__ds__year + , subq_6.booking__ds__extract_year + , subq_6.booking__ds__extract_quarter + , subq_6.booking__ds__extract_month + , subq_6.booking__ds__extract_day + , subq_6.booking__ds__extract_dow + , subq_6.booking__ds__extract_doy + , subq_6.booking__ds_partitioned__day + , subq_6.booking__ds_partitioned__week + , subq_6.booking__ds_partitioned__month + , subq_6.booking__ds_partitioned__quarter + , subq_6.booking__ds_partitioned__year + , subq_6.booking__ds_partitioned__extract_year + , subq_6.booking__ds_partitioned__extract_quarter + , subq_6.booking__ds_partitioned__extract_month + , subq_6.booking__ds_partitioned__extract_day + , subq_6.booking__ds_partitioned__extract_dow + , subq_6.booking__ds_partitioned__extract_doy + , subq_6.booking__paid_at__day + , subq_6.booking__paid_at__week + , subq_6.booking__paid_at__month + , subq_6.booking__paid_at__quarter + , subq_6.booking__paid_at__year + , subq_6.booking__paid_at__extract_year + , subq_6.booking__paid_at__extract_quarter + , subq_6.booking__paid_at__extract_month + , subq_6.booking__paid_at__extract_day + , subq_6.booking__paid_at__extract_dow + , subq_6.booking__paid_at__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.listing + , subq_6.guest + , subq_6.host + , subq_6.booking__listing + , subq_6.booking__guest + , subq_6.booking__host + , subq_6.is_instant + , subq_6.booking__is_instant + , subq_6.bookings + , subq_6.instant_bookings + , subq_6.booking_value + , subq_6.max_booking_value + , subq_6.min_booking_value + , subq_6.bookers + , subq_6.average_booking_value + , subq_6.referred_bookings + , subq_6.median_booking_value + , subq_6.booking_value_p99 + , subq_6.discrete_booking_value_p99 + , subq_6.approximate_continuous_booking_value_p99 + , subq_6.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_6 + ) subq_7 + WHERE NOT booking__is_instant + ) subq_8 + ) subq_9 WHERE NOT booking__is_instant - ) subq_3 - ) subq_4 + ) subq_10 + ) subq_11 GROUP BY - subq_4.metric_time__day - ) subq_5 -) subq_6 + subq_11.metric_time__day + ) subq_12 +) subq_13 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql index 3202b9915d..33436b83b6 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql @@ -11,16 +11,24 @@ FROM ( metric_time__day , SUM(bookings) AS delayed_bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + metric_time__day + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_15 + WHERE NOT booking__is_instant + ) subq_17 WHERE NOT booking__is_instant GROUP BY metric_time__day -) subq_13 +) subq_21 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_distinct_values__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_distinct_values__plan0.sql index cd3d4c172a..4fb1321801 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_distinct_values__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_distinct_values__plan0.sql @@ -1,134 +1,195 @@ -- Order By ['listing__country_latest'] Limit 100 SELECT - subq_2.listing__country_latest + subq_5.listing__country_latest FROM ( -- Pass Only Elements: ['listing__country_latest',] SELECT - subq_1.listing__country_latest + subq_4.listing__country_latest FROM ( -- Constrain Output with WHERE 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.created_at__day - , subq_0.created_at__week - , subq_0.created_at__month - , subq_0.created_at__quarter - , subq_0.created_at__year - , subq_0.created_at__extract_year - , subq_0.created_at__extract_quarter - , subq_0.created_at__extract_month - , subq_0.created_at__extract_day - , subq_0.created_at__extract_dow - , subq_0.created_at__extract_doy - , subq_0.listing__ds__day - , subq_0.listing__ds__week - , subq_0.listing__ds__month - , subq_0.listing__ds__quarter - , subq_0.listing__ds__year - , subq_0.listing__ds__extract_year - , subq_0.listing__ds__extract_quarter - , subq_0.listing__ds__extract_month - , subq_0.listing__ds__extract_day - , subq_0.listing__ds__extract_dow - , subq_0.listing__ds__extract_doy - , subq_0.listing__created_at__day - , subq_0.listing__created_at__week - , subq_0.listing__created_at__month - , subq_0.listing__created_at__quarter - , subq_0.listing__created_at__year - , subq_0.listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month - , subq_0.listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow - , subq_0.listing__created_at__extract_doy - , subq_0.listing - , subq_0.user - , subq_0.listing__user - , subq_0.country_latest - , subq_0.is_lux_latest - , subq_0.capacity_latest - , subq_0.listing__country_latest - , subq_0.listing__is_lux_latest - , subq_0.listing__capacity_latest - , subq_0.listings - , subq_0.largest_listing - , subq_0.smallest_listing + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing FROM ( - -- Read Elements From Semantic Model 'listings_latest' + -- Constrain Output with WHERE SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , listings_latest_src_28000.user_id AS user - , listings_latest_src_28000.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_0 + subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.created_at__day + , subq_2.created_at__week + , subq_2.created_at__month + , subq_2.created_at__quarter + , subq_2.created_at__year + , subq_2.created_at__extract_year + , subq_2.created_at__extract_quarter + , subq_2.created_at__extract_month + , subq_2.created_at__extract_day + , subq_2.created_at__extract_dow + , subq_2.created_at__extract_doy + , subq_2.listing__ds__day + , subq_2.listing__ds__week + , subq_2.listing__ds__month + , subq_2.listing__ds__quarter + , subq_2.listing__ds__year + , subq_2.listing__ds__extract_year + , subq_2.listing__ds__extract_quarter + , subq_2.listing__ds__extract_month + , subq_2.listing__ds__extract_day + , subq_2.listing__ds__extract_dow + , subq_2.listing__ds__extract_doy + , subq_2.listing__created_at__day + , subq_2.listing__created_at__week + , subq_2.listing__created_at__month + , subq_2.listing__created_at__quarter + , subq_2.listing__created_at__year + , subq_2.listing__created_at__extract_year + , subq_2.listing__created_at__extract_quarter + , subq_2.listing__created_at__extract_month + , subq_2.listing__created_at__extract_day + , subq_2.listing__created_at__extract_dow + , subq_2.listing__created_at__extract_doy + , subq_2.listing + , subq_2.user + , subq_2.listing__user + , subq_2.country_latest + , subq_2.is_lux_latest + , subq_2.capacity_latest + , subq_2.listing__country_latest + , subq_2.listing__is_lux_latest + , subq_2.listing__capacity_latest + , subq_2.listings + , subq_2.largest_listing + , subq_2.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_2 + WHERE listing__country_latest = 'us' + ) subq_3 WHERE listing__country_latest = 'us' - ) subq_1 + ) subq_4 GROUP BY - subq_1.listing__country_latest -) subq_2 -ORDER BY subq_2.listing__country_latest DESC + subq_4.listing__country_latest +) subq_5 +ORDER BY subq_5.listing__country_latest DESC LIMIT 100 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_distinct_values__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_distinct_values__plan0_optimized.sql index 1653ada5bd..76e6591b6c 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_distinct_values__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_distinct_values__plan0_optimized.sql @@ -4,11 +4,17 @@ SELECT listing__country_latest FROM ( - -- Read Elements From Semantic Model 'listings_latest' + -- Constrain Output with WHERE SELECT - country AS listing__country_latest - FROM ***************************.dim_listings_latest listings_latest_src_28000 -) subq_3 + listing__country_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + country AS listing__country_latest + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_6 + WHERE listing__country_latest = 'us' +) subq_7 WHERE listing__country_latest = 'us' GROUP BY listing__country_latest diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_reused_measure__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_reused_measure__plan0.sql index 19a913bb1f..5dd3547c45 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_reused_measure__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_reused_measure__plan0.sql @@ -1,359 +1,462 @@ -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day - , CAST(subq_12.booking_value_with_is_instant_constraint AS DOUBLE PRECISION) / CAST(NULLIF(subq_12.booking_value, 0) AS DOUBLE PRECISION) AS instant_booking_value_ratio + subq_19.metric_time__day + , CAST(subq_19.booking_value_with_is_instant_constraint AS DOUBLE PRECISION) / CAST(NULLIF(subq_19.booking_value, 0) AS DOUBLE PRECISION) AS instant_booking_value_ratio FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) AS metric_time__day - , MAX(subq_6.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_11.booking_value) AS booking_value + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) AS metric_time__day + , MAX(subq_13.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_18.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.booking_value AS booking_value_with_is_instant_constraint + subq_12.metric_time__day + , subq_12.booking_value AS booking_value_with_is_instant_constraint FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.booking_value) AS booking_value + subq_11.metric_time__day + , SUM(subq_11.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.booking_value + subq_10.metric_time__day + , subq_10.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.booking_value + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.booking_value + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE 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.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.booking__paid_at__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.listing - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_7.ds__day + , subq_7.ds__week + , subq_7.ds__month + , subq_7.ds__quarter + , subq_7.ds__year + , subq_7.ds__extract_year + , subq_7.ds__extract_quarter + , subq_7.ds__extract_month + , subq_7.ds__extract_day + , subq_7.ds__extract_dow + , subq_7.ds__extract_doy + , subq_7.ds_partitioned__day + , subq_7.ds_partitioned__week + , subq_7.ds_partitioned__month + , subq_7.ds_partitioned__quarter + , subq_7.ds_partitioned__year + , subq_7.ds_partitioned__extract_year + , subq_7.ds_partitioned__extract_quarter + , subq_7.ds_partitioned__extract_month + , subq_7.ds_partitioned__extract_day + , subq_7.ds_partitioned__extract_dow + , subq_7.ds_partitioned__extract_doy + , subq_7.paid_at__day + , subq_7.paid_at__week + , subq_7.paid_at__month + , subq_7.paid_at__quarter + , subq_7.paid_at__year + , subq_7.paid_at__extract_year + , subq_7.paid_at__extract_quarter + , subq_7.paid_at__extract_month + , subq_7.paid_at__extract_day + , subq_7.paid_at__extract_dow + , subq_7.paid_at__extract_doy + , subq_7.booking__ds__day + , subq_7.booking__ds__week + , subq_7.booking__ds__month + , subq_7.booking__ds__quarter + , subq_7.booking__ds__year + , subq_7.booking__ds__extract_year + , subq_7.booking__ds__extract_quarter + , subq_7.booking__ds__extract_month + , subq_7.booking__ds__extract_day + , subq_7.booking__ds__extract_dow + , subq_7.booking__ds__extract_doy + , subq_7.booking__ds_partitioned__day + , subq_7.booking__ds_partitioned__week + , subq_7.booking__ds_partitioned__month + , subq_7.booking__ds_partitioned__quarter + , subq_7.booking__ds_partitioned__year + , subq_7.booking__ds_partitioned__extract_year + , subq_7.booking__ds_partitioned__extract_quarter + , subq_7.booking__ds_partitioned__extract_month + , subq_7.booking__ds_partitioned__extract_day + , subq_7.booking__ds_partitioned__extract_dow + , subq_7.booking__ds_partitioned__extract_doy + , subq_7.booking__paid_at__day + , subq_7.booking__paid_at__week + , subq_7.booking__paid_at__month + , subq_7.booking__paid_at__quarter + , subq_7.booking__paid_at__year + , subq_7.booking__paid_at__extract_year + , subq_7.booking__paid_at__extract_quarter + , subq_7.booking__paid_at__extract_month + , subq_7.booking__paid_at__extract_day + , subq_7.booking__paid_at__extract_dow + , subq_7.booking__paid_at__extract_doy + , subq_7.metric_time__day + , subq_7.metric_time__week + , subq_7.metric_time__month + , subq_7.metric_time__quarter + , subq_7.metric_time__year + , subq_7.metric_time__extract_year + , subq_7.metric_time__extract_quarter + , subq_7.metric_time__extract_month + , subq_7.metric_time__extract_day + , subq_7.metric_time__extract_dow + , subq_7.metric_time__extract_doy + , subq_7.listing + , subq_7.guest + , subq_7.host + , subq_7.booking__listing + , subq_7.booking__guest + , subq_7.booking__host + , subq_7.is_instant + , subq_7.booking__is_instant + , subq_7.bookings + , subq_7.instant_bookings + , subq_7.booking_value + , subq_7.max_booking_value + , subq_7.min_booking_value + , subq_7.bookers + , subq_7.average_booking_value + , subq_7.referred_bookings + , subq_7.median_booking_value + , subq_7.booking_value_p99 + , subq_7.discrete_booking_value_p99 + , subq_7.approximate_continuous_booking_value_p99 + , subq_7.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + 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.ds_partitioned__day + , subq_6.ds_partitioned__week + , subq_6.ds_partitioned__month + , subq_6.ds_partitioned__quarter + , subq_6.ds_partitioned__year + , subq_6.ds_partitioned__extract_year + , subq_6.ds_partitioned__extract_quarter + , subq_6.ds_partitioned__extract_month + , subq_6.ds_partitioned__extract_day + , subq_6.ds_partitioned__extract_dow + , subq_6.ds_partitioned__extract_doy + , subq_6.paid_at__day + , subq_6.paid_at__week + , subq_6.paid_at__month + , subq_6.paid_at__quarter + , subq_6.paid_at__year + , subq_6.paid_at__extract_year + , subq_6.paid_at__extract_quarter + , subq_6.paid_at__extract_month + , subq_6.paid_at__extract_day + , subq_6.paid_at__extract_dow + , subq_6.paid_at__extract_doy + , subq_6.booking__ds__day + , subq_6.booking__ds__week + , subq_6.booking__ds__month + , subq_6.booking__ds__quarter + , subq_6.booking__ds__year + , subq_6.booking__ds__extract_year + , subq_6.booking__ds__extract_quarter + , subq_6.booking__ds__extract_month + , subq_6.booking__ds__extract_day + , subq_6.booking__ds__extract_dow + , subq_6.booking__ds__extract_doy + , subq_6.booking__ds_partitioned__day + , subq_6.booking__ds_partitioned__week + , subq_6.booking__ds_partitioned__month + , subq_6.booking__ds_partitioned__quarter + , subq_6.booking__ds_partitioned__year + , subq_6.booking__ds_partitioned__extract_year + , subq_6.booking__ds_partitioned__extract_quarter + , subq_6.booking__ds_partitioned__extract_month + , subq_6.booking__ds_partitioned__extract_day + , subq_6.booking__ds_partitioned__extract_dow + , subq_6.booking__ds_partitioned__extract_doy + , subq_6.booking__paid_at__day + , subq_6.booking__paid_at__week + , subq_6.booking__paid_at__month + , subq_6.booking__paid_at__quarter + , subq_6.booking__paid_at__year + , subq_6.booking__paid_at__extract_year + , subq_6.booking__paid_at__extract_quarter + , subq_6.booking__paid_at__extract_month + , subq_6.booking__paid_at__extract_day + , subq_6.booking__paid_at__extract_dow + , subq_6.booking__paid_at__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.listing + , subq_6.guest + , subq_6.host + , subq_6.booking__listing + , subq_6.booking__guest + , subq_6.booking__host + , subq_6.is_instant + , subq_6.booking__is_instant + , subq_6.bookings + , subq_6.instant_bookings + , subq_6.booking_value + , subq_6.max_booking_value + , subq_6.min_booking_value + , subq_6.bookers + , subq_6.average_booking_value + , subq_6.referred_bookings + , subq_6.median_booking_value + , subq_6.booking_value_p99 + , subq_6.discrete_booking_value_p99 + , subq_6.approximate_continuous_booking_value_p99 + , subq_6.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 WHERE booking__is_instant - ) subq_3 - ) subq_4 + ) subq_10 + ) subq_11 GROUP BY - subq_4.metric_time__day - ) subq_5 - ) subq_6 + subq_11.metric_time__day + ) subq_12 + ) subq_13 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day - , subq_10.booking_value + subq_17.metric_time__day + , subq_17.booking_value FROM ( -- Aggregate Measures SELECT - subq_9.metric_time__day - , SUM(subq_9.booking_value) AS booking_value + subq_16.metric_time__day + , SUM(subq_16.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'metric_time__day'] SELECT - subq_8.metric_time__day - , subq_8.booking_value + subq_15.metric_time__day + , subq_15.booking_value FROM ( -- Metric Time Dimension 'ds' SELECT - subq_7.ds__day - , subq_7.ds__week - , subq_7.ds__month - , subq_7.ds__quarter - , subq_7.ds__year - , subq_7.ds__extract_year - , subq_7.ds__extract_quarter - , subq_7.ds__extract_month - , subq_7.ds__extract_day - , subq_7.ds__extract_dow - , subq_7.ds__extract_doy - , subq_7.ds_partitioned__day - , subq_7.ds_partitioned__week - , subq_7.ds_partitioned__month - , subq_7.ds_partitioned__quarter - , subq_7.ds_partitioned__year - , subq_7.ds_partitioned__extract_year - , subq_7.ds_partitioned__extract_quarter - , subq_7.ds_partitioned__extract_month - , subq_7.ds_partitioned__extract_day - , subq_7.ds_partitioned__extract_dow - , subq_7.ds_partitioned__extract_doy - , subq_7.paid_at__day - , subq_7.paid_at__week - , subq_7.paid_at__month - , subq_7.paid_at__quarter - , subq_7.paid_at__year - , subq_7.paid_at__extract_year - , subq_7.paid_at__extract_quarter - , subq_7.paid_at__extract_month - , subq_7.paid_at__extract_day - , subq_7.paid_at__extract_dow - , subq_7.paid_at__extract_doy - , subq_7.booking__ds__day - , subq_7.booking__ds__week - , subq_7.booking__ds__month - , subq_7.booking__ds__quarter - , subq_7.booking__ds__year - , subq_7.booking__ds__extract_year - , subq_7.booking__ds__extract_quarter - , subq_7.booking__ds__extract_month - , subq_7.booking__ds__extract_day - , subq_7.booking__ds__extract_dow - , subq_7.booking__ds__extract_doy - , subq_7.booking__ds_partitioned__day - , subq_7.booking__ds_partitioned__week - , subq_7.booking__ds_partitioned__month - , subq_7.booking__ds_partitioned__quarter - , subq_7.booking__ds_partitioned__year - , subq_7.booking__ds_partitioned__extract_year - , subq_7.booking__ds_partitioned__extract_quarter - , subq_7.booking__ds_partitioned__extract_month - , subq_7.booking__ds_partitioned__extract_day - , subq_7.booking__ds_partitioned__extract_dow - , subq_7.booking__ds_partitioned__extract_doy - , subq_7.booking__paid_at__day - , subq_7.booking__paid_at__week - , subq_7.booking__paid_at__month - , subq_7.booking__paid_at__quarter - , subq_7.booking__paid_at__year - , subq_7.booking__paid_at__extract_year - , subq_7.booking__paid_at__extract_quarter - , subq_7.booking__paid_at__extract_month - , subq_7.booking__paid_at__extract_day - , subq_7.booking__paid_at__extract_dow - , subq_7.booking__paid_at__extract_doy - , subq_7.ds__day AS metric_time__day - , subq_7.ds__week AS metric_time__week - , subq_7.ds__month AS metric_time__month - , subq_7.ds__quarter AS metric_time__quarter - , subq_7.ds__year AS metric_time__year - , subq_7.ds__extract_year AS metric_time__extract_year - , subq_7.ds__extract_quarter AS metric_time__extract_quarter - , subq_7.ds__extract_month AS metric_time__extract_month - , subq_7.ds__extract_day AS metric_time__extract_day - , subq_7.ds__extract_dow AS metric_time__extract_dow - , subq_7.ds__extract_doy AS metric_time__extract_doy - , subq_7.listing - , subq_7.guest - , subq_7.host - , subq_7.booking__listing - , subq_7.booking__guest - , subq_7.booking__host - , subq_7.is_instant - , subq_7.booking__is_instant - , subq_7.bookings - , subq_7.instant_bookings - , subq_7.booking_value - , subq_7.max_booking_value - , subq_7.min_booking_value - , subq_7.bookers - , subq_7.average_booking_value - , subq_7.referred_bookings - , subq_7.median_booking_value - , subq_7.booking_value_p99 - , subq_7.discrete_booking_value_p99 - , subq_7.approximate_continuous_booking_value_p99 - , subq_7.approximate_discrete_booking_value_p99 + subq_14.ds__day + , subq_14.ds__week + , subq_14.ds__month + , subq_14.ds__quarter + , subq_14.ds__year + , subq_14.ds__extract_year + , subq_14.ds__extract_quarter + , subq_14.ds__extract_month + , subq_14.ds__extract_day + , subq_14.ds__extract_dow + , subq_14.ds__extract_doy + , subq_14.ds_partitioned__day + , subq_14.ds_partitioned__week + , subq_14.ds_partitioned__month + , subq_14.ds_partitioned__quarter + , subq_14.ds_partitioned__year + , subq_14.ds_partitioned__extract_year + , subq_14.ds_partitioned__extract_quarter + , subq_14.ds_partitioned__extract_month + , subq_14.ds_partitioned__extract_day + , subq_14.ds_partitioned__extract_dow + , subq_14.ds_partitioned__extract_doy + , subq_14.paid_at__day + , subq_14.paid_at__week + , subq_14.paid_at__month + , subq_14.paid_at__quarter + , subq_14.paid_at__year + , subq_14.paid_at__extract_year + , subq_14.paid_at__extract_quarter + , subq_14.paid_at__extract_month + , subq_14.paid_at__extract_day + , subq_14.paid_at__extract_dow + , subq_14.paid_at__extract_doy + , subq_14.booking__ds__day + , subq_14.booking__ds__week + , subq_14.booking__ds__month + , subq_14.booking__ds__quarter + , subq_14.booking__ds__year + , subq_14.booking__ds__extract_year + , subq_14.booking__ds__extract_quarter + , subq_14.booking__ds__extract_month + , subq_14.booking__ds__extract_day + , subq_14.booking__ds__extract_dow + , subq_14.booking__ds__extract_doy + , subq_14.booking__ds_partitioned__day + , subq_14.booking__ds_partitioned__week + , subq_14.booking__ds_partitioned__month + , subq_14.booking__ds_partitioned__quarter + , subq_14.booking__ds_partitioned__year + , subq_14.booking__ds_partitioned__extract_year + , subq_14.booking__ds_partitioned__extract_quarter + , subq_14.booking__ds_partitioned__extract_month + , subq_14.booking__ds_partitioned__extract_day + , subq_14.booking__ds_partitioned__extract_dow + , subq_14.booking__ds_partitioned__extract_doy + , subq_14.booking__paid_at__day + , subq_14.booking__paid_at__week + , subq_14.booking__paid_at__month + , subq_14.booking__paid_at__quarter + , subq_14.booking__paid_at__year + , subq_14.booking__paid_at__extract_year + , subq_14.booking__paid_at__extract_quarter + , subq_14.booking__paid_at__extract_month + , subq_14.booking__paid_at__extract_day + , subq_14.booking__paid_at__extract_dow + , subq_14.booking__paid_at__extract_doy + , subq_14.ds__day AS metric_time__day + , subq_14.ds__week AS metric_time__week + , subq_14.ds__month AS metric_time__month + , subq_14.ds__quarter AS metric_time__quarter + , subq_14.ds__year AS metric_time__year + , subq_14.ds__extract_year AS metric_time__extract_year + , subq_14.ds__extract_quarter AS metric_time__extract_quarter + , subq_14.ds__extract_month AS metric_time__extract_month + , subq_14.ds__extract_day AS metric_time__extract_day + , subq_14.ds__extract_dow AS metric_time__extract_dow + , subq_14.ds__extract_doy AS metric_time__extract_doy + , subq_14.listing + , subq_14.guest + , subq_14.host + , subq_14.booking__listing + , subq_14.booking__guest + , subq_14.booking__host + , subq_14.is_instant + , subq_14.booking__is_instant + , subq_14.bookings + , subq_14.instant_bookings + , subq_14.booking_value + , subq_14.max_booking_value + , subq_14.min_booking_value + , subq_14.bookers + , subq_14.average_booking_value + , subq_14.referred_bookings + , subq_14.median_booking_value + , subq_14.booking_value_p99 + , subq_14.discrete_booking_value_p99 + , subq_14.approximate_continuous_booking_value_p99 + , subq_14.approximate_discrete_booking_value_p99 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -446,15 +549,15 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_7 - ) subq_8 - ) subq_9 + ) subq_14 + ) subq_15 + ) subq_16 GROUP BY - subq_9.metric_time__day - ) subq_10 - ) subq_11 + subq_16.metric_time__day + ) subq_17 + ) subq_18 ON - subq_6.metric_time__day = subq_11.metric_time__day + subq_13.metric_time__day = subq_18.metric_time__day GROUP BY - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) -) subq_12 + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) +) subq_19 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_reused_measure__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_reused_measure__plan0_optimized.sql index e3a93f4824..29af02b578 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_reused_measure__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_reused_measure__plan0_optimized.sql @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) AS metric_time__day - , MAX(subq_19.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_24.booking_value) AS booking_value + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) AS metric_time__day + , MAX(subq_27.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_32.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'metric_time__day'] @@ -17,19 +17,27 @@ FROM ( metric_time__day , SUM(booking_value) AS booking_value_with_is_instant_constraint FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant + metric_time__day + , booking__is_instant , booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_15 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_21 + WHERE booking__is_instant + ) subq_23 WHERE booking__is_instant GROUP BY metric_time__day - ) subq_19 + ) subq_27 FULL OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -42,9 +50,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY DATE_TRUNC('day', ds) - ) subq_24 + ) subq_32 ON - subq_19.metric_time__day = subq_24.metric_time__day + subq_27.metric_time__day = subq_32.metric_time__day GROUP BY - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) -) subq_25 + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) +) subq_33 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_single_expr_and_alias__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_single_expr_and_alias__plan0.sql index 9182b35971..8e811be580 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_single_expr_and_alias__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_single_expr_and_alias__plan0.sql @@ -1,234 +1,337 @@ -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day + subq_13.metric_time__day , delayed_bookings * 2 AS double_counted_delayed_bookings FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.bookings AS delayed_bookings + subq_12.metric_time__day + , subq_12.bookings AS delayed_bookings FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.bookings) AS bookings + subq_11.metric_time__day + , SUM(subq_11.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.bookings + subq_10.metric_time__day + , subq_10.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE 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.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.booking__paid_at__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.listing - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_7.ds__day + , subq_7.ds__week + , subq_7.ds__month + , subq_7.ds__quarter + , subq_7.ds__year + , subq_7.ds__extract_year + , subq_7.ds__extract_quarter + , subq_7.ds__extract_month + , subq_7.ds__extract_day + , subq_7.ds__extract_dow + , subq_7.ds__extract_doy + , subq_7.ds_partitioned__day + , subq_7.ds_partitioned__week + , subq_7.ds_partitioned__month + , subq_7.ds_partitioned__quarter + , subq_7.ds_partitioned__year + , subq_7.ds_partitioned__extract_year + , subq_7.ds_partitioned__extract_quarter + , subq_7.ds_partitioned__extract_month + , subq_7.ds_partitioned__extract_day + , subq_7.ds_partitioned__extract_dow + , subq_7.ds_partitioned__extract_doy + , subq_7.paid_at__day + , subq_7.paid_at__week + , subq_7.paid_at__month + , subq_7.paid_at__quarter + , subq_7.paid_at__year + , subq_7.paid_at__extract_year + , subq_7.paid_at__extract_quarter + , subq_7.paid_at__extract_month + , subq_7.paid_at__extract_day + , subq_7.paid_at__extract_dow + , subq_7.paid_at__extract_doy + , subq_7.booking__ds__day + , subq_7.booking__ds__week + , subq_7.booking__ds__month + , subq_7.booking__ds__quarter + , subq_7.booking__ds__year + , subq_7.booking__ds__extract_year + , subq_7.booking__ds__extract_quarter + , subq_7.booking__ds__extract_month + , subq_7.booking__ds__extract_day + , subq_7.booking__ds__extract_dow + , subq_7.booking__ds__extract_doy + , subq_7.booking__ds_partitioned__day + , subq_7.booking__ds_partitioned__week + , subq_7.booking__ds_partitioned__month + , subq_7.booking__ds_partitioned__quarter + , subq_7.booking__ds_partitioned__year + , subq_7.booking__ds_partitioned__extract_year + , subq_7.booking__ds_partitioned__extract_quarter + , subq_7.booking__ds_partitioned__extract_month + , subq_7.booking__ds_partitioned__extract_day + , subq_7.booking__ds_partitioned__extract_dow + , subq_7.booking__ds_partitioned__extract_doy + , subq_7.booking__paid_at__day + , subq_7.booking__paid_at__week + , subq_7.booking__paid_at__month + , subq_7.booking__paid_at__quarter + , subq_7.booking__paid_at__year + , subq_7.booking__paid_at__extract_year + , subq_7.booking__paid_at__extract_quarter + , subq_7.booking__paid_at__extract_month + , subq_7.booking__paid_at__extract_day + , subq_7.booking__paid_at__extract_dow + , subq_7.booking__paid_at__extract_doy + , subq_7.metric_time__day + , subq_7.metric_time__week + , subq_7.metric_time__month + , subq_7.metric_time__quarter + , subq_7.metric_time__year + , subq_7.metric_time__extract_year + , subq_7.metric_time__extract_quarter + , subq_7.metric_time__extract_month + , subq_7.metric_time__extract_day + , subq_7.metric_time__extract_dow + , subq_7.metric_time__extract_doy + , subq_7.listing + , subq_7.guest + , subq_7.host + , subq_7.booking__listing + , subq_7.booking__guest + , subq_7.booking__host + , subq_7.is_instant + , subq_7.booking__is_instant + , subq_7.bookings + , subq_7.instant_bookings + , subq_7.booking_value + , subq_7.max_booking_value + , subq_7.min_booking_value + , subq_7.bookers + , subq_7.average_booking_value + , subq_7.referred_bookings + , subq_7.median_booking_value + , subq_7.booking_value_p99 + , subq_7.discrete_booking_value_p99 + , subq_7.approximate_continuous_booking_value_p99 + , subq_7.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + 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.ds_partitioned__day + , subq_6.ds_partitioned__week + , subq_6.ds_partitioned__month + , subq_6.ds_partitioned__quarter + , subq_6.ds_partitioned__year + , subq_6.ds_partitioned__extract_year + , subq_6.ds_partitioned__extract_quarter + , subq_6.ds_partitioned__extract_month + , subq_6.ds_partitioned__extract_day + , subq_6.ds_partitioned__extract_dow + , subq_6.ds_partitioned__extract_doy + , subq_6.paid_at__day + , subq_6.paid_at__week + , subq_6.paid_at__month + , subq_6.paid_at__quarter + , subq_6.paid_at__year + , subq_6.paid_at__extract_year + , subq_6.paid_at__extract_quarter + , subq_6.paid_at__extract_month + , subq_6.paid_at__extract_day + , subq_6.paid_at__extract_dow + , subq_6.paid_at__extract_doy + , subq_6.booking__ds__day + , subq_6.booking__ds__week + , subq_6.booking__ds__month + , subq_6.booking__ds__quarter + , subq_6.booking__ds__year + , subq_6.booking__ds__extract_year + , subq_6.booking__ds__extract_quarter + , subq_6.booking__ds__extract_month + , subq_6.booking__ds__extract_day + , subq_6.booking__ds__extract_dow + , subq_6.booking__ds__extract_doy + , subq_6.booking__ds_partitioned__day + , subq_6.booking__ds_partitioned__week + , subq_6.booking__ds_partitioned__month + , subq_6.booking__ds_partitioned__quarter + , subq_6.booking__ds_partitioned__year + , subq_6.booking__ds_partitioned__extract_year + , subq_6.booking__ds_partitioned__extract_quarter + , subq_6.booking__ds_partitioned__extract_month + , subq_6.booking__ds_partitioned__extract_day + , subq_6.booking__ds_partitioned__extract_dow + , subq_6.booking__ds_partitioned__extract_doy + , subq_6.booking__paid_at__day + , subq_6.booking__paid_at__week + , subq_6.booking__paid_at__month + , subq_6.booking__paid_at__quarter + , subq_6.booking__paid_at__year + , subq_6.booking__paid_at__extract_year + , subq_6.booking__paid_at__extract_quarter + , subq_6.booking__paid_at__extract_month + , subq_6.booking__paid_at__extract_day + , subq_6.booking__paid_at__extract_dow + , subq_6.booking__paid_at__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.listing + , subq_6.guest + , subq_6.host + , subq_6.booking__listing + , subq_6.booking__guest + , subq_6.booking__host + , subq_6.is_instant + , subq_6.booking__is_instant + , subq_6.bookings + , subq_6.instant_bookings + , subq_6.booking_value + , subq_6.max_booking_value + , subq_6.min_booking_value + , subq_6.bookers + , subq_6.average_booking_value + , subq_6.referred_bookings + , subq_6.median_booking_value + , subq_6.booking_value_p99 + , subq_6.discrete_booking_value_p99 + , subq_6.approximate_continuous_booking_value_p99 + , subq_6.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_6 + ) subq_7 + WHERE NOT booking__is_instant + ) subq_8 + ) subq_9 WHERE NOT booking__is_instant - ) subq_3 - ) subq_4 + ) subq_10 + ) subq_11 GROUP BY - subq_4.metric_time__day - ) subq_5 -) subq_6 + subq_11.metric_time__day + ) subq_12 +) subq_13 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql index 3202b9915d..33436b83b6 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql @@ -11,16 +11,24 @@ FROM ( metric_time__day , SUM(bookings) AS delayed_bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + metric_time__day + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_15 + WHERE NOT booking__is_instant + ) subq_17 WHERE NOT booking__is_instant GROUP BY metric_time__day -) subq_13 +) subq_21 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_distinct_values__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_distinct_values__plan0.sql index cf9f152551..72b8fe6a27 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_distinct_values__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_distinct_values__plan0.sql @@ -1,134 +1,195 @@ -- Order By ['listing__country_latest'] Limit 100 SELECT - subq_2.listing__country_latest + subq_5.listing__country_latest FROM ( -- Pass Only Elements: ['listing__country_latest',] SELECT - subq_1.listing__country_latest + subq_4.listing__country_latest FROM ( -- Constrain Output with WHERE 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.created_at__day - , subq_0.created_at__week - , subq_0.created_at__month - , subq_0.created_at__quarter - , subq_0.created_at__year - , subq_0.created_at__extract_year - , subq_0.created_at__extract_quarter - , subq_0.created_at__extract_month - , subq_0.created_at__extract_day - , subq_0.created_at__extract_dow - , subq_0.created_at__extract_doy - , subq_0.listing__ds__day - , subq_0.listing__ds__week - , subq_0.listing__ds__month - , subq_0.listing__ds__quarter - , subq_0.listing__ds__year - , subq_0.listing__ds__extract_year - , subq_0.listing__ds__extract_quarter - , subq_0.listing__ds__extract_month - , subq_0.listing__ds__extract_day - , subq_0.listing__ds__extract_dow - , subq_0.listing__ds__extract_doy - , subq_0.listing__created_at__day - , subq_0.listing__created_at__week - , subq_0.listing__created_at__month - , subq_0.listing__created_at__quarter - , subq_0.listing__created_at__year - , subq_0.listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month - , subq_0.listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow - , subq_0.listing__created_at__extract_doy - , subq_0.listing - , subq_0.user - , subq_0.listing__user - , subq_0.country_latest - , subq_0.is_lux_latest - , subq_0.capacity_latest - , subq_0.listing__country_latest - , subq_0.listing__is_lux_latest - , subq_0.listing__capacity_latest - , subq_0.listings - , subq_0.largest_listing - , subq_0.smallest_listing + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing FROM ( - -- Read Elements From Semantic Model 'listings_latest' + -- Constrain Output with WHERE SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , listings_latest_src_28000.user_id AS user - , listings_latest_src_28000.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_0 + subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.created_at__day + , subq_2.created_at__week + , subq_2.created_at__month + , subq_2.created_at__quarter + , subq_2.created_at__year + , subq_2.created_at__extract_year + , subq_2.created_at__extract_quarter + , subq_2.created_at__extract_month + , subq_2.created_at__extract_day + , subq_2.created_at__extract_dow + , subq_2.created_at__extract_doy + , subq_2.listing__ds__day + , subq_2.listing__ds__week + , subq_2.listing__ds__month + , subq_2.listing__ds__quarter + , subq_2.listing__ds__year + , subq_2.listing__ds__extract_year + , subq_2.listing__ds__extract_quarter + , subq_2.listing__ds__extract_month + , subq_2.listing__ds__extract_day + , subq_2.listing__ds__extract_dow + , subq_2.listing__ds__extract_doy + , subq_2.listing__created_at__day + , subq_2.listing__created_at__week + , subq_2.listing__created_at__month + , subq_2.listing__created_at__quarter + , subq_2.listing__created_at__year + , subq_2.listing__created_at__extract_year + , subq_2.listing__created_at__extract_quarter + , subq_2.listing__created_at__extract_month + , subq_2.listing__created_at__extract_day + , subq_2.listing__created_at__extract_dow + , subq_2.listing__created_at__extract_doy + , subq_2.listing + , subq_2.user + , subq_2.listing__user + , subq_2.country_latest + , subq_2.is_lux_latest + , subq_2.capacity_latest + , subq_2.listing__country_latest + , subq_2.listing__is_lux_latest + , subq_2.listing__capacity_latest + , subq_2.listings + , subq_2.largest_listing + , subq_2.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_2 + WHERE listing__country_latest = 'us' + ) subq_3 WHERE listing__country_latest = 'us' - ) subq_1 + ) subq_4 GROUP BY - subq_1.listing__country_latest -) subq_2 -ORDER BY subq_2.listing__country_latest DESC + subq_4.listing__country_latest +) subq_5 +ORDER BY subq_5.listing__country_latest DESC LIMIT 100 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_distinct_values__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_distinct_values__plan0_optimized.sql index 1653ada5bd..76e6591b6c 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_distinct_values__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_distinct_values__plan0_optimized.sql @@ -4,11 +4,17 @@ SELECT listing__country_latest FROM ( - -- Read Elements From Semantic Model 'listings_latest' + -- Constrain Output with WHERE SELECT - country AS listing__country_latest - FROM ***************************.dim_listings_latest listings_latest_src_28000 -) subq_3 + listing__country_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + country AS listing__country_latest + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_6 + WHERE listing__country_latest = 'us' +) subq_7 WHERE listing__country_latest = 'us' GROUP BY listing__country_latest diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_reused_measure__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_reused_measure__plan0.sql index cda95b14fc..e51209f538 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_reused_measure__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_reused_measure__plan0.sql @@ -1,359 +1,462 @@ -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day - , CAST(subq_12.booking_value_with_is_instant_constraint AS DOUBLE PRECISION) / CAST(NULLIF(subq_12.booking_value, 0) AS DOUBLE PRECISION) AS instant_booking_value_ratio + subq_19.metric_time__day + , CAST(subq_19.booking_value_with_is_instant_constraint AS DOUBLE PRECISION) / CAST(NULLIF(subq_19.booking_value, 0) AS DOUBLE PRECISION) AS instant_booking_value_ratio FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) AS metric_time__day - , MAX(subq_6.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_11.booking_value) AS booking_value + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) AS metric_time__day + , MAX(subq_13.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_18.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.booking_value AS booking_value_with_is_instant_constraint + subq_12.metric_time__day + , subq_12.booking_value AS booking_value_with_is_instant_constraint FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.booking_value) AS booking_value + subq_11.metric_time__day + , SUM(subq_11.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.booking_value + subq_10.metric_time__day + , subq_10.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.booking_value + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.booking_value + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE 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.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.booking__paid_at__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.listing - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_7.ds__day + , subq_7.ds__week + , subq_7.ds__month + , subq_7.ds__quarter + , subq_7.ds__year + , subq_7.ds__extract_year + , subq_7.ds__extract_quarter + , subq_7.ds__extract_month + , subq_7.ds__extract_day + , subq_7.ds__extract_dow + , subq_7.ds__extract_doy + , subq_7.ds_partitioned__day + , subq_7.ds_partitioned__week + , subq_7.ds_partitioned__month + , subq_7.ds_partitioned__quarter + , subq_7.ds_partitioned__year + , subq_7.ds_partitioned__extract_year + , subq_7.ds_partitioned__extract_quarter + , subq_7.ds_partitioned__extract_month + , subq_7.ds_partitioned__extract_day + , subq_7.ds_partitioned__extract_dow + , subq_7.ds_partitioned__extract_doy + , subq_7.paid_at__day + , subq_7.paid_at__week + , subq_7.paid_at__month + , subq_7.paid_at__quarter + , subq_7.paid_at__year + , subq_7.paid_at__extract_year + , subq_7.paid_at__extract_quarter + , subq_7.paid_at__extract_month + , subq_7.paid_at__extract_day + , subq_7.paid_at__extract_dow + , subq_7.paid_at__extract_doy + , subq_7.booking__ds__day + , subq_7.booking__ds__week + , subq_7.booking__ds__month + , subq_7.booking__ds__quarter + , subq_7.booking__ds__year + , subq_7.booking__ds__extract_year + , subq_7.booking__ds__extract_quarter + , subq_7.booking__ds__extract_month + , subq_7.booking__ds__extract_day + , subq_7.booking__ds__extract_dow + , subq_7.booking__ds__extract_doy + , subq_7.booking__ds_partitioned__day + , subq_7.booking__ds_partitioned__week + , subq_7.booking__ds_partitioned__month + , subq_7.booking__ds_partitioned__quarter + , subq_7.booking__ds_partitioned__year + , subq_7.booking__ds_partitioned__extract_year + , subq_7.booking__ds_partitioned__extract_quarter + , subq_7.booking__ds_partitioned__extract_month + , subq_7.booking__ds_partitioned__extract_day + , subq_7.booking__ds_partitioned__extract_dow + , subq_7.booking__ds_partitioned__extract_doy + , subq_7.booking__paid_at__day + , subq_7.booking__paid_at__week + , subq_7.booking__paid_at__month + , subq_7.booking__paid_at__quarter + , subq_7.booking__paid_at__year + , subq_7.booking__paid_at__extract_year + , subq_7.booking__paid_at__extract_quarter + , subq_7.booking__paid_at__extract_month + , subq_7.booking__paid_at__extract_day + , subq_7.booking__paid_at__extract_dow + , subq_7.booking__paid_at__extract_doy + , subq_7.metric_time__day + , subq_7.metric_time__week + , subq_7.metric_time__month + , subq_7.metric_time__quarter + , subq_7.metric_time__year + , subq_7.metric_time__extract_year + , subq_7.metric_time__extract_quarter + , subq_7.metric_time__extract_month + , subq_7.metric_time__extract_day + , subq_7.metric_time__extract_dow + , subq_7.metric_time__extract_doy + , subq_7.listing + , subq_7.guest + , subq_7.host + , subq_7.booking__listing + , subq_7.booking__guest + , subq_7.booking__host + , subq_7.is_instant + , subq_7.booking__is_instant + , subq_7.bookings + , subq_7.instant_bookings + , subq_7.booking_value + , subq_7.max_booking_value + , subq_7.min_booking_value + , subq_7.bookers + , subq_7.average_booking_value + , subq_7.referred_bookings + , subq_7.median_booking_value + , subq_7.booking_value_p99 + , subq_7.discrete_booking_value_p99 + , subq_7.approximate_continuous_booking_value_p99 + , subq_7.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + 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.ds_partitioned__day + , subq_6.ds_partitioned__week + , subq_6.ds_partitioned__month + , subq_6.ds_partitioned__quarter + , subq_6.ds_partitioned__year + , subq_6.ds_partitioned__extract_year + , subq_6.ds_partitioned__extract_quarter + , subq_6.ds_partitioned__extract_month + , subq_6.ds_partitioned__extract_day + , subq_6.ds_partitioned__extract_dow + , subq_6.ds_partitioned__extract_doy + , subq_6.paid_at__day + , subq_6.paid_at__week + , subq_6.paid_at__month + , subq_6.paid_at__quarter + , subq_6.paid_at__year + , subq_6.paid_at__extract_year + , subq_6.paid_at__extract_quarter + , subq_6.paid_at__extract_month + , subq_6.paid_at__extract_day + , subq_6.paid_at__extract_dow + , subq_6.paid_at__extract_doy + , subq_6.booking__ds__day + , subq_6.booking__ds__week + , subq_6.booking__ds__month + , subq_6.booking__ds__quarter + , subq_6.booking__ds__year + , subq_6.booking__ds__extract_year + , subq_6.booking__ds__extract_quarter + , subq_6.booking__ds__extract_month + , subq_6.booking__ds__extract_day + , subq_6.booking__ds__extract_dow + , subq_6.booking__ds__extract_doy + , subq_6.booking__ds_partitioned__day + , subq_6.booking__ds_partitioned__week + , subq_6.booking__ds_partitioned__month + , subq_6.booking__ds_partitioned__quarter + , subq_6.booking__ds_partitioned__year + , subq_6.booking__ds_partitioned__extract_year + , subq_6.booking__ds_partitioned__extract_quarter + , subq_6.booking__ds_partitioned__extract_month + , subq_6.booking__ds_partitioned__extract_day + , subq_6.booking__ds_partitioned__extract_dow + , subq_6.booking__ds_partitioned__extract_doy + , subq_6.booking__paid_at__day + , subq_6.booking__paid_at__week + , subq_6.booking__paid_at__month + , subq_6.booking__paid_at__quarter + , subq_6.booking__paid_at__year + , subq_6.booking__paid_at__extract_year + , subq_6.booking__paid_at__extract_quarter + , subq_6.booking__paid_at__extract_month + , subq_6.booking__paid_at__extract_day + , subq_6.booking__paid_at__extract_dow + , subq_6.booking__paid_at__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.listing + , subq_6.guest + , subq_6.host + , subq_6.booking__listing + , subq_6.booking__guest + , subq_6.booking__host + , subq_6.is_instant + , subq_6.booking__is_instant + , subq_6.bookings + , subq_6.instant_bookings + , subq_6.booking_value + , subq_6.max_booking_value + , subq_6.min_booking_value + , subq_6.bookers + , subq_6.average_booking_value + , subq_6.referred_bookings + , subq_6.median_booking_value + , subq_6.booking_value_p99 + , subq_6.discrete_booking_value_p99 + , subq_6.approximate_continuous_booking_value_p99 + , subq_6.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 WHERE booking__is_instant - ) subq_3 - ) subq_4 + ) subq_10 + ) subq_11 GROUP BY - subq_4.metric_time__day - ) subq_5 - ) subq_6 + subq_11.metric_time__day + ) subq_12 + ) subq_13 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day - , subq_10.booking_value + subq_17.metric_time__day + , subq_17.booking_value FROM ( -- Aggregate Measures SELECT - subq_9.metric_time__day - , SUM(subq_9.booking_value) AS booking_value + subq_16.metric_time__day + , SUM(subq_16.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'metric_time__day'] SELECT - subq_8.metric_time__day - , subq_8.booking_value + subq_15.metric_time__day + , subq_15.booking_value FROM ( -- Metric Time Dimension 'ds' SELECT - subq_7.ds__day - , subq_7.ds__week - , subq_7.ds__month - , subq_7.ds__quarter - , subq_7.ds__year - , subq_7.ds__extract_year - , subq_7.ds__extract_quarter - , subq_7.ds__extract_month - , subq_7.ds__extract_day - , subq_7.ds__extract_dow - , subq_7.ds__extract_doy - , subq_7.ds_partitioned__day - , subq_7.ds_partitioned__week - , subq_7.ds_partitioned__month - , subq_7.ds_partitioned__quarter - , subq_7.ds_partitioned__year - , subq_7.ds_partitioned__extract_year - , subq_7.ds_partitioned__extract_quarter - , subq_7.ds_partitioned__extract_month - , subq_7.ds_partitioned__extract_day - , subq_7.ds_partitioned__extract_dow - , subq_7.ds_partitioned__extract_doy - , subq_7.paid_at__day - , subq_7.paid_at__week - , subq_7.paid_at__month - , subq_7.paid_at__quarter - , subq_7.paid_at__year - , subq_7.paid_at__extract_year - , subq_7.paid_at__extract_quarter - , subq_7.paid_at__extract_month - , subq_7.paid_at__extract_day - , subq_7.paid_at__extract_dow - , subq_7.paid_at__extract_doy - , subq_7.booking__ds__day - , subq_7.booking__ds__week - , subq_7.booking__ds__month - , subq_7.booking__ds__quarter - , subq_7.booking__ds__year - , subq_7.booking__ds__extract_year - , subq_7.booking__ds__extract_quarter - , subq_7.booking__ds__extract_month - , subq_7.booking__ds__extract_day - , subq_7.booking__ds__extract_dow - , subq_7.booking__ds__extract_doy - , subq_7.booking__ds_partitioned__day - , subq_7.booking__ds_partitioned__week - , subq_7.booking__ds_partitioned__month - , subq_7.booking__ds_partitioned__quarter - , subq_7.booking__ds_partitioned__year - , subq_7.booking__ds_partitioned__extract_year - , subq_7.booking__ds_partitioned__extract_quarter - , subq_7.booking__ds_partitioned__extract_month - , subq_7.booking__ds_partitioned__extract_day - , subq_7.booking__ds_partitioned__extract_dow - , subq_7.booking__ds_partitioned__extract_doy - , subq_7.booking__paid_at__day - , subq_7.booking__paid_at__week - , subq_7.booking__paid_at__month - , subq_7.booking__paid_at__quarter - , subq_7.booking__paid_at__year - , subq_7.booking__paid_at__extract_year - , subq_7.booking__paid_at__extract_quarter - , subq_7.booking__paid_at__extract_month - , subq_7.booking__paid_at__extract_day - , subq_7.booking__paid_at__extract_dow - , subq_7.booking__paid_at__extract_doy - , subq_7.ds__day AS metric_time__day - , subq_7.ds__week AS metric_time__week - , subq_7.ds__month AS metric_time__month - , subq_7.ds__quarter AS metric_time__quarter - , subq_7.ds__year AS metric_time__year - , subq_7.ds__extract_year AS metric_time__extract_year - , subq_7.ds__extract_quarter AS metric_time__extract_quarter - , subq_7.ds__extract_month AS metric_time__extract_month - , subq_7.ds__extract_day AS metric_time__extract_day - , subq_7.ds__extract_dow AS metric_time__extract_dow - , subq_7.ds__extract_doy AS metric_time__extract_doy - , subq_7.listing - , subq_7.guest - , subq_7.host - , subq_7.booking__listing - , subq_7.booking__guest - , subq_7.booking__host - , subq_7.is_instant - , subq_7.booking__is_instant - , subq_7.bookings - , subq_7.instant_bookings - , subq_7.booking_value - , subq_7.max_booking_value - , subq_7.min_booking_value - , subq_7.bookers - , subq_7.average_booking_value - , subq_7.referred_bookings - , subq_7.median_booking_value - , subq_7.booking_value_p99 - , subq_7.discrete_booking_value_p99 - , subq_7.approximate_continuous_booking_value_p99 - , subq_7.approximate_discrete_booking_value_p99 + subq_14.ds__day + , subq_14.ds__week + , subq_14.ds__month + , subq_14.ds__quarter + , subq_14.ds__year + , subq_14.ds__extract_year + , subq_14.ds__extract_quarter + , subq_14.ds__extract_month + , subq_14.ds__extract_day + , subq_14.ds__extract_dow + , subq_14.ds__extract_doy + , subq_14.ds_partitioned__day + , subq_14.ds_partitioned__week + , subq_14.ds_partitioned__month + , subq_14.ds_partitioned__quarter + , subq_14.ds_partitioned__year + , subq_14.ds_partitioned__extract_year + , subq_14.ds_partitioned__extract_quarter + , subq_14.ds_partitioned__extract_month + , subq_14.ds_partitioned__extract_day + , subq_14.ds_partitioned__extract_dow + , subq_14.ds_partitioned__extract_doy + , subq_14.paid_at__day + , subq_14.paid_at__week + , subq_14.paid_at__month + , subq_14.paid_at__quarter + , subq_14.paid_at__year + , subq_14.paid_at__extract_year + , subq_14.paid_at__extract_quarter + , subq_14.paid_at__extract_month + , subq_14.paid_at__extract_day + , subq_14.paid_at__extract_dow + , subq_14.paid_at__extract_doy + , subq_14.booking__ds__day + , subq_14.booking__ds__week + , subq_14.booking__ds__month + , subq_14.booking__ds__quarter + , subq_14.booking__ds__year + , subq_14.booking__ds__extract_year + , subq_14.booking__ds__extract_quarter + , subq_14.booking__ds__extract_month + , subq_14.booking__ds__extract_day + , subq_14.booking__ds__extract_dow + , subq_14.booking__ds__extract_doy + , subq_14.booking__ds_partitioned__day + , subq_14.booking__ds_partitioned__week + , subq_14.booking__ds_partitioned__month + , subq_14.booking__ds_partitioned__quarter + , subq_14.booking__ds_partitioned__year + , subq_14.booking__ds_partitioned__extract_year + , subq_14.booking__ds_partitioned__extract_quarter + , subq_14.booking__ds_partitioned__extract_month + , subq_14.booking__ds_partitioned__extract_day + , subq_14.booking__ds_partitioned__extract_dow + , subq_14.booking__ds_partitioned__extract_doy + , subq_14.booking__paid_at__day + , subq_14.booking__paid_at__week + , subq_14.booking__paid_at__month + , subq_14.booking__paid_at__quarter + , subq_14.booking__paid_at__year + , subq_14.booking__paid_at__extract_year + , subq_14.booking__paid_at__extract_quarter + , subq_14.booking__paid_at__extract_month + , subq_14.booking__paid_at__extract_day + , subq_14.booking__paid_at__extract_dow + , subq_14.booking__paid_at__extract_doy + , subq_14.ds__day AS metric_time__day + , subq_14.ds__week AS metric_time__week + , subq_14.ds__month AS metric_time__month + , subq_14.ds__quarter AS metric_time__quarter + , subq_14.ds__year AS metric_time__year + , subq_14.ds__extract_year AS metric_time__extract_year + , subq_14.ds__extract_quarter AS metric_time__extract_quarter + , subq_14.ds__extract_month AS metric_time__extract_month + , subq_14.ds__extract_day AS metric_time__extract_day + , subq_14.ds__extract_dow AS metric_time__extract_dow + , subq_14.ds__extract_doy AS metric_time__extract_doy + , subq_14.listing + , subq_14.guest + , subq_14.host + , subq_14.booking__listing + , subq_14.booking__guest + , subq_14.booking__host + , subq_14.is_instant + , subq_14.booking__is_instant + , subq_14.bookings + , subq_14.instant_bookings + , subq_14.booking_value + , subq_14.max_booking_value + , subq_14.min_booking_value + , subq_14.bookers + , subq_14.average_booking_value + , subq_14.referred_bookings + , subq_14.median_booking_value + , subq_14.booking_value_p99 + , subq_14.discrete_booking_value_p99 + , subq_14.approximate_continuous_booking_value_p99 + , subq_14.approximate_discrete_booking_value_p99 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -446,15 +549,15 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_7 - ) subq_8 - ) subq_9 + ) subq_14 + ) subq_15 + ) subq_16 GROUP BY - subq_9.metric_time__day - ) subq_10 - ) subq_11 + subq_16.metric_time__day + ) subq_17 + ) subq_18 ON - subq_6.metric_time__day = subq_11.metric_time__day + subq_13.metric_time__day = subq_18.metric_time__day GROUP BY - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) -) subq_12 + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) +) subq_19 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_reused_measure__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_reused_measure__plan0_optimized.sql index e3a93f4824..29af02b578 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_reused_measure__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_reused_measure__plan0_optimized.sql @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) AS metric_time__day - , MAX(subq_19.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_24.booking_value) AS booking_value + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) AS metric_time__day + , MAX(subq_27.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_32.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'metric_time__day'] @@ -17,19 +17,27 @@ FROM ( metric_time__day , SUM(booking_value) AS booking_value_with_is_instant_constraint FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant + metric_time__day + , booking__is_instant , booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_15 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_21 + WHERE booking__is_instant + ) subq_23 WHERE booking__is_instant GROUP BY metric_time__day - ) subq_19 + ) subq_27 FULL OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -42,9 +50,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY DATE_TRUNC('day', ds) - ) subq_24 + ) subq_32 ON - subq_19.metric_time__day = subq_24.metric_time__day + subq_27.metric_time__day = subq_32.metric_time__day GROUP BY - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) -) subq_25 + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) +) subq_33 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_single_expr_and_alias__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_single_expr_and_alias__plan0.sql index 6b26ce724b..882a6a8201 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_single_expr_and_alias__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_single_expr_and_alias__plan0.sql @@ -1,234 +1,337 @@ -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day + subq_13.metric_time__day , delayed_bookings * 2 AS double_counted_delayed_bookings FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.bookings AS delayed_bookings + subq_12.metric_time__day + , subq_12.bookings AS delayed_bookings FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.bookings) AS bookings + subq_11.metric_time__day + , SUM(subq_11.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.bookings + subq_10.metric_time__day + , subq_10.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE 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.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.booking__paid_at__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.listing - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_7.ds__day + , subq_7.ds__week + , subq_7.ds__month + , subq_7.ds__quarter + , subq_7.ds__year + , subq_7.ds__extract_year + , subq_7.ds__extract_quarter + , subq_7.ds__extract_month + , subq_7.ds__extract_day + , subq_7.ds__extract_dow + , subq_7.ds__extract_doy + , subq_7.ds_partitioned__day + , subq_7.ds_partitioned__week + , subq_7.ds_partitioned__month + , subq_7.ds_partitioned__quarter + , subq_7.ds_partitioned__year + , subq_7.ds_partitioned__extract_year + , subq_7.ds_partitioned__extract_quarter + , subq_7.ds_partitioned__extract_month + , subq_7.ds_partitioned__extract_day + , subq_7.ds_partitioned__extract_dow + , subq_7.ds_partitioned__extract_doy + , subq_7.paid_at__day + , subq_7.paid_at__week + , subq_7.paid_at__month + , subq_7.paid_at__quarter + , subq_7.paid_at__year + , subq_7.paid_at__extract_year + , subq_7.paid_at__extract_quarter + , subq_7.paid_at__extract_month + , subq_7.paid_at__extract_day + , subq_7.paid_at__extract_dow + , subq_7.paid_at__extract_doy + , subq_7.booking__ds__day + , subq_7.booking__ds__week + , subq_7.booking__ds__month + , subq_7.booking__ds__quarter + , subq_7.booking__ds__year + , subq_7.booking__ds__extract_year + , subq_7.booking__ds__extract_quarter + , subq_7.booking__ds__extract_month + , subq_7.booking__ds__extract_day + , subq_7.booking__ds__extract_dow + , subq_7.booking__ds__extract_doy + , subq_7.booking__ds_partitioned__day + , subq_7.booking__ds_partitioned__week + , subq_7.booking__ds_partitioned__month + , subq_7.booking__ds_partitioned__quarter + , subq_7.booking__ds_partitioned__year + , subq_7.booking__ds_partitioned__extract_year + , subq_7.booking__ds_partitioned__extract_quarter + , subq_7.booking__ds_partitioned__extract_month + , subq_7.booking__ds_partitioned__extract_day + , subq_7.booking__ds_partitioned__extract_dow + , subq_7.booking__ds_partitioned__extract_doy + , subq_7.booking__paid_at__day + , subq_7.booking__paid_at__week + , subq_7.booking__paid_at__month + , subq_7.booking__paid_at__quarter + , subq_7.booking__paid_at__year + , subq_7.booking__paid_at__extract_year + , subq_7.booking__paid_at__extract_quarter + , subq_7.booking__paid_at__extract_month + , subq_7.booking__paid_at__extract_day + , subq_7.booking__paid_at__extract_dow + , subq_7.booking__paid_at__extract_doy + , subq_7.metric_time__day + , subq_7.metric_time__week + , subq_7.metric_time__month + , subq_7.metric_time__quarter + , subq_7.metric_time__year + , subq_7.metric_time__extract_year + , subq_7.metric_time__extract_quarter + , subq_7.metric_time__extract_month + , subq_7.metric_time__extract_day + , subq_7.metric_time__extract_dow + , subq_7.metric_time__extract_doy + , subq_7.listing + , subq_7.guest + , subq_7.host + , subq_7.booking__listing + , subq_7.booking__guest + , subq_7.booking__host + , subq_7.is_instant + , subq_7.booking__is_instant + , subq_7.bookings + , subq_7.instant_bookings + , subq_7.booking_value + , subq_7.max_booking_value + , subq_7.min_booking_value + , subq_7.bookers + , subq_7.average_booking_value + , subq_7.referred_bookings + , subq_7.median_booking_value + , subq_7.booking_value_p99 + , subq_7.discrete_booking_value_p99 + , subq_7.approximate_continuous_booking_value_p99 + , subq_7.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + 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.ds_partitioned__day + , subq_6.ds_partitioned__week + , subq_6.ds_partitioned__month + , subq_6.ds_partitioned__quarter + , subq_6.ds_partitioned__year + , subq_6.ds_partitioned__extract_year + , subq_6.ds_partitioned__extract_quarter + , subq_6.ds_partitioned__extract_month + , subq_6.ds_partitioned__extract_day + , subq_6.ds_partitioned__extract_dow + , subq_6.ds_partitioned__extract_doy + , subq_6.paid_at__day + , subq_6.paid_at__week + , subq_6.paid_at__month + , subq_6.paid_at__quarter + , subq_6.paid_at__year + , subq_6.paid_at__extract_year + , subq_6.paid_at__extract_quarter + , subq_6.paid_at__extract_month + , subq_6.paid_at__extract_day + , subq_6.paid_at__extract_dow + , subq_6.paid_at__extract_doy + , subq_6.booking__ds__day + , subq_6.booking__ds__week + , subq_6.booking__ds__month + , subq_6.booking__ds__quarter + , subq_6.booking__ds__year + , subq_6.booking__ds__extract_year + , subq_6.booking__ds__extract_quarter + , subq_6.booking__ds__extract_month + , subq_6.booking__ds__extract_day + , subq_6.booking__ds__extract_dow + , subq_6.booking__ds__extract_doy + , subq_6.booking__ds_partitioned__day + , subq_6.booking__ds_partitioned__week + , subq_6.booking__ds_partitioned__month + , subq_6.booking__ds_partitioned__quarter + , subq_6.booking__ds_partitioned__year + , subq_6.booking__ds_partitioned__extract_year + , subq_6.booking__ds_partitioned__extract_quarter + , subq_6.booking__ds_partitioned__extract_month + , subq_6.booking__ds_partitioned__extract_day + , subq_6.booking__ds_partitioned__extract_dow + , subq_6.booking__ds_partitioned__extract_doy + , subq_6.booking__paid_at__day + , subq_6.booking__paid_at__week + , subq_6.booking__paid_at__month + , subq_6.booking__paid_at__quarter + , subq_6.booking__paid_at__year + , subq_6.booking__paid_at__extract_year + , subq_6.booking__paid_at__extract_quarter + , subq_6.booking__paid_at__extract_month + , subq_6.booking__paid_at__extract_day + , subq_6.booking__paid_at__extract_dow + , subq_6.booking__paid_at__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.listing + , subq_6.guest + , subq_6.host + , subq_6.booking__listing + , subq_6.booking__guest + , subq_6.booking__host + , subq_6.is_instant + , subq_6.booking__is_instant + , subq_6.bookings + , subq_6.instant_bookings + , subq_6.booking_value + , subq_6.max_booking_value + , subq_6.min_booking_value + , subq_6.bookers + , subq_6.average_booking_value + , subq_6.referred_bookings + , subq_6.median_booking_value + , subq_6.booking_value_p99 + , subq_6.discrete_booking_value_p99 + , subq_6.approximate_continuous_booking_value_p99 + , subq_6.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_6 + ) subq_7 + WHERE NOT booking__is_instant + ) subq_8 + ) subq_9 WHERE NOT booking__is_instant - ) subq_3 - ) subq_4 + ) subq_10 + ) subq_11 GROUP BY - subq_4.metric_time__day - ) subq_5 -) subq_6 + subq_11.metric_time__day + ) subq_12 +) subq_13 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql index 3202b9915d..33436b83b6 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql @@ -11,16 +11,24 @@ FROM ( metric_time__day , SUM(bookings) AS delayed_bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + metric_time__day + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_15 + WHERE NOT booking__is_instant + ) subq_17 WHERE NOT booking__is_instant GROUP BY metric_time__day -) subq_13 +) subq_21 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_distinct_values__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_distinct_values__plan0.sql index 0a82b5e771..1c8af99bba 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_distinct_values__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_distinct_values__plan0.sql @@ -1,134 +1,195 @@ -- Order By ['listing__country_latest'] Limit 100 SELECT - subq_2.listing__country_latest + subq_5.listing__country_latest FROM ( -- Pass Only Elements: ['listing__country_latest',] SELECT - subq_1.listing__country_latest + subq_4.listing__country_latest FROM ( -- Constrain Output with WHERE 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.created_at__day - , subq_0.created_at__week - , subq_0.created_at__month - , subq_0.created_at__quarter - , subq_0.created_at__year - , subq_0.created_at__extract_year - , subq_0.created_at__extract_quarter - , subq_0.created_at__extract_month - , subq_0.created_at__extract_day - , subq_0.created_at__extract_dow - , subq_0.created_at__extract_doy - , subq_0.listing__ds__day - , subq_0.listing__ds__week - , subq_0.listing__ds__month - , subq_0.listing__ds__quarter - , subq_0.listing__ds__year - , subq_0.listing__ds__extract_year - , subq_0.listing__ds__extract_quarter - , subq_0.listing__ds__extract_month - , subq_0.listing__ds__extract_day - , subq_0.listing__ds__extract_dow - , subq_0.listing__ds__extract_doy - , subq_0.listing__created_at__day - , subq_0.listing__created_at__week - , subq_0.listing__created_at__month - , subq_0.listing__created_at__quarter - , subq_0.listing__created_at__year - , subq_0.listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month - , subq_0.listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow - , subq_0.listing__created_at__extract_doy - , subq_0.listing - , subq_0.user - , subq_0.listing__user - , subq_0.country_latest - , subq_0.is_lux_latest - , subq_0.capacity_latest - , subq_0.listing__country_latest - , subq_0.listing__is_lux_latest - , subq_0.listing__capacity_latest - , subq_0.listings - , subq_0.largest_listing - , subq_0.smallest_listing + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing FROM ( - -- Read Elements From Semantic Model 'listings_latest' + -- Constrain Output with WHERE SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , listings_latest_src_28000.user_id AS user - , listings_latest_src_28000.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_0 + subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.created_at__day + , subq_2.created_at__week + , subq_2.created_at__month + , subq_2.created_at__quarter + , subq_2.created_at__year + , subq_2.created_at__extract_year + , subq_2.created_at__extract_quarter + , subq_2.created_at__extract_month + , subq_2.created_at__extract_day + , subq_2.created_at__extract_dow + , subq_2.created_at__extract_doy + , subq_2.listing__ds__day + , subq_2.listing__ds__week + , subq_2.listing__ds__month + , subq_2.listing__ds__quarter + , subq_2.listing__ds__year + , subq_2.listing__ds__extract_year + , subq_2.listing__ds__extract_quarter + , subq_2.listing__ds__extract_month + , subq_2.listing__ds__extract_day + , subq_2.listing__ds__extract_dow + , subq_2.listing__ds__extract_doy + , subq_2.listing__created_at__day + , subq_2.listing__created_at__week + , subq_2.listing__created_at__month + , subq_2.listing__created_at__quarter + , subq_2.listing__created_at__year + , subq_2.listing__created_at__extract_year + , subq_2.listing__created_at__extract_quarter + , subq_2.listing__created_at__extract_month + , subq_2.listing__created_at__extract_day + , subq_2.listing__created_at__extract_dow + , subq_2.listing__created_at__extract_doy + , subq_2.listing + , subq_2.user + , subq_2.listing__user + , subq_2.country_latest + , subq_2.is_lux_latest + , subq_2.capacity_latest + , subq_2.listing__country_latest + , subq_2.listing__is_lux_latest + , subq_2.listing__capacity_latest + , subq_2.listings + , subq_2.largest_listing + , subq_2.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_2 + WHERE listing__country_latest = 'us' + ) subq_3 WHERE listing__country_latest = 'us' - ) subq_1 + ) subq_4 GROUP BY - subq_1.listing__country_latest -) subq_2 -ORDER BY subq_2.listing__country_latest DESC + subq_4.listing__country_latest +) subq_5 +ORDER BY subq_5.listing__country_latest DESC LIMIT 100 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_distinct_values__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_distinct_values__plan0_optimized.sql index 1653ada5bd..76e6591b6c 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_distinct_values__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_distinct_values__plan0_optimized.sql @@ -4,11 +4,17 @@ SELECT listing__country_latest FROM ( - -- Read Elements From Semantic Model 'listings_latest' + -- Constrain Output with WHERE SELECT - country AS listing__country_latest - FROM ***************************.dim_listings_latest listings_latest_src_28000 -) subq_3 + listing__country_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + country AS listing__country_latest + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_6 + WHERE listing__country_latest = 'us' +) subq_7 WHERE listing__country_latest = 'us' GROUP BY listing__country_latest diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_reused_measure__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_reused_measure__plan0.sql index 09af3a3c27..41e951d762 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_reused_measure__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_reused_measure__plan0.sql @@ -1,359 +1,462 @@ -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day - , CAST(subq_12.booking_value_with_is_instant_constraint AS DOUBLE) / CAST(NULLIF(subq_12.booking_value, 0) AS DOUBLE) AS instant_booking_value_ratio + subq_19.metric_time__day + , CAST(subq_19.booking_value_with_is_instant_constraint AS DOUBLE) / CAST(NULLIF(subq_19.booking_value, 0) AS DOUBLE) AS instant_booking_value_ratio FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) AS metric_time__day - , MAX(subq_6.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_11.booking_value) AS booking_value + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) AS metric_time__day + , MAX(subq_13.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_18.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.booking_value AS booking_value_with_is_instant_constraint + subq_12.metric_time__day + , subq_12.booking_value AS booking_value_with_is_instant_constraint FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.booking_value) AS booking_value + subq_11.metric_time__day + , SUM(subq_11.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.booking_value + subq_10.metric_time__day + , subq_10.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.booking_value + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.booking_value + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE 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.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.booking__paid_at__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.listing - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_7.ds__day + , subq_7.ds__week + , subq_7.ds__month + , subq_7.ds__quarter + , subq_7.ds__year + , subq_7.ds__extract_year + , subq_7.ds__extract_quarter + , subq_7.ds__extract_month + , subq_7.ds__extract_day + , subq_7.ds__extract_dow + , subq_7.ds__extract_doy + , subq_7.ds_partitioned__day + , subq_7.ds_partitioned__week + , subq_7.ds_partitioned__month + , subq_7.ds_partitioned__quarter + , subq_7.ds_partitioned__year + , subq_7.ds_partitioned__extract_year + , subq_7.ds_partitioned__extract_quarter + , subq_7.ds_partitioned__extract_month + , subq_7.ds_partitioned__extract_day + , subq_7.ds_partitioned__extract_dow + , subq_7.ds_partitioned__extract_doy + , subq_7.paid_at__day + , subq_7.paid_at__week + , subq_7.paid_at__month + , subq_7.paid_at__quarter + , subq_7.paid_at__year + , subq_7.paid_at__extract_year + , subq_7.paid_at__extract_quarter + , subq_7.paid_at__extract_month + , subq_7.paid_at__extract_day + , subq_7.paid_at__extract_dow + , subq_7.paid_at__extract_doy + , subq_7.booking__ds__day + , subq_7.booking__ds__week + , subq_7.booking__ds__month + , subq_7.booking__ds__quarter + , subq_7.booking__ds__year + , subq_7.booking__ds__extract_year + , subq_7.booking__ds__extract_quarter + , subq_7.booking__ds__extract_month + , subq_7.booking__ds__extract_day + , subq_7.booking__ds__extract_dow + , subq_7.booking__ds__extract_doy + , subq_7.booking__ds_partitioned__day + , subq_7.booking__ds_partitioned__week + , subq_7.booking__ds_partitioned__month + , subq_7.booking__ds_partitioned__quarter + , subq_7.booking__ds_partitioned__year + , subq_7.booking__ds_partitioned__extract_year + , subq_7.booking__ds_partitioned__extract_quarter + , subq_7.booking__ds_partitioned__extract_month + , subq_7.booking__ds_partitioned__extract_day + , subq_7.booking__ds_partitioned__extract_dow + , subq_7.booking__ds_partitioned__extract_doy + , subq_7.booking__paid_at__day + , subq_7.booking__paid_at__week + , subq_7.booking__paid_at__month + , subq_7.booking__paid_at__quarter + , subq_7.booking__paid_at__year + , subq_7.booking__paid_at__extract_year + , subq_7.booking__paid_at__extract_quarter + , subq_7.booking__paid_at__extract_month + , subq_7.booking__paid_at__extract_day + , subq_7.booking__paid_at__extract_dow + , subq_7.booking__paid_at__extract_doy + , subq_7.metric_time__day + , subq_7.metric_time__week + , subq_7.metric_time__month + , subq_7.metric_time__quarter + , subq_7.metric_time__year + , subq_7.metric_time__extract_year + , subq_7.metric_time__extract_quarter + , subq_7.metric_time__extract_month + , subq_7.metric_time__extract_day + , subq_7.metric_time__extract_dow + , subq_7.metric_time__extract_doy + , subq_7.listing + , subq_7.guest + , subq_7.host + , subq_7.booking__listing + , subq_7.booking__guest + , subq_7.booking__host + , subq_7.is_instant + , subq_7.booking__is_instant + , subq_7.bookings + , subq_7.instant_bookings + , subq_7.booking_value + , subq_7.max_booking_value + , subq_7.min_booking_value + , subq_7.bookers + , subq_7.average_booking_value + , subq_7.referred_bookings + , subq_7.median_booking_value + , subq_7.booking_value_p99 + , subq_7.discrete_booking_value_p99 + , subq_7.approximate_continuous_booking_value_p99 + , subq_7.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + 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.ds_partitioned__day + , subq_6.ds_partitioned__week + , subq_6.ds_partitioned__month + , subq_6.ds_partitioned__quarter + , subq_6.ds_partitioned__year + , subq_6.ds_partitioned__extract_year + , subq_6.ds_partitioned__extract_quarter + , subq_6.ds_partitioned__extract_month + , subq_6.ds_partitioned__extract_day + , subq_6.ds_partitioned__extract_dow + , subq_6.ds_partitioned__extract_doy + , subq_6.paid_at__day + , subq_6.paid_at__week + , subq_6.paid_at__month + , subq_6.paid_at__quarter + , subq_6.paid_at__year + , subq_6.paid_at__extract_year + , subq_6.paid_at__extract_quarter + , subq_6.paid_at__extract_month + , subq_6.paid_at__extract_day + , subq_6.paid_at__extract_dow + , subq_6.paid_at__extract_doy + , subq_6.booking__ds__day + , subq_6.booking__ds__week + , subq_6.booking__ds__month + , subq_6.booking__ds__quarter + , subq_6.booking__ds__year + , subq_6.booking__ds__extract_year + , subq_6.booking__ds__extract_quarter + , subq_6.booking__ds__extract_month + , subq_6.booking__ds__extract_day + , subq_6.booking__ds__extract_dow + , subq_6.booking__ds__extract_doy + , subq_6.booking__ds_partitioned__day + , subq_6.booking__ds_partitioned__week + , subq_6.booking__ds_partitioned__month + , subq_6.booking__ds_partitioned__quarter + , subq_6.booking__ds_partitioned__year + , subq_6.booking__ds_partitioned__extract_year + , subq_6.booking__ds_partitioned__extract_quarter + , subq_6.booking__ds_partitioned__extract_month + , subq_6.booking__ds_partitioned__extract_day + , subq_6.booking__ds_partitioned__extract_dow + , subq_6.booking__ds_partitioned__extract_doy + , subq_6.booking__paid_at__day + , subq_6.booking__paid_at__week + , subq_6.booking__paid_at__month + , subq_6.booking__paid_at__quarter + , subq_6.booking__paid_at__year + , subq_6.booking__paid_at__extract_year + , subq_6.booking__paid_at__extract_quarter + , subq_6.booking__paid_at__extract_month + , subq_6.booking__paid_at__extract_day + , subq_6.booking__paid_at__extract_dow + , subq_6.booking__paid_at__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.listing + , subq_6.guest + , subq_6.host + , subq_6.booking__listing + , subq_6.booking__guest + , subq_6.booking__host + , subq_6.is_instant + , subq_6.booking__is_instant + , subq_6.bookings + , subq_6.instant_bookings + , subq_6.booking_value + , subq_6.max_booking_value + , subq_6.min_booking_value + , subq_6.bookers + , subq_6.average_booking_value + , subq_6.referred_bookings + , subq_6.median_booking_value + , subq_6.booking_value_p99 + , subq_6.discrete_booking_value_p99 + , subq_6.approximate_continuous_booking_value_p99 + , subq_6.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 WHERE booking__is_instant - ) subq_3 - ) subq_4 + ) subq_10 + ) subq_11 GROUP BY - subq_4.metric_time__day - ) subq_5 - ) subq_6 + subq_11.metric_time__day + ) subq_12 + ) subq_13 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day - , subq_10.booking_value + subq_17.metric_time__day + , subq_17.booking_value FROM ( -- Aggregate Measures SELECT - subq_9.metric_time__day - , SUM(subq_9.booking_value) AS booking_value + subq_16.metric_time__day + , SUM(subq_16.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'metric_time__day'] SELECT - subq_8.metric_time__day - , subq_8.booking_value + subq_15.metric_time__day + , subq_15.booking_value FROM ( -- Metric Time Dimension 'ds' SELECT - subq_7.ds__day - , subq_7.ds__week - , subq_7.ds__month - , subq_7.ds__quarter - , subq_7.ds__year - , subq_7.ds__extract_year - , subq_7.ds__extract_quarter - , subq_7.ds__extract_month - , subq_7.ds__extract_day - , subq_7.ds__extract_dow - , subq_7.ds__extract_doy - , subq_7.ds_partitioned__day - , subq_7.ds_partitioned__week - , subq_7.ds_partitioned__month - , subq_7.ds_partitioned__quarter - , subq_7.ds_partitioned__year - , subq_7.ds_partitioned__extract_year - , subq_7.ds_partitioned__extract_quarter - , subq_7.ds_partitioned__extract_month - , subq_7.ds_partitioned__extract_day - , subq_7.ds_partitioned__extract_dow - , subq_7.ds_partitioned__extract_doy - , subq_7.paid_at__day - , subq_7.paid_at__week - , subq_7.paid_at__month - , subq_7.paid_at__quarter - , subq_7.paid_at__year - , subq_7.paid_at__extract_year - , subq_7.paid_at__extract_quarter - , subq_7.paid_at__extract_month - , subq_7.paid_at__extract_day - , subq_7.paid_at__extract_dow - , subq_7.paid_at__extract_doy - , subq_7.booking__ds__day - , subq_7.booking__ds__week - , subq_7.booking__ds__month - , subq_7.booking__ds__quarter - , subq_7.booking__ds__year - , subq_7.booking__ds__extract_year - , subq_7.booking__ds__extract_quarter - , subq_7.booking__ds__extract_month - , subq_7.booking__ds__extract_day - , subq_7.booking__ds__extract_dow - , subq_7.booking__ds__extract_doy - , subq_7.booking__ds_partitioned__day - , subq_7.booking__ds_partitioned__week - , subq_7.booking__ds_partitioned__month - , subq_7.booking__ds_partitioned__quarter - , subq_7.booking__ds_partitioned__year - , subq_7.booking__ds_partitioned__extract_year - , subq_7.booking__ds_partitioned__extract_quarter - , subq_7.booking__ds_partitioned__extract_month - , subq_7.booking__ds_partitioned__extract_day - , subq_7.booking__ds_partitioned__extract_dow - , subq_7.booking__ds_partitioned__extract_doy - , subq_7.booking__paid_at__day - , subq_7.booking__paid_at__week - , subq_7.booking__paid_at__month - , subq_7.booking__paid_at__quarter - , subq_7.booking__paid_at__year - , subq_7.booking__paid_at__extract_year - , subq_7.booking__paid_at__extract_quarter - , subq_7.booking__paid_at__extract_month - , subq_7.booking__paid_at__extract_day - , subq_7.booking__paid_at__extract_dow - , subq_7.booking__paid_at__extract_doy - , subq_7.ds__day AS metric_time__day - , subq_7.ds__week AS metric_time__week - , subq_7.ds__month AS metric_time__month - , subq_7.ds__quarter AS metric_time__quarter - , subq_7.ds__year AS metric_time__year - , subq_7.ds__extract_year AS metric_time__extract_year - , subq_7.ds__extract_quarter AS metric_time__extract_quarter - , subq_7.ds__extract_month AS metric_time__extract_month - , subq_7.ds__extract_day AS metric_time__extract_day - , subq_7.ds__extract_dow AS metric_time__extract_dow - , subq_7.ds__extract_doy AS metric_time__extract_doy - , subq_7.listing - , subq_7.guest - , subq_7.host - , subq_7.booking__listing - , subq_7.booking__guest - , subq_7.booking__host - , subq_7.is_instant - , subq_7.booking__is_instant - , subq_7.bookings - , subq_7.instant_bookings - , subq_7.booking_value - , subq_7.max_booking_value - , subq_7.min_booking_value - , subq_7.bookers - , subq_7.average_booking_value - , subq_7.referred_bookings - , subq_7.median_booking_value - , subq_7.booking_value_p99 - , subq_7.discrete_booking_value_p99 - , subq_7.approximate_continuous_booking_value_p99 - , subq_7.approximate_discrete_booking_value_p99 + subq_14.ds__day + , subq_14.ds__week + , subq_14.ds__month + , subq_14.ds__quarter + , subq_14.ds__year + , subq_14.ds__extract_year + , subq_14.ds__extract_quarter + , subq_14.ds__extract_month + , subq_14.ds__extract_day + , subq_14.ds__extract_dow + , subq_14.ds__extract_doy + , subq_14.ds_partitioned__day + , subq_14.ds_partitioned__week + , subq_14.ds_partitioned__month + , subq_14.ds_partitioned__quarter + , subq_14.ds_partitioned__year + , subq_14.ds_partitioned__extract_year + , subq_14.ds_partitioned__extract_quarter + , subq_14.ds_partitioned__extract_month + , subq_14.ds_partitioned__extract_day + , subq_14.ds_partitioned__extract_dow + , subq_14.ds_partitioned__extract_doy + , subq_14.paid_at__day + , subq_14.paid_at__week + , subq_14.paid_at__month + , subq_14.paid_at__quarter + , subq_14.paid_at__year + , subq_14.paid_at__extract_year + , subq_14.paid_at__extract_quarter + , subq_14.paid_at__extract_month + , subq_14.paid_at__extract_day + , subq_14.paid_at__extract_dow + , subq_14.paid_at__extract_doy + , subq_14.booking__ds__day + , subq_14.booking__ds__week + , subq_14.booking__ds__month + , subq_14.booking__ds__quarter + , subq_14.booking__ds__year + , subq_14.booking__ds__extract_year + , subq_14.booking__ds__extract_quarter + , subq_14.booking__ds__extract_month + , subq_14.booking__ds__extract_day + , subq_14.booking__ds__extract_dow + , subq_14.booking__ds__extract_doy + , subq_14.booking__ds_partitioned__day + , subq_14.booking__ds_partitioned__week + , subq_14.booking__ds_partitioned__month + , subq_14.booking__ds_partitioned__quarter + , subq_14.booking__ds_partitioned__year + , subq_14.booking__ds_partitioned__extract_year + , subq_14.booking__ds_partitioned__extract_quarter + , subq_14.booking__ds_partitioned__extract_month + , subq_14.booking__ds_partitioned__extract_day + , subq_14.booking__ds_partitioned__extract_dow + , subq_14.booking__ds_partitioned__extract_doy + , subq_14.booking__paid_at__day + , subq_14.booking__paid_at__week + , subq_14.booking__paid_at__month + , subq_14.booking__paid_at__quarter + , subq_14.booking__paid_at__year + , subq_14.booking__paid_at__extract_year + , subq_14.booking__paid_at__extract_quarter + , subq_14.booking__paid_at__extract_month + , subq_14.booking__paid_at__extract_day + , subq_14.booking__paid_at__extract_dow + , subq_14.booking__paid_at__extract_doy + , subq_14.ds__day AS metric_time__day + , subq_14.ds__week AS metric_time__week + , subq_14.ds__month AS metric_time__month + , subq_14.ds__quarter AS metric_time__quarter + , subq_14.ds__year AS metric_time__year + , subq_14.ds__extract_year AS metric_time__extract_year + , subq_14.ds__extract_quarter AS metric_time__extract_quarter + , subq_14.ds__extract_month AS metric_time__extract_month + , subq_14.ds__extract_day AS metric_time__extract_day + , subq_14.ds__extract_dow AS metric_time__extract_dow + , subq_14.ds__extract_doy AS metric_time__extract_doy + , subq_14.listing + , subq_14.guest + , subq_14.host + , subq_14.booking__listing + , subq_14.booking__guest + , subq_14.booking__host + , subq_14.is_instant + , subq_14.booking__is_instant + , subq_14.bookings + , subq_14.instant_bookings + , subq_14.booking_value + , subq_14.max_booking_value + , subq_14.min_booking_value + , subq_14.bookers + , subq_14.average_booking_value + , subq_14.referred_bookings + , subq_14.median_booking_value + , subq_14.booking_value_p99 + , subq_14.discrete_booking_value_p99 + , subq_14.approximate_continuous_booking_value_p99 + , subq_14.approximate_discrete_booking_value_p99 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -446,15 +549,15 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_7 - ) subq_8 - ) subq_9 + ) subq_14 + ) subq_15 + ) subq_16 GROUP BY - subq_9.metric_time__day - ) subq_10 - ) subq_11 + subq_16.metric_time__day + ) subq_17 + ) subq_18 ON - subq_6.metric_time__day = subq_11.metric_time__day + subq_13.metric_time__day = subq_18.metric_time__day GROUP BY - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) -) subq_12 + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) +) subq_19 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_reused_measure__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_reused_measure__plan0_optimized.sql index a465dac6f6..f0def82955 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_reused_measure__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_reused_measure__plan0_optimized.sql @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) AS metric_time__day - , MAX(subq_19.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_24.booking_value) AS booking_value + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) AS metric_time__day + , MAX(subq_27.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_32.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'metric_time__day'] @@ -17,19 +17,27 @@ FROM ( metric_time__day , SUM(booking_value) AS booking_value_with_is_instant_constraint FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant + metric_time__day + , booking__is_instant , booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_15 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_21 + WHERE booking__is_instant + ) subq_23 WHERE booking__is_instant GROUP BY metric_time__day - ) subq_19 + ) subq_27 FULL OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -42,9 +50,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY DATE_TRUNC('day', ds) - ) subq_24 + ) subq_32 ON - subq_19.metric_time__day = subq_24.metric_time__day + subq_27.metric_time__day = subq_32.metric_time__day GROUP BY - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) -) subq_25 + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) +) subq_33 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_single_expr_and_alias__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_single_expr_and_alias__plan0.sql index 73954cba02..65a868eb42 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_single_expr_and_alias__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_single_expr_and_alias__plan0.sql @@ -1,234 +1,337 @@ -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day + subq_13.metric_time__day , delayed_bookings * 2 AS double_counted_delayed_bookings FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.bookings AS delayed_bookings + subq_12.metric_time__day + , subq_12.bookings AS delayed_bookings FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.bookings) AS bookings + subq_11.metric_time__day + , SUM(subq_11.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.bookings + subq_10.metric_time__day + , subq_10.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE 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.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.booking__paid_at__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.listing - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_7.ds__day + , subq_7.ds__week + , subq_7.ds__month + , subq_7.ds__quarter + , subq_7.ds__year + , subq_7.ds__extract_year + , subq_7.ds__extract_quarter + , subq_7.ds__extract_month + , subq_7.ds__extract_day + , subq_7.ds__extract_dow + , subq_7.ds__extract_doy + , subq_7.ds_partitioned__day + , subq_7.ds_partitioned__week + , subq_7.ds_partitioned__month + , subq_7.ds_partitioned__quarter + , subq_7.ds_partitioned__year + , subq_7.ds_partitioned__extract_year + , subq_7.ds_partitioned__extract_quarter + , subq_7.ds_partitioned__extract_month + , subq_7.ds_partitioned__extract_day + , subq_7.ds_partitioned__extract_dow + , subq_7.ds_partitioned__extract_doy + , subq_7.paid_at__day + , subq_7.paid_at__week + , subq_7.paid_at__month + , subq_7.paid_at__quarter + , subq_7.paid_at__year + , subq_7.paid_at__extract_year + , subq_7.paid_at__extract_quarter + , subq_7.paid_at__extract_month + , subq_7.paid_at__extract_day + , subq_7.paid_at__extract_dow + , subq_7.paid_at__extract_doy + , subq_7.booking__ds__day + , subq_7.booking__ds__week + , subq_7.booking__ds__month + , subq_7.booking__ds__quarter + , subq_7.booking__ds__year + , subq_7.booking__ds__extract_year + , subq_7.booking__ds__extract_quarter + , subq_7.booking__ds__extract_month + , subq_7.booking__ds__extract_day + , subq_7.booking__ds__extract_dow + , subq_7.booking__ds__extract_doy + , subq_7.booking__ds_partitioned__day + , subq_7.booking__ds_partitioned__week + , subq_7.booking__ds_partitioned__month + , subq_7.booking__ds_partitioned__quarter + , subq_7.booking__ds_partitioned__year + , subq_7.booking__ds_partitioned__extract_year + , subq_7.booking__ds_partitioned__extract_quarter + , subq_7.booking__ds_partitioned__extract_month + , subq_7.booking__ds_partitioned__extract_day + , subq_7.booking__ds_partitioned__extract_dow + , subq_7.booking__ds_partitioned__extract_doy + , subq_7.booking__paid_at__day + , subq_7.booking__paid_at__week + , subq_7.booking__paid_at__month + , subq_7.booking__paid_at__quarter + , subq_7.booking__paid_at__year + , subq_7.booking__paid_at__extract_year + , subq_7.booking__paid_at__extract_quarter + , subq_7.booking__paid_at__extract_month + , subq_7.booking__paid_at__extract_day + , subq_7.booking__paid_at__extract_dow + , subq_7.booking__paid_at__extract_doy + , subq_7.metric_time__day + , subq_7.metric_time__week + , subq_7.metric_time__month + , subq_7.metric_time__quarter + , subq_7.metric_time__year + , subq_7.metric_time__extract_year + , subq_7.metric_time__extract_quarter + , subq_7.metric_time__extract_month + , subq_7.metric_time__extract_day + , subq_7.metric_time__extract_dow + , subq_7.metric_time__extract_doy + , subq_7.listing + , subq_7.guest + , subq_7.host + , subq_7.booking__listing + , subq_7.booking__guest + , subq_7.booking__host + , subq_7.is_instant + , subq_7.booking__is_instant + , subq_7.bookings + , subq_7.instant_bookings + , subq_7.booking_value + , subq_7.max_booking_value + , subq_7.min_booking_value + , subq_7.bookers + , subq_7.average_booking_value + , subq_7.referred_bookings + , subq_7.median_booking_value + , subq_7.booking_value_p99 + , subq_7.discrete_booking_value_p99 + , subq_7.approximate_continuous_booking_value_p99 + , subq_7.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + 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.ds_partitioned__day + , subq_6.ds_partitioned__week + , subq_6.ds_partitioned__month + , subq_6.ds_partitioned__quarter + , subq_6.ds_partitioned__year + , subq_6.ds_partitioned__extract_year + , subq_6.ds_partitioned__extract_quarter + , subq_6.ds_partitioned__extract_month + , subq_6.ds_partitioned__extract_day + , subq_6.ds_partitioned__extract_dow + , subq_6.ds_partitioned__extract_doy + , subq_6.paid_at__day + , subq_6.paid_at__week + , subq_6.paid_at__month + , subq_6.paid_at__quarter + , subq_6.paid_at__year + , subq_6.paid_at__extract_year + , subq_6.paid_at__extract_quarter + , subq_6.paid_at__extract_month + , subq_6.paid_at__extract_day + , subq_6.paid_at__extract_dow + , subq_6.paid_at__extract_doy + , subq_6.booking__ds__day + , subq_6.booking__ds__week + , subq_6.booking__ds__month + , subq_6.booking__ds__quarter + , subq_6.booking__ds__year + , subq_6.booking__ds__extract_year + , subq_6.booking__ds__extract_quarter + , subq_6.booking__ds__extract_month + , subq_6.booking__ds__extract_day + , subq_6.booking__ds__extract_dow + , subq_6.booking__ds__extract_doy + , subq_6.booking__ds_partitioned__day + , subq_6.booking__ds_partitioned__week + , subq_6.booking__ds_partitioned__month + , subq_6.booking__ds_partitioned__quarter + , subq_6.booking__ds_partitioned__year + , subq_6.booking__ds_partitioned__extract_year + , subq_6.booking__ds_partitioned__extract_quarter + , subq_6.booking__ds_partitioned__extract_month + , subq_6.booking__ds_partitioned__extract_day + , subq_6.booking__ds_partitioned__extract_dow + , subq_6.booking__ds_partitioned__extract_doy + , subq_6.booking__paid_at__day + , subq_6.booking__paid_at__week + , subq_6.booking__paid_at__month + , subq_6.booking__paid_at__quarter + , subq_6.booking__paid_at__year + , subq_6.booking__paid_at__extract_year + , subq_6.booking__paid_at__extract_quarter + , subq_6.booking__paid_at__extract_month + , subq_6.booking__paid_at__extract_day + , subq_6.booking__paid_at__extract_dow + , subq_6.booking__paid_at__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.listing + , subq_6.guest + , subq_6.host + , subq_6.booking__listing + , subq_6.booking__guest + , subq_6.booking__host + , subq_6.is_instant + , subq_6.booking__is_instant + , subq_6.bookings + , subq_6.instant_bookings + , subq_6.booking_value + , subq_6.max_booking_value + , subq_6.min_booking_value + , subq_6.bookers + , subq_6.average_booking_value + , subq_6.referred_bookings + , subq_6.median_booking_value + , subq_6.booking_value_p99 + , subq_6.discrete_booking_value_p99 + , subq_6.approximate_continuous_booking_value_p99 + , subq_6.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_6 + ) subq_7 + WHERE NOT booking__is_instant + ) subq_8 + ) subq_9 WHERE NOT booking__is_instant - ) subq_3 - ) subq_4 + ) subq_10 + ) subq_11 GROUP BY - subq_4.metric_time__day - ) subq_5 -) subq_6 + subq_11.metric_time__day + ) subq_12 +) subq_13 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql index 3202b9915d..33436b83b6 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql @@ -11,16 +11,24 @@ FROM ( metric_time__day , SUM(bookings) AS delayed_bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + metric_time__day + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_15 + WHERE NOT booking__is_instant + ) subq_17 WHERE NOT booking__is_instant GROUP BY metric_time__day -) subq_13 +) subq_21 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0.sql index 955c17a477..c77e8402bb 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0.sql @@ -1,134 +1,195 @@ -- Order By ['listing__country_latest'] Limit 100 SELECT - subq_2.listing__country_latest + subq_5.listing__country_latest FROM ( -- Pass Only Elements: ['listing__country_latest',] SELECT - subq_1.listing__country_latest + subq_4.listing__country_latest FROM ( -- Constrain Output with WHERE 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.created_at__day - , subq_0.created_at__week - , subq_0.created_at__month - , subq_0.created_at__quarter - , subq_0.created_at__year - , subq_0.created_at__extract_year - , subq_0.created_at__extract_quarter - , subq_0.created_at__extract_month - , subq_0.created_at__extract_day - , subq_0.created_at__extract_dow - , subq_0.created_at__extract_doy - , subq_0.listing__ds__day - , subq_0.listing__ds__week - , subq_0.listing__ds__month - , subq_0.listing__ds__quarter - , subq_0.listing__ds__year - , subq_0.listing__ds__extract_year - , subq_0.listing__ds__extract_quarter - , subq_0.listing__ds__extract_month - , subq_0.listing__ds__extract_day - , subq_0.listing__ds__extract_dow - , subq_0.listing__ds__extract_doy - , subq_0.listing__created_at__day - , subq_0.listing__created_at__week - , subq_0.listing__created_at__month - , subq_0.listing__created_at__quarter - , subq_0.listing__created_at__year - , subq_0.listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month - , subq_0.listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow - , subq_0.listing__created_at__extract_doy - , subq_0.listing - , subq_0.user - , subq_0.listing__user - , subq_0.country_latest - , subq_0.is_lux_latest - , subq_0.capacity_latest - , subq_0.listing__country_latest - , subq_0.listing__is_lux_latest - , subq_0.listing__capacity_latest - , subq_0.listings - , subq_0.largest_listing - , subq_0.smallest_listing + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing FROM ( - -- Read Elements From Semantic Model 'listings_latest' + -- Constrain Output with WHERE SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , listings_latest_src_28000.user_id AS user - , listings_latest_src_28000.user_id AS listing__user - FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_0 + subq_2.ds__day + , subq_2.ds__week + , subq_2.ds__month + , subq_2.ds__quarter + , subq_2.ds__year + , subq_2.ds__extract_year + , subq_2.ds__extract_quarter + , subq_2.ds__extract_month + , subq_2.ds__extract_day + , subq_2.ds__extract_dow + , subq_2.ds__extract_doy + , subq_2.created_at__day + , subq_2.created_at__week + , subq_2.created_at__month + , subq_2.created_at__quarter + , subq_2.created_at__year + , subq_2.created_at__extract_year + , subq_2.created_at__extract_quarter + , subq_2.created_at__extract_month + , subq_2.created_at__extract_day + , subq_2.created_at__extract_dow + , subq_2.created_at__extract_doy + , subq_2.listing__ds__day + , subq_2.listing__ds__week + , subq_2.listing__ds__month + , subq_2.listing__ds__quarter + , subq_2.listing__ds__year + , subq_2.listing__ds__extract_year + , subq_2.listing__ds__extract_quarter + , subq_2.listing__ds__extract_month + , subq_2.listing__ds__extract_day + , subq_2.listing__ds__extract_dow + , subq_2.listing__ds__extract_doy + , subq_2.listing__created_at__day + , subq_2.listing__created_at__week + , subq_2.listing__created_at__month + , subq_2.listing__created_at__quarter + , subq_2.listing__created_at__year + , subq_2.listing__created_at__extract_year + , subq_2.listing__created_at__extract_quarter + , subq_2.listing__created_at__extract_month + , subq_2.listing__created_at__extract_day + , subq_2.listing__created_at__extract_dow + , subq_2.listing__created_at__extract_doy + , subq_2.listing + , subq_2.user + , subq_2.listing__user + , subq_2.country_latest + , subq_2.is_lux_latest + , subq_2.capacity_latest + , subq_2.listing__country_latest + , subq_2.listing__is_lux_latest + , subq_2.listing__capacity_latest + , subq_2.listings + , subq_2.largest_listing + , subq_2.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_2 + WHERE listing__country_latest = 'us' + ) subq_3 WHERE listing__country_latest = 'us' - ) subq_1 + ) subq_4 GROUP BY - subq_1.listing__country_latest -) subq_2 -ORDER BY subq_2.listing__country_latest DESC + subq_4.listing__country_latest +) subq_5 +ORDER BY subq_5.listing__country_latest DESC LIMIT 100 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0_optimized.sql index 1653ada5bd..76e6591b6c 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0_optimized.sql @@ -4,11 +4,17 @@ SELECT listing__country_latest FROM ( - -- Read Elements From Semantic Model 'listings_latest' + -- Constrain Output with WHERE SELECT - country AS listing__country_latest - FROM ***************************.dim_listings_latest listings_latest_src_28000 -) subq_3 + listing__country_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + country AS listing__country_latest + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_6 + WHERE listing__country_latest = 'us' +) subq_7 WHERE listing__country_latest = 'us' GROUP BY listing__country_latest diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0.sql index d757f7bc0b..dd97f89d8f 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0.sql @@ -1,359 +1,462 @@ -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day - , CAST(subq_12.booking_value_with_is_instant_constraint AS DOUBLE) / CAST(NULLIF(subq_12.booking_value, 0) AS DOUBLE) AS instant_booking_value_ratio + subq_19.metric_time__day + , CAST(subq_19.booking_value_with_is_instant_constraint AS DOUBLE) / CAST(NULLIF(subq_19.booking_value, 0) AS DOUBLE) AS instant_booking_value_ratio FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) AS metric_time__day - , MAX(subq_6.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_11.booking_value) AS booking_value + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) AS metric_time__day + , MAX(subq_13.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_18.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.booking_value AS booking_value_with_is_instant_constraint + subq_12.metric_time__day + , subq_12.booking_value AS booking_value_with_is_instant_constraint FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.booking_value) AS booking_value + subq_11.metric_time__day + , SUM(subq_11.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.booking_value + subq_10.metric_time__day + , subq_10.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.booking_value + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.booking_value + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE 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.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.booking__paid_at__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.listing - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_7.ds__day + , subq_7.ds__week + , subq_7.ds__month + , subq_7.ds__quarter + , subq_7.ds__year + , subq_7.ds__extract_year + , subq_7.ds__extract_quarter + , subq_7.ds__extract_month + , subq_7.ds__extract_day + , subq_7.ds__extract_dow + , subq_7.ds__extract_doy + , subq_7.ds_partitioned__day + , subq_7.ds_partitioned__week + , subq_7.ds_partitioned__month + , subq_7.ds_partitioned__quarter + , subq_7.ds_partitioned__year + , subq_7.ds_partitioned__extract_year + , subq_7.ds_partitioned__extract_quarter + , subq_7.ds_partitioned__extract_month + , subq_7.ds_partitioned__extract_day + , subq_7.ds_partitioned__extract_dow + , subq_7.ds_partitioned__extract_doy + , subq_7.paid_at__day + , subq_7.paid_at__week + , subq_7.paid_at__month + , subq_7.paid_at__quarter + , subq_7.paid_at__year + , subq_7.paid_at__extract_year + , subq_7.paid_at__extract_quarter + , subq_7.paid_at__extract_month + , subq_7.paid_at__extract_day + , subq_7.paid_at__extract_dow + , subq_7.paid_at__extract_doy + , subq_7.booking__ds__day + , subq_7.booking__ds__week + , subq_7.booking__ds__month + , subq_7.booking__ds__quarter + , subq_7.booking__ds__year + , subq_7.booking__ds__extract_year + , subq_7.booking__ds__extract_quarter + , subq_7.booking__ds__extract_month + , subq_7.booking__ds__extract_day + , subq_7.booking__ds__extract_dow + , subq_7.booking__ds__extract_doy + , subq_7.booking__ds_partitioned__day + , subq_7.booking__ds_partitioned__week + , subq_7.booking__ds_partitioned__month + , subq_7.booking__ds_partitioned__quarter + , subq_7.booking__ds_partitioned__year + , subq_7.booking__ds_partitioned__extract_year + , subq_7.booking__ds_partitioned__extract_quarter + , subq_7.booking__ds_partitioned__extract_month + , subq_7.booking__ds_partitioned__extract_day + , subq_7.booking__ds_partitioned__extract_dow + , subq_7.booking__ds_partitioned__extract_doy + , subq_7.booking__paid_at__day + , subq_7.booking__paid_at__week + , subq_7.booking__paid_at__month + , subq_7.booking__paid_at__quarter + , subq_7.booking__paid_at__year + , subq_7.booking__paid_at__extract_year + , subq_7.booking__paid_at__extract_quarter + , subq_7.booking__paid_at__extract_month + , subq_7.booking__paid_at__extract_day + , subq_7.booking__paid_at__extract_dow + , subq_7.booking__paid_at__extract_doy + , subq_7.metric_time__day + , subq_7.metric_time__week + , subq_7.metric_time__month + , subq_7.metric_time__quarter + , subq_7.metric_time__year + , subq_7.metric_time__extract_year + , subq_7.metric_time__extract_quarter + , subq_7.metric_time__extract_month + , subq_7.metric_time__extract_day + , subq_7.metric_time__extract_dow + , subq_7.metric_time__extract_doy + , subq_7.listing + , subq_7.guest + , subq_7.host + , subq_7.booking__listing + , subq_7.booking__guest + , subq_7.booking__host + , subq_7.is_instant + , subq_7.booking__is_instant + , subq_7.bookings + , subq_7.instant_bookings + , subq_7.booking_value + , subq_7.max_booking_value + , subq_7.min_booking_value + , subq_7.bookers + , subq_7.average_booking_value + , subq_7.referred_bookings + , subq_7.median_booking_value + , subq_7.booking_value_p99 + , subq_7.discrete_booking_value_p99 + , subq_7.approximate_continuous_booking_value_p99 + , subq_7.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + 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.ds_partitioned__day + , subq_6.ds_partitioned__week + , subq_6.ds_partitioned__month + , subq_6.ds_partitioned__quarter + , subq_6.ds_partitioned__year + , subq_6.ds_partitioned__extract_year + , subq_6.ds_partitioned__extract_quarter + , subq_6.ds_partitioned__extract_month + , subq_6.ds_partitioned__extract_day + , subq_6.ds_partitioned__extract_dow + , subq_6.ds_partitioned__extract_doy + , subq_6.paid_at__day + , subq_6.paid_at__week + , subq_6.paid_at__month + , subq_6.paid_at__quarter + , subq_6.paid_at__year + , subq_6.paid_at__extract_year + , subq_6.paid_at__extract_quarter + , subq_6.paid_at__extract_month + , subq_6.paid_at__extract_day + , subq_6.paid_at__extract_dow + , subq_6.paid_at__extract_doy + , subq_6.booking__ds__day + , subq_6.booking__ds__week + , subq_6.booking__ds__month + , subq_6.booking__ds__quarter + , subq_6.booking__ds__year + , subq_6.booking__ds__extract_year + , subq_6.booking__ds__extract_quarter + , subq_6.booking__ds__extract_month + , subq_6.booking__ds__extract_day + , subq_6.booking__ds__extract_dow + , subq_6.booking__ds__extract_doy + , subq_6.booking__ds_partitioned__day + , subq_6.booking__ds_partitioned__week + , subq_6.booking__ds_partitioned__month + , subq_6.booking__ds_partitioned__quarter + , subq_6.booking__ds_partitioned__year + , subq_6.booking__ds_partitioned__extract_year + , subq_6.booking__ds_partitioned__extract_quarter + , subq_6.booking__ds_partitioned__extract_month + , subq_6.booking__ds_partitioned__extract_day + , subq_6.booking__ds_partitioned__extract_dow + , subq_6.booking__ds_partitioned__extract_doy + , subq_6.booking__paid_at__day + , subq_6.booking__paid_at__week + , subq_6.booking__paid_at__month + , subq_6.booking__paid_at__quarter + , subq_6.booking__paid_at__year + , subq_6.booking__paid_at__extract_year + , subq_6.booking__paid_at__extract_quarter + , subq_6.booking__paid_at__extract_month + , subq_6.booking__paid_at__extract_day + , subq_6.booking__paid_at__extract_dow + , subq_6.booking__paid_at__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.listing + , subq_6.guest + , subq_6.host + , subq_6.booking__listing + , subq_6.booking__guest + , subq_6.booking__host + , subq_6.is_instant + , subq_6.booking__is_instant + , subq_6.bookings + , subq_6.instant_bookings + , subq_6.booking_value + , subq_6.max_booking_value + , subq_6.min_booking_value + , subq_6.bookers + , subq_6.average_booking_value + , subq_6.referred_bookings + , subq_6.median_booking_value + , subq_6.booking_value_p99 + , subq_6.discrete_booking_value_p99 + , subq_6.approximate_continuous_booking_value_p99 + , subq_6.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 WHERE booking__is_instant - ) subq_3 - ) subq_4 + ) subq_10 + ) subq_11 GROUP BY - subq_4.metric_time__day - ) subq_5 - ) subq_6 + subq_11.metric_time__day + ) subq_12 + ) subq_13 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day - , subq_10.booking_value + subq_17.metric_time__day + , subq_17.booking_value FROM ( -- Aggregate Measures SELECT - subq_9.metric_time__day - , SUM(subq_9.booking_value) AS booking_value + subq_16.metric_time__day + , SUM(subq_16.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'metric_time__day'] SELECT - subq_8.metric_time__day - , subq_8.booking_value + subq_15.metric_time__day + , subq_15.booking_value FROM ( -- Metric Time Dimension 'ds' SELECT - subq_7.ds__day - , subq_7.ds__week - , subq_7.ds__month - , subq_7.ds__quarter - , subq_7.ds__year - , subq_7.ds__extract_year - , subq_7.ds__extract_quarter - , subq_7.ds__extract_month - , subq_7.ds__extract_day - , subq_7.ds__extract_dow - , subq_7.ds__extract_doy - , subq_7.ds_partitioned__day - , subq_7.ds_partitioned__week - , subq_7.ds_partitioned__month - , subq_7.ds_partitioned__quarter - , subq_7.ds_partitioned__year - , subq_7.ds_partitioned__extract_year - , subq_7.ds_partitioned__extract_quarter - , subq_7.ds_partitioned__extract_month - , subq_7.ds_partitioned__extract_day - , subq_7.ds_partitioned__extract_dow - , subq_7.ds_partitioned__extract_doy - , subq_7.paid_at__day - , subq_7.paid_at__week - , subq_7.paid_at__month - , subq_7.paid_at__quarter - , subq_7.paid_at__year - , subq_7.paid_at__extract_year - , subq_7.paid_at__extract_quarter - , subq_7.paid_at__extract_month - , subq_7.paid_at__extract_day - , subq_7.paid_at__extract_dow - , subq_7.paid_at__extract_doy - , subq_7.booking__ds__day - , subq_7.booking__ds__week - , subq_7.booking__ds__month - , subq_7.booking__ds__quarter - , subq_7.booking__ds__year - , subq_7.booking__ds__extract_year - , subq_7.booking__ds__extract_quarter - , subq_7.booking__ds__extract_month - , subq_7.booking__ds__extract_day - , subq_7.booking__ds__extract_dow - , subq_7.booking__ds__extract_doy - , subq_7.booking__ds_partitioned__day - , subq_7.booking__ds_partitioned__week - , subq_7.booking__ds_partitioned__month - , subq_7.booking__ds_partitioned__quarter - , subq_7.booking__ds_partitioned__year - , subq_7.booking__ds_partitioned__extract_year - , subq_7.booking__ds_partitioned__extract_quarter - , subq_7.booking__ds_partitioned__extract_month - , subq_7.booking__ds_partitioned__extract_day - , subq_7.booking__ds_partitioned__extract_dow - , subq_7.booking__ds_partitioned__extract_doy - , subq_7.booking__paid_at__day - , subq_7.booking__paid_at__week - , subq_7.booking__paid_at__month - , subq_7.booking__paid_at__quarter - , subq_7.booking__paid_at__year - , subq_7.booking__paid_at__extract_year - , subq_7.booking__paid_at__extract_quarter - , subq_7.booking__paid_at__extract_month - , subq_7.booking__paid_at__extract_day - , subq_7.booking__paid_at__extract_dow - , subq_7.booking__paid_at__extract_doy - , subq_7.ds__day AS metric_time__day - , subq_7.ds__week AS metric_time__week - , subq_7.ds__month AS metric_time__month - , subq_7.ds__quarter AS metric_time__quarter - , subq_7.ds__year AS metric_time__year - , subq_7.ds__extract_year AS metric_time__extract_year - , subq_7.ds__extract_quarter AS metric_time__extract_quarter - , subq_7.ds__extract_month AS metric_time__extract_month - , subq_7.ds__extract_day AS metric_time__extract_day - , subq_7.ds__extract_dow AS metric_time__extract_dow - , subq_7.ds__extract_doy AS metric_time__extract_doy - , subq_7.listing - , subq_7.guest - , subq_7.host - , subq_7.booking__listing - , subq_7.booking__guest - , subq_7.booking__host - , subq_7.is_instant - , subq_7.booking__is_instant - , subq_7.bookings - , subq_7.instant_bookings - , subq_7.booking_value - , subq_7.max_booking_value - , subq_7.min_booking_value - , subq_7.bookers - , subq_7.average_booking_value - , subq_7.referred_bookings - , subq_7.median_booking_value - , subq_7.booking_value_p99 - , subq_7.discrete_booking_value_p99 - , subq_7.approximate_continuous_booking_value_p99 - , subq_7.approximate_discrete_booking_value_p99 + subq_14.ds__day + , subq_14.ds__week + , subq_14.ds__month + , subq_14.ds__quarter + , subq_14.ds__year + , subq_14.ds__extract_year + , subq_14.ds__extract_quarter + , subq_14.ds__extract_month + , subq_14.ds__extract_day + , subq_14.ds__extract_dow + , subq_14.ds__extract_doy + , subq_14.ds_partitioned__day + , subq_14.ds_partitioned__week + , subq_14.ds_partitioned__month + , subq_14.ds_partitioned__quarter + , subq_14.ds_partitioned__year + , subq_14.ds_partitioned__extract_year + , subq_14.ds_partitioned__extract_quarter + , subq_14.ds_partitioned__extract_month + , subq_14.ds_partitioned__extract_day + , subq_14.ds_partitioned__extract_dow + , subq_14.ds_partitioned__extract_doy + , subq_14.paid_at__day + , subq_14.paid_at__week + , subq_14.paid_at__month + , subq_14.paid_at__quarter + , subq_14.paid_at__year + , subq_14.paid_at__extract_year + , subq_14.paid_at__extract_quarter + , subq_14.paid_at__extract_month + , subq_14.paid_at__extract_day + , subq_14.paid_at__extract_dow + , subq_14.paid_at__extract_doy + , subq_14.booking__ds__day + , subq_14.booking__ds__week + , subq_14.booking__ds__month + , subq_14.booking__ds__quarter + , subq_14.booking__ds__year + , subq_14.booking__ds__extract_year + , subq_14.booking__ds__extract_quarter + , subq_14.booking__ds__extract_month + , subq_14.booking__ds__extract_day + , subq_14.booking__ds__extract_dow + , subq_14.booking__ds__extract_doy + , subq_14.booking__ds_partitioned__day + , subq_14.booking__ds_partitioned__week + , subq_14.booking__ds_partitioned__month + , subq_14.booking__ds_partitioned__quarter + , subq_14.booking__ds_partitioned__year + , subq_14.booking__ds_partitioned__extract_year + , subq_14.booking__ds_partitioned__extract_quarter + , subq_14.booking__ds_partitioned__extract_month + , subq_14.booking__ds_partitioned__extract_day + , subq_14.booking__ds_partitioned__extract_dow + , subq_14.booking__ds_partitioned__extract_doy + , subq_14.booking__paid_at__day + , subq_14.booking__paid_at__week + , subq_14.booking__paid_at__month + , subq_14.booking__paid_at__quarter + , subq_14.booking__paid_at__year + , subq_14.booking__paid_at__extract_year + , subq_14.booking__paid_at__extract_quarter + , subq_14.booking__paid_at__extract_month + , subq_14.booking__paid_at__extract_day + , subq_14.booking__paid_at__extract_dow + , subq_14.booking__paid_at__extract_doy + , subq_14.ds__day AS metric_time__day + , subq_14.ds__week AS metric_time__week + , subq_14.ds__month AS metric_time__month + , subq_14.ds__quarter AS metric_time__quarter + , subq_14.ds__year AS metric_time__year + , subq_14.ds__extract_year AS metric_time__extract_year + , subq_14.ds__extract_quarter AS metric_time__extract_quarter + , subq_14.ds__extract_month AS metric_time__extract_month + , subq_14.ds__extract_day AS metric_time__extract_day + , subq_14.ds__extract_dow AS metric_time__extract_dow + , subq_14.ds__extract_doy AS metric_time__extract_doy + , subq_14.listing + , subq_14.guest + , subq_14.host + , subq_14.booking__listing + , subq_14.booking__guest + , subq_14.booking__host + , subq_14.is_instant + , subq_14.booking__is_instant + , subq_14.bookings + , subq_14.instant_bookings + , subq_14.booking_value + , subq_14.max_booking_value + , subq_14.min_booking_value + , subq_14.bookers + , subq_14.average_booking_value + , subq_14.referred_bookings + , subq_14.median_booking_value + , subq_14.booking_value_p99 + , subq_14.discrete_booking_value_p99 + , subq_14.approximate_continuous_booking_value_p99 + , subq_14.approximate_discrete_booking_value_p99 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -446,15 +549,15 @@ FROM ( , bookings_source_src_28000.guest_id AS booking__guest , bookings_source_src_28000.host_id AS booking__host FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_7 - ) subq_8 - ) subq_9 + ) subq_14 + ) subq_15 + ) subq_16 GROUP BY - subq_9.metric_time__day - ) subq_10 - ) subq_11 + subq_16.metric_time__day + ) subq_17 + ) subq_18 ON - subq_6.metric_time__day = subq_11.metric_time__day + subq_13.metric_time__day = subq_18.metric_time__day GROUP BY - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) -) subq_12 + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) +) subq_19 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0_optimized.sql index a465dac6f6..f0def82955 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0_optimized.sql @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) AS metric_time__day - , MAX(subq_19.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_24.booking_value) AS booking_value + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) AS metric_time__day + , MAX(subq_27.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_32.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'metric_time__day'] @@ -17,19 +17,27 @@ FROM ( metric_time__day , SUM(booking_value) AS booking_value_with_is_instant_constraint FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant + metric_time__day + , booking__is_instant , booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_15 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_21 + WHERE booking__is_instant + ) subq_23 WHERE booking__is_instant GROUP BY metric_time__day - ) subq_19 + ) subq_27 FULL OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -42,9 +50,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY DATE_TRUNC('day', ds) - ) subq_24 + ) subq_32 ON - subq_19.metric_time__day = subq_24.metric_time__day + subq_27.metric_time__day = subq_32.metric_time__day GROUP BY - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) -) subq_25 + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) +) subq_33 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0.sql index fa133adf99..9b8d9efeee 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0.sql @@ -1,234 +1,337 @@ -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day + subq_13.metric_time__day , delayed_bookings * 2 AS double_counted_delayed_bookings FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.bookings AS delayed_bookings + subq_12.metric_time__day + , subq_12.bookings AS delayed_bookings FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.bookings) AS bookings + subq_11.metric_time__day + , SUM(subq_11.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.bookings + subq_10.metric_time__day + , subq_10.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE 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.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.booking__paid_at__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.listing - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_7.ds__day + , subq_7.ds__week + , subq_7.ds__month + , subq_7.ds__quarter + , subq_7.ds__year + , subq_7.ds__extract_year + , subq_7.ds__extract_quarter + , subq_7.ds__extract_month + , subq_7.ds__extract_day + , subq_7.ds__extract_dow + , subq_7.ds__extract_doy + , subq_7.ds_partitioned__day + , subq_7.ds_partitioned__week + , subq_7.ds_partitioned__month + , subq_7.ds_partitioned__quarter + , subq_7.ds_partitioned__year + , subq_7.ds_partitioned__extract_year + , subq_7.ds_partitioned__extract_quarter + , subq_7.ds_partitioned__extract_month + , subq_7.ds_partitioned__extract_day + , subq_7.ds_partitioned__extract_dow + , subq_7.ds_partitioned__extract_doy + , subq_7.paid_at__day + , subq_7.paid_at__week + , subq_7.paid_at__month + , subq_7.paid_at__quarter + , subq_7.paid_at__year + , subq_7.paid_at__extract_year + , subq_7.paid_at__extract_quarter + , subq_7.paid_at__extract_month + , subq_7.paid_at__extract_day + , subq_7.paid_at__extract_dow + , subq_7.paid_at__extract_doy + , subq_7.booking__ds__day + , subq_7.booking__ds__week + , subq_7.booking__ds__month + , subq_7.booking__ds__quarter + , subq_7.booking__ds__year + , subq_7.booking__ds__extract_year + , subq_7.booking__ds__extract_quarter + , subq_7.booking__ds__extract_month + , subq_7.booking__ds__extract_day + , subq_7.booking__ds__extract_dow + , subq_7.booking__ds__extract_doy + , subq_7.booking__ds_partitioned__day + , subq_7.booking__ds_partitioned__week + , subq_7.booking__ds_partitioned__month + , subq_7.booking__ds_partitioned__quarter + , subq_7.booking__ds_partitioned__year + , subq_7.booking__ds_partitioned__extract_year + , subq_7.booking__ds_partitioned__extract_quarter + , subq_7.booking__ds_partitioned__extract_month + , subq_7.booking__ds_partitioned__extract_day + , subq_7.booking__ds_partitioned__extract_dow + , subq_7.booking__ds_partitioned__extract_doy + , subq_7.booking__paid_at__day + , subq_7.booking__paid_at__week + , subq_7.booking__paid_at__month + , subq_7.booking__paid_at__quarter + , subq_7.booking__paid_at__year + , subq_7.booking__paid_at__extract_year + , subq_7.booking__paid_at__extract_quarter + , subq_7.booking__paid_at__extract_month + , subq_7.booking__paid_at__extract_day + , subq_7.booking__paid_at__extract_dow + , subq_7.booking__paid_at__extract_doy + , subq_7.metric_time__day + , subq_7.metric_time__week + , subq_7.metric_time__month + , subq_7.metric_time__quarter + , subq_7.metric_time__year + , subq_7.metric_time__extract_year + , subq_7.metric_time__extract_quarter + , subq_7.metric_time__extract_month + , subq_7.metric_time__extract_day + , subq_7.metric_time__extract_dow + , subq_7.metric_time__extract_doy + , subq_7.listing + , subq_7.guest + , subq_7.host + , subq_7.booking__listing + , subq_7.booking__guest + , subq_7.booking__host + , subq_7.is_instant + , subq_7.booking__is_instant + , subq_7.bookings + , subq_7.instant_bookings + , subq_7.booking_value + , subq_7.max_booking_value + , subq_7.min_booking_value + , subq_7.bookers + , subq_7.average_booking_value + , subq_7.referred_bookings + , subq_7.median_booking_value + , subq_7.booking_value_p99 + , subq_7.discrete_booking_value_p99 + , subq_7.approximate_continuous_booking_value_p99 + , subq_7.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value - , bookings_source_src_28000.booking_value AS max_booking_value - , bookings_source_src_28000.booking_value AS min_booking_value - , bookings_source_src_28000.guest_id AS bookers - , bookings_source_src_28000.booking_value AS average_booking_value - , bookings_source_src_28000.booking_value AS booking_payments - , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings - , bookings_source_src_28000.booking_value AS median_booking_value - , bookings_source_src_28000.booking_value AS booking_value_p99 - , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 - , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 - , bookings_source_src_28000.is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy - , bookings_source_src_28000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day - , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_28000.listing_id AS listing - , bookings_source_src_28000.guest_id AS guest - , bookings_source_src_28000.host_id AS host - , bookings_source_src_28000.listing_id AS booking__listing - , bookings_source_src_28000.guest_id AS booking__guest - , bookings_source_src_28000.host_id AS booking__host - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + 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.ds_partitioned__day + , subq_6.ds_partitioned__week + , subq_6.ds_partitioned__month + , subq_6.ds_partitioned__quarter + , subq_6.ds_partitioned__year + , subq_6.ds_partitioned__extract_year + , subq_6.ds_partitioned__extract_quarter + , subq_6.ds_partitioned__extract_month + , subq_6.ds_partitioned__extract_day + , subq_6.ds_partitioned__extract_dow + , subq_6.ds_partitioned__extract_doy + , subq_6.paid_at__day + , subq_6.paid_at__week + , subq_6.paid_at__month + , subq_6.paid_at__quarter + , subq_6.paid_at__year + , subq_6.paid_at__extract_year + , subq_6.paid_at__extract_quarter + , subq_6.paid_at__extract_month + , subq_6.paid_at__extract_day + , subq_6.paid_at__extract_dow + , subq_6.paid_at__extract_doy + , subq_6.booking__ds__day + , subq_6.booking__ds__week + , subq_6.booking__ds__month + , subq_6.booking__ds__quarter + , subq_6.booking__ds__year + , subq_6.booking__ds__extract_year + , subq_6.booking__ds__extract_quarter + , subq_6.booking__ds__extract_month + , subq_6.booking__ds__extract_day + , subq_6.booking__ds__extract_dow + , subq_6.booking__ds__extract_doy + , subq_6.booking__ds_partitioned__day + , subq_6.booking__ds_partitioned__week + , subq_6.booking__ds_partitioned__month + , subq_6.booking__ds_partitioned__quarter + , subq_6.booking__ds_partitioned__year + , subq_6.booking__ds_partitioned__extract_year + , subq_6.booking__ds_partitioned__extract_quarter + , subq_6.booking__ds_partitioned__extract_month + , subq_6.booking__ds_partitioned__extract_day + , subq_6.booking__ds_partitioned__extract_dow + , subq_6.booking__ds_partitioned__extract_doy + , subq_6.booking__paid_at__day + , subq_6.booking__paid_at__week + , subq_6.booking__paid_at__month + , subq_6.booking__paid_at__quarter + , subq_6.booking__paid_at__year + , subq_6.booking__paid_at__extract_year + , subq_6.booking__paid_at__extract_quarter + , subq_6.booking__paid_at__extract_month + , subq_6.booking__paid_at__extract_day + , subq_6.booking__paid_at__extract_dow + , subq_6.booking__paid_at__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.listing + , subq_6.guest + , subq_6.host + , subq_6.booking__listing + , subq_6.booking__guest + , subq_6.booking__host + , subq_6.is_instant + , subq_6.booking__is_instant + , subq_6.bookings + , subq_6.instant_bookings + , subq_6.booking_value + , subq_6.max_booking_value + , subq_6.min_booking_value + , subq_6.bookers + , subq_6.average_booking_value + , subq_6.referred_bookings + , subq_6.median_booking_value + , subq_6.booking_value_p99 + , subq_6.discrete_booking_value_p99 + , subq_6.approximate_continuous_booking_value_p99 + , subq_6.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_6 + ) subq_7 + WHERE NOT booking__is_instant + ) subq_8 + ) subq_9 WHERE NOT booking__is_instant - ) subq_3 - ) subq_4 + ) subq_10 + ) subq_11 GROUP BY - subq_4.metric_time__day - ) subq_5 -) subq_6 + subq_11.metric_time__day + ) subq_12 +) subq_13 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql index 3202b9915d..33436b83b6 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql @@ -11,16 +11,24 @@ FROM ( metric_time__day , SUM(bookings) AS delayed_bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + metric_time__day + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_15 + WHERE NOT booking__is_instant + ) subq_17 WHERE NOT booking__is_instant GROUP BY metric_time__day -) subq_13 +) subq_21