From 088e4d3a4e06740e13890a1f7ff6c93537d0cbf4 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Fri, 8 Nov 2024 14:47:58 -0800 Subject: [PATCH 1/2] WIP - SCD bug fix --- metricflow/dataset/convert_semantic_model.py | 1 + 1 file changed, 1 insertion(+) diff --git a/metricflow/dataset/convert_semantic_model.py b/metricflow/dataset/convert_semantic_model.py index 8410b2bfd..29871ffe8 100644 --- a/metricflow/dataset/convert_semantic_model.py +++ b/metricflow/dataset/convert_semantic_model.py @@ -293,6 +293,7 @@ def _convert_time_dimension( ) time_dimension_instances.append(time_dimension_instance) + # TODO: figure out how to repro this bug https://dbt-labs.slack.com/archives/C06UEFM66P5/p1730317825261629 # Until we support minimal granularities, we cannot truncate for # any time dimension used as part of a validity window, since a validity window might # be stored in seconds while we would truncate to daily. From a8d69c21a659e4727e055293963129c3a1b00bb7 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Tue, 12 Nov 2024 14:18:47 -0800 Subject: [PATCH 2/2] WIP --- .../metricflow_semantics/specs/x.sql | 32 +++++++ .../scd_manifest/scd_bookings.yaml | 2 +- .../scd_manifest/scd_listings.yaml | 4 +- .../simple_model/dim_listings.yaml | 18 ++-- .../simple_model/fct_bookings.yaml | 92 +++++++++---------- .../query_rendering/test_query_rendering.py | 7 +- .../test_join_to_scd_dimension__plan0.sql | 92 +++++++++++++------ ...join_to_scd_dimension__plan0_optimized.sql | 16 ++-- ...multi_hop_through_scd_dimension__plan0.sql | 48 +++++++--- ...through_scd_dimension__plan0_optimized.sql | 12 +-- 10 files changed, 210 insertions(+), 113 deletions(-) create mode 100644 metricflow-semantics/metricflow_semantics/specs/x.sql diff --git a/metricflow-semantics/metricflow_semantics/specs/x.sql b/metricflow-semantics/metricflow_semantics/specs/x.sql new file mode 100644 index 000000000..65d5e5051 --- /dev/null +++ b/metricflow-semantics/metricflow_semantics/specs/x.sql @@ -0,0 +1,32 @@ +SELECT + COUNT(DISTINCT bnr_user_count) AS bnr_user_count + , COUNT(DISTINCT bnr_external_transaction_count) AS bnr_transaction_count + , SUM(complimentary_item_cost) AS complimentary_item_cost +FROM ( + SELECT + DATETIME_TRUNC(sem_bnr_transactions_src_10000.transaction_time_est, day) AS metric_time__day + , sem_user_unit_historical_src_10000.property_id AS user_id__property_id + , sem_bnr_transactions_src_10000.category AS bnr_transaction_id__category + , sem_bnr_transactions_src_10000.transaction_id AS bnr_external_transaction_count + , sem_bnr_transactions_src_10000.user_id AS bnr_user_count + , sem_bnr_transactions_src_10000.complimentary_item_cost AS complimentary_item_cost + FROM `bilt-prod`.`analytics`.`stg_all_bnr_transactions` sem_bnr_transactions_src_10000 + LEFT OUTER JOIN + `bilt-prod`.`analytics`.`stg_user_units_historical` sem_user_unit_historical_src_10000 + ON + ( + sem_bnr_transactions_src_10000.user_id = sem_user_unit_historical_src_10000.user_id + ) AND ( + ( + DATETIME_TRUNC(sem_bnr_transactions_src_10000.transaction_time_est, day) >= sem_user_unit_historical_src_10000.user_unit_create_time_est + ) AND ( + ( + DATETIME_TRUNC(sem_bnr_transactions_src_10000.transaction_time_est, day) < sem_user_unit_historical_src_10000.user_unit_delete_time_est + ) OR ( + sem_user_unit_historical_src_10000.user_unit_delete_time_est IS NULL + ) + ) + ) +) subq_6 +WHERE (bnr_transaction_id__category = 'Fitness' ) AND (user_id__property_id = 378182 and metric_time__day>= '2024-01-01') +LIMIT 100 \ No newline at end of file diff --git a/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/scd_manifest/scd_bookings.yaml b/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/scd_manifest/scd_bookings.yaml index 2d92e3820..2da60d29a 100644 --- a/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/scd_manifest/scd_bookings.yaml +++ b/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/scd_manifest/scd_bookings.yaml @@ -36,7 +36,7 @@ semantic_model: - name: ds type: time type_params: - time_granularity: day + time_granularity: second - name: ds_partitioned type: time is_partition: true diff --git a/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/scd_manifest/scd_listings.yaml b/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/scd_manifest/scd_listings.yaml index 921250af6..7e22b1ceb 100644 --- a/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/scd_manifest/scd_listings.yaml +++ b/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/scd_manifest/scd_listings.yaml @@ -12,14 +12,14 @@ semantic_model: type: time expr: active_from type_params: - time_granularity: day + time_granularity: second validity_params: is_start: True - name: window_end type: time expr: active_to type_params: - time_granularity: day + time_granularity: second validity_params: is_end: True - name: country diff --git a/tests_metricflow/fixtures/source_table_snapshots/simple_model/dim_listings.yaml b/tests_metricflow/fixtures/source_table_snapshots/simple_model/dim_listings.yaml index 6c58266e7..146491764 100644 --- a/tests_metricflow/fixtures/source_table_snapshots/simple_model/dim_listings.yaml +++ b/tests_metricflow/fixtures/source_table_snapshots/simple_model/dim_listings.yaml @@ -17,13 +17,13 @@ table_snapshot: - name: user_id type: STRING rows: - - ["2020-01-01", "2020-01-02", "l3141592", "us", "2", "True", "u0004114"] - - ["2020-01-01", "2020-01-02", "l2718281", "cote d'ivoire", "4", "True", "u0005432"] - - ["2020-01-01", "2020-01-02", "l9658588-incomplete", null, null, null, "u1004114"] - - ["2020-01-02", null, "l3141592", "us", "3", "True", "u0004114"] + - ["2020-01-01 00:00:11", "2020-01-02 00:00:11", "l3141592", "us", "2", "True", "u0004114"] + - ["2020-01-01 00:00:11", "2020-01-02 00:00:11", "l2718281", "cote d'ivoire", "4", "True", "u0005432"] + - ["2020-01-01 00:00:11", "2020-01-02 00:00:11", "l9658588-incomplete", null, null, null, "u1004114"] + - ["2020-01-02 00:00:11", null, "l3141592", "us", "3", "True", "u0004114"] # This cote_divoire property changed hands to a person from Maryland who considers it not lux - - ["2020-01-02", null, "l2718281", "cote d'ivoire", "4", "False", "u0003154"] - - ["2020-01-02", null, "l5948301", "us", "5", "True", "u0004114"] - - ["2020-01-02", null, "l9658588-incomplete", "us", null, null, "u1004114"] - - ["2020-01-02", null, "l8912456-incomplete", null, null, null, "u1004114"] - - ["2020-01-02", null, "l7891283-incomplete", "ca", null, "False", "u1004114"] + - ["2020-01-02 00:00:11", null, "l2718281", "cote d'ivoire", "4", "False", "u0003154"] + - ["2020-01-02 00:00:11", null, "l5948301", "us", "5", "True", "u0004114"] + - ["2020-01-02 00:00:11", null, "l9658588-incomplete", "us", null, null, "u1004114"] + - ["2020-01-02 00:00:11", null, "l8912456-incomplete", null, null, null, "u1004114"] + - ["2020-01-02 00:00:11", null, "l7891283-incomplete", "ca", null, "False", "u1004114"] diff --git a/tests_metricflow/fixtures/source_table_snapshots/simple_model/fct_bookings.yaml b/tests_metricflow/fixtures/source_table_snapshots/simple_model/fct_bookings.yaml index 1703754c7..5394b44ce 100644 --- a/tests_metricflow/fixtures/source_table_snapshots/simple_model/fct_bookings.yaml +++ b/tests_metricflow/fixtures/source_table_snapshots/simple_model/fct_bookings.yaml @@ -20,49 +20,49 @@ table_snapshot: - name: referrer_id type: STRING rows: - - ["2019-12-01", "2019-12-01", "2019-12-01", "u0003452", "u0004114", "l5948301", "951.23", "False", "u0003141"] - - ["2019-12-18", "2019-12-18", "2019-12-19", "u0004114", "u0003141", "l3141592", "797.42", "False", null] - - ["2019-12-18", "2019-12-18", "2019-12-19", "u0004114", "u0003141", "l3141592", "808.14", "True", "u0003141"] - - ["2019-12-18", "2019-12-18", "2019-12-19", "u0003141", "u0003154", "l2718281", "531.99", "True", null] - - ["2019-12-18", "2019-12-18", "2019-12-19", "u0003154", "u0003141", "l2718281", "285.89", "False", null] - - ["2019-12-18", "2019-12-18", "2019-12-19", "u0004114", "u0003141", "l3141592", "714.85", "True", "u0005432"] - - ["2019-12-18", "2019-12-18", "2019-12-19", "u0004114", "u0003141", "l3141592", "352.42", "False", null] - - ["2019-12-18", "2019-12-18", "2019-12-19", "u0004114", "u0003141", "l3141592", "444.14", "True", "u0003141"] - - ["2019-12-18", "2019-12-18", "2019-12-19", "u0003141", "u0003154", "l2718281", "415.99", "True", null] - - ["2019-12-18", "2019-12-18", "2019-12-19", "u0003154", "u0003141", "l2718281", "578.89", "False", null] - - ["2019-12-18", "2019-12-18", "2019-12-19", "u0004114", "u0003141", "l3141592", "768.85", "True", "u0005432"] - - ["2019-12-19", "2019-12-19", "2019-12-20", "u0004114", "u0003141", "l2718281", "368.42", "True", null] - - ["2019-12-19", "2019-12-19", "2019-12-20", "u0004114", "u0003141", "l2718281", "521.14", "True", null] - - ["2019-12-19", "2019-12-19", "2019-12-20", "u0004114", "u0003141", "l3141592", "581.99", "False", null] - - ["2019-12-19", "2019-12-19", "2019-12-20", "u0005432", "u0003452", "l2718281", "753.85", "True", "u0003452"] - - ["2019-12-19", "2019-12-19", "2019-12-20", "u0004114", "u1004114", "l9658588-incomplete", "0.0", "False", null] - - ["2019-12-19", "2019-12-19", "2019-12-20", "u0004114", "u1004114", "l8912456-incomplete", "0.0", "False", null] - - ["2019-12-19", "2019-12-19", "2019-12-20", "u0003452", "u0005432", "l3141592", "754.89", "False", "u0003141"] - - ["2019-12-19", "2019-12-19", "2019-12-20", "u0003452", "u0004114", "l5948301", "152.23", "False", "u0003141"] - - ["2019-12-19", "2019-12-19", "2019-12-20", "u1003452", "u1004114", "no_such_listing", "0.0", "False", null] - - ["2019-12-19", "2019-12-19", "2019-12-20", "u0004114", "u0003141", "l2718281", "532.42", "True", null] - - ["2019-12-19", "2019-12-19", "2019-12-20", "u0004114", "u0003141", "l2718281", "258.14", "True", null] - - ["2019-12-19", "2019-12-19", "2019-12-20", "u0004114", "u0003141", "l3141592", "753.99", "False", null] - - ["2019-12-19", "2019-12-19", "2019-12-20", "u0005432", "u0003452", "l2718281", "852.85", "True", "u0003452"] - - ["2019-12-19", "2019-12-19", "2019-12-20", "u0004114", "u1004114", "l9658588-incomplete", "0.0", "False", null] - - ["2019-12-19", "2019-12-19", "2019-12-20", "u0004114", "u1004114", "l8912456-incomplete", "0.0", "False", null] - - ["2019-12-19", "2019-12-19", "2019-12-20", "u0003452", "u0005432", "l3141592", "728.89", "False", "u0003141"] - - ["2019-12-19", "2019-12-19", "2019-12-20", "u0003452", "u0004114", "l5948301", "951.23", "False", "u0003141"] - - ["2019-12-19", "2019-12-19", "2019-12-20", "u1003452", "u1004114", "no_such_listing", "0.0", "False", null] - - ["2019-12-20", "2019-12-20", "2019-12-21", "u0003452", "u0004114", "l5948301", "0.0", "False", null] - - ["2019-12-20", "2019-12-20", "2019-12-21", "u0003452", "u0004114", "l5948301", "0.0", "False", null] - - ["2020-01-01", "2020-01-01", "2020-01-02", "u0004114", "u0003141", "l3141592", "742.42", "False", null] - - ["2020-01-01", "2020-01-01", "2020-01-02", "u0004114", "u0003141", "l3141592", "441.14", "True", "u0003141"] - - ["2020-01-01", "2020-01-01", "2020-01-02", "u0003141", "u0003154", "l2718281", "499.99", "True", null] - - ["2020-01-01", "2020-01-01", "2020-01-02", "u0003154", "u0003141", "l2718281", "719.89", "False", null] - - ["2020-01-01", "2020-01-01", "2020-01-02", "u0004114", "u0003141", "l3141592", "319.85", "True", "u0005432"] - - ["2020-01-02", "2020-01-02", "2020-01-03", "u0004114", "u0003141", "l2718281", "442.42", "True", null] - - ["2020-01-02", "2020-01-02", "2020-01-03", "u0004114", "u0003141", "l2718281", "241.14", "True", null] - - ["2020-01-02", "2020-01-02", "2020-01-03", "u0004114", "u0003141", "l3141592", "799.99", "False", null] - - ["2020-01-02", "2020-01-02", "2020-01-03", "u0005432", "u0003452", "l2718281", "319.85", "True", "u0003452"] - - ["2020-01-02", "2020-01-02", "2020-01-03", "u0004114", "u1004114", "l9658588-incomplete", "0.0", "False", null] - - ["2020-01-02", "2020-01-02", "2020-01-03", "u0004114", "u1004114", "l8912456-incomplete", "0.0", "False", null] - - ["2020-01-02", "2020-01-02", "2020-01-03", "u0003452", "u0005432", "l3141592", "519.89", "False", "u0003141"] - - ["2020-01-02", "2020-01-02", "2020-01-03", "u0003452", "u0004114", "l5948301", "332.23", "False", "u0003141"] - - ["2020-01-02", "2020-01-02", "2020-01-03", "u1003452", "u1004114", "no_such_listing", "0.0", "False", null] - - ["2020-01-03", "2020-01-03", "2020-01-04", "u0003452", "u0004114", "l5948301", "0.0", "False", null] + - ["2019-12-01 00:00:00", "2019-12-01", "2019-12-01", "u0003452", "u0004114", "l5948301", "951.23", "False", "u0003141"] + - ["2019-12-18 00:00:00", "2019-12-18", "2019-12-19", "u0004114", "u0003141", "l3141592", "797.42", "False", null] + - ["2019-12-18 00:00:00", "2019-12-18", "2019-12-19", "u0004114", "u0003141", "l3141592", "808.14", "True", "u0003141"] + - ["2019-12-18 00:00:00", "2019-12-18", "2019-12-19", "u0003141", "u0003154", "l2718281", "531.99", "True", null] + - ["2019-12-18 00:00:00", "2019-12-18", "2019-12-19", "u0003154", "u0003141", "l2718281", "285.89", "False", null] + - ["2019-12-18 00:00:00", "2019-12-18", "2019-12-19", "u0004114", "u0003141", "l3141592", "714.85", "True", "u0005432"] + - ["2019-12-18 00:00:00", "2019-12-18", "2019-12-19", "u0004114", "u0003141", "l3141592", "352.42", "False", null] + - ["2019-12-18 00:00:00", "2019-12-18", "2019-12-19", "u0004114", "u0003141", "l3141592", "444.14", "True", "u0003141"] + - ["2019-12-18 00:00:00", "2019-12-18", "2019-12-19", "u0003141", "u0003154", "l2718281", "415.99", "True", null] + - ["2019-12-18 00:00:00", "2019-12-18", "2019-12-19", "u0003154", "u0003141", "l2718281", "578.89", "False", null] + - ["2019-12-18 00:00:00", "2019-12-18", "2019-12-19", "u0004114", "u0003141", "l3141592", "768.85", "True", "u0005432"] + - ["2019-12-19 00:00:00", "2019-12-19", "2019-12-20", "u0004114", "u0003141", "l2718281", "368.42", "True", null] + - ["2019-12-19 00:00:00", "2019-12-19", "2019-12-20", "u0004114", "u0003141", "l2718281", "521.14", "True", null] + - ["2019-12-19 00:00:00", "2019-12-19", "2019-12-20", "u0004114", "u0003141", "l3141592", "581.99", "False", null] + - ["2019-12-19 00:00:00", "2019-12-19", "2019-12-20", "u0005432", "u0003452", "l2718281", "753.85", "True", "u0003452"] + - ["2019-12-19 00:00:00", "2019-12-19", "2019-12-20", "u0004114", "u1004114", "l9658588-incomplete", "0.0", "False", null] + - ["2019-12-19 00:00:00", "2019-12-19", "2019-12-20", "u0004114", "u1004114", "l8912456-incomplete", "0.0", "False", null] + - ["2019-12-19 00:00:00", "2019-12-19", "2019-12-20", "u0003452", "u0005432", "l3141592", "754.89", "False", "u0003141"] + - ["2019-12-19 00:00:00", "2019-12-19", "2019-12-20", "u0003452", "u0004114", "l5948301", "152.23", "False", "u0003141"] + - ["2019-12-19 00:00:00", "2019-12-19", "2019-12-20", "u1003452", "u1004114", "no_such_listing", "0.0", "False", null] + - ["2019-12-19 00:00:00", "2019-12-19", "2019-12-20", "u0004114", "u0003141", "l2718281", "532.42", "True", null] + - ["2019-12-19 00:00:00", "2019-12-19", "2019-12-20", "u0004114", "u0003141", "l2718281", "258.14", "True", null] + - ["2019-12-19 00:00:00", "2019-12-19", "2019-12-20", "u0004114", "u0003141", "l3141592", "753.99", "False", null] + - ["2019-12-19 00:00:00", "2019-12-19", "2019-12-20", "u0005432", "u0003452", "l2718281", "852.85", "True", "u0003452"] + - ["2019-12-19 00:00:00", "2019-12-19", "2019-12-20", "u0004114", "u1004114", "l9658588-incomplete", "0.0", "False", null] + - ["2019-12-19 00:00:00", "2019-12-19", "2019-12-20", "u0004114", "u1004114", "l8912456-incomplete", "0.0", "False", null] + - ["2019-12-19 00:00:00", "2019-12-19", "2019-12-20", "u0003452", "u0005432", "l3141592", "728.89", "False", "u0003141"] + - ["2019-12-19 00:00:00", "2019-12-19", "2019-12-20", "u0003452", "u0004114", "l5948301", "951.23", "False", "u0003141"] + - ["2019-12-19 00:00:00", "2019-12-19", "2019-12-20", "u1003452", "u1004114", "no_such_listing", "0.0", "False", null] + - ["2019-12-20 00:00:00", "2019-12-20", "2019-12-21", "u0003452", "u0004114", "l5948301", "0.0", "False", null] + - ["2019-12-20 00:00:00", "2019-12-20", "2019-12-21", "u0003452", "u0004114", "l5948301", "0.0", "False", null] + - ["2020-01-01 00:00:00", "2020-01-01", "2020-01-02", "u0004114", "u0003141", "l3141592", "742.42", "False", null] + - ["2020-01-01 00:00:00", "2020-01-01", "2020-01-02", "u0004114", "u0003141", "l3141592", "441.14", "True", "u0003141"] + - ["2020-01-01 00:00:00", "2020-01-01", "2020-01-02", "u0003141", "u0003154", "l2718281", "499.99", "True", null] + - ["2020-01-01 00:00:00", "2020-01-01", "2020-01-02", "u0003154", "u0003141", "l2718281", "719.89", "False", null] + - ["2020-01-01 00:00:00", "2020-01-01", "2020-01-02", "u0004114", "u0003141", "l3141592", "319.85", "True", "u0005432"] + - ["2020-01-02 00:00:00", "2020-01-02", "2020-01-03", "u0004114", "u0003141", "l2718281", "442.42", "True", null] + - ["2020-01-02 00:00:00", "2020-01-02", "2020-01-03", "u0004114", "u0003141", "l2718281", "241.14", "True", null] + - ["2020-01-02 00:00:00", "2020-01-02", "2020-01-03", "u0004114", "u0003141", "l3141592", "799.99", "False", null] + - ["2020-01-02 00:00:00", "2020-01-02", "2020-01-03", "u0005432", "u0003452", "l2718281", "319.85", "True", "u0003452"] + - ["2020-01-02 00:00:00", "2020-01-02", "2020-01-03", "u0004114", "u1004114", "l9658588-incomplete", "0.0", "False", null] + - ["2020-01-02 00:00:00", "2020-01-02", "2020-01-03", "u0004114", "u1004114", "l8912456-incomplete", "0.0", "False", null] + - ["2020-01-02 00:00:00", "2020-01-02", "2020-01-03", "u0003452", "u0005432", "l3141592", "519.89", "False", "u0003141"] + - ["2020-01-02 00:00:00", "2020-01-02", "2020-01-03", "u0003452", "u0004114", "l5948301", "332.23", "False", "u0003141"] + - ["2020-01-02 00:00:00", "2020-01-02", "2020-01-03", "u1003452", "u1004114", "no_such_listing", "0.0", "False", null] + - ["2020-01-03 00:00:00", "2020-01-03", "2020-01-04", "u0003452", "u0004114", "l5948301", "0.0", "False", null] diff --git a/tests_metricflow/query_rendering/test_query_rendering.py b/tests_metricflow/query_rendering/test_query_rendering.py index 8bc409642..fdd7ea9e7 100644 --- a/tests_metricflow/query_rendering/test_query_rendering.py +++ b/tests_metricflow/query_rendering/test_query_rendering.py @@ -298,11 +298,14 @@ def test_join_to_scd_dimension( """Tests conversion of a plan using a dimension with a validity window inside a measure constraint.""" query_spec = scd_query_parser.parse_and_validate_query( metric_names=("family_bookings",), - group_by_names=(METRIC_TIME_ELEMENT_NAME,), + # group_by_names=(METRIC_TIME_ELEMENT_NAME,), where_constraints=[ PydanticWhereFilter( where_sql_template="{{ Dimension('listing__capacity') }} > 2", - ) + ), + PydanticWhereFilter( + where_sql_template="{{ TimeDimension('metric_time') }} > '2020-01-01'", + ), ], ).query_spec diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_join_to_scd_dimension__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_join_to_scd_dimension__plan0.sql index fc8d02763..f8fae3601 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_join_to_scd_dimension__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_join_to_scd_dimension__plan0.sql @@ -1,21 +1,21 @@ -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day - , subq_7.bookings AS family_bookings + subq_7.bookings AS family_bookings FROM ( -- Aggregate Measures SELECT - subq_6.metric_time__day - , SUM(subq_6.bookings) AS bookings + SUM(subq_6.bookings) AS bookings FROM ( - -- Pass Only Elements: ['bookings', 'metric_time__day'] + -- Pass Only Elements: ['bookings',] SELECT - subq_5.metric_time__day - , subq_5.bookings + subq_5.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_4.ds__day + subq_4.ds__second + , subq_4.ds__minute + , subq_4.ds__hour + , subq_4.ds__day , subq_4.ds__week , subq_4.ds__month , subq_4.ds__quarter @@ -48,6 +48,9 @@ FROM ( , subq_4.paid_at__extract_day , subq_4.paid_at__extract_dow , subq_4.paid_at__extract_doy + , subq_4.booking__ds__second + , subq_4.booking__ds__minute + , subq_4.booking__ds__hour , subq_4.booking__ds__day , subq_4.booking__ds__week , subq_4.booking__ds__month @@ -81,6 +84,9 @@ FROM ( , subq_4.booking__paid_at__extract_day , subq_4.booking__paid_at__extract_dow , subq_4.booking__paid_at__extract_doy + , subq_4.metric_time__second + , subq_4.metric_time__minute + , subq_4.metric_time__hour , subq_4.metric_time__day , subq_4.metric_time__week , subq_4.metric_time__month @@ -92,8 +98,8 @@ FROM ( , subq_4.metric_time__extract_day , subq_4.metric_time__extract_dow , subq_4.metric_time__extract_doy - , subq_4.listing__window_start__day - , subq_4.listing__window_end__day + , subq_4.listing__window_start__second + , subq_4.listing__window_end__second , subq_4.listing , subq_4.guest , subq_4.host @@ -114,8 +120,11 @@ FROM ( -- Join Standard Outputs SELECT subq_3.capacity AS listing__capacity - , subq_3.window_start__day AS listing__window_start__day - , subq_3.window_end__day AS listing__window_end__day + , subq_3.window_start__second AS listing__window_start__second + , subq_3.window_end__second AS listing__window_end__second + , subq_1.ds__second AS ds__second + , subq_1.ds__minute AS ds__minute + , subq_1.ds__hour AS ds__hour , subq_1.ds__day AS ds__day , subq_1.ds__week AS ds__week , subq_1.ds__month AS ds__month @@ -149,6 +158,9 @@ FROM ( , subq_1.paid_at__extract_day AS paid_at__extract_day , subq_1.paid_at__extract_dow AS paid_at__extract_dow , subq_1.paid_at__extract_doy AS paid_at__extract_doy + , subq_1.booking__ds__second AS booking__ds__second + , subq_1.booking__ds__minute AS booking__ds__minute + , subq_1.booking__ds__hour AS booking__ds__hour , subq_1.booking__ds__day AS booking__ds__day , subq_1.booking__ds__week AS booking__ds__week , subq_1.booking__ds__month AS booking__ds__month @@ -182,6 +194,9 @@ FROM ( , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_1.metric_time__second AS metric_time__second + , subq_1.metric_time__minute AS metric_time__minute + , subq_1.metric_time__hour AS metric_time__hour , subq_1.metric_time__day AS metric_time__day , subq_1.metric_time__week AS metric_time__week , subq_1.metric_time__month AS metric_time__month @@ -211,7 +226,10 @@ FROM ( FROM ( -- Metric Time Dimension 'ds' SELECT - subq_0.ds__day + subq_0.ds__second + , subq_0.ds__minute + , subq_0.ds__hour + , subq_0.ds__day , subq_0.ds__week , subq_0.ds__month , subq_0.ds__quarter @@ -244,6 +262,9 @@ FROM ( , subq_0.paid_at__extract_day , subq_0.paid_at__extract_dow , subq_0.paid_at__extract_doy + , subq_0.booking__ds__second + , subq_0.booking__ds__minute + , subq_0.booking__ds__hour , subq_0.booking__ds__day , subq_0.booking__ds__week , subq_0.booking__ds__month @@ -277,6 +298,9 @@ FROM ( , subq_0.booking__paid_at__extract_day , subq_0.booking__paid_at__extract_dow , subq_0.booking__paid_at__extract_doy + , subq_0.ds__second AS metric_time__second + , subq_0.ds__minute AS metric_time__minute + , subq_0.ds__hour AS metric_time__hour , subq_0.ds__day AS metric_time__day , subq_0.ds__week AS metric_time__week , subq_0.ds__month AS metric_time__month @@ -313,6 +337,9 @@ FROM ( , bookings_source_src_26000.booking_value AS average_booking_value , bookings_source_src_26000.booking_value AS booking_payments , bookings_source_src_26000.is_instant + , DATE_TRUNC('second', bookings_source_src_26000.ds) AS ds__second + , DATE_TRUNC('minute', bookings_source_src_26000.ds) AS ds__minute + , DATE_TRUNC('hour', bookings_source_src_26000.ds) AS ds__hour , DATE_TRUNC('day', bookings_source_src_26000.ds) AS ds__day , DATE_TRUNC('week', bookings_source_src_26000.ds) AS ds__week , DATE_TRUNC('month', bookings_source_src_26000.ds) AS ds__month @@ -347,6 +374,9 @@ FROM ( , EXTRACT(isodow FROM bookings_source_src_26000.paid_at) AS paid_at__extract_dow , EXTRACT(doy FROM bookings_source_src_26000.paid_at) AS paid_at__extract_doy , bookings_source_src_26000.is_instant AS booking__is_instant + , DATE_TRUNC('second', bookings_source_src_26000.ds) AS booking__ds__second + , DATE_TRUNC('minute', bookings_source_src_26000.ds) AS booking__ds__minute + , DATE_TRUNC('hour', bookings_source_src_26000.ds) AS booking__ds__hour , DATE_TRUNC('day', bookings_source_src_26000.ds) AS booking__ds__day , DATE_TRUNC('week', bookings_source_src_26000.ds) AS booking__ds__week , DATE_TRUNC('month', bookings_source_src_26000.ds) AS booking__ds__month @@ -392,16 +422,19 @@ FROM ( ) subq_0 ) subq_1 LEFT OUTER JOIN ( - -- Pass Only Elements: ['capacity', 'window_start__day', 'window_end__day', 'listing'] + -- Pass Only Elements: ['capacity', 'window_start__second', 'window_end__second', 'listing'] SELECT - subq_2.window_start__day - , subq_2.window_end__day + subq_2.window_start__second + , subq_2.window_end__second , subq_2.listing , subq_2.capacity FROM ( -- Read Elements From Semantic Model 'listings' SELECT - listings_src_26000.active_from AS window_start__day + listings_src_26000.active_from AS window_start__second + , DATE_TRUNC('minute', listings_src_26000.active_from) AS window_start__minute + , DATE_TRUNC('hour', listings_src_26000.active_from) AS window_start__hour + , DATE_TRUNC('day', listings_src_26000.active_from) AS window_start__day , DATE_TRUNC('week', listings_src_26000.active_from) AS window_start__week , DATE_TRUNC('month', listings_src_26000.active_from) AS window_start__month , DATE_TRUNC('quarter', listings_src_26000.active_from) AS window_start__quarter @@ -412,7 +445,10 @@ FROM ( , EXTRACT(day FROM listings_src_26000.active_from) AS window_start__extract_day , EXTRACT(isodow FROM listings_src_26000.active_from) AS window_start__extract_dow , EXTRACT(doy FROM listings_src_26000.active_from) AS window_start__extract_doy - , listings_src_26000.active_to AS window_end__day + , listings_src_26000.active_to AS window_end__second + , DATE_TRUNC('minute', listings_src_26000.active_to) AS window_end__minute + , DATE_TRUNC('hour', listings_src_26000.active_to) AS window_end__hour + , DATE_TRUNC('day', listings_src_26000.active_to) AS window_end__day , DATE_TRUNC('week', listings_src_26000.active_to) AS window_end__week , DATE_TRUNC('month', listings_src_26000.active_to) AS window_end__month , DATE_TRUNC('quarter', listings_src_26000.active_to) AS window_end__quarter @@ -426,7 +462,10 @@ FROM ( , listings_src_26000.country , listings_src_26000.is_lux , listings_src_26000.capacity - , listings_src_26000.active_from AS listing__window_start__day + , listings_src_26000.active_from AS listing__window_start__second + , DATE_TRUNC('minute', listings_src_26000.active_from) AS listing__window_start__minute + , DATE_TRUNC('hour', listings_src_26000.active_from) AS listing__window_start__hour + , DATE_TRUNC('day', listings_src_26000.active_from) AS listing__window_start__day , DATE_TRUNC('week', listings_src_26000.active_from) AS listing__window_start__week , DATE_TRUNC('month', listings_src_26000.active_from) AS listing__window_start__month , DATE_TRUNC('quarter', listings_src_26000.active_from) AS listing__window_start__quarter @@ -437,7 +476,10 @@ FROM ( , EXTRACT(day FROM listings_src_26000.active_from) AS listing__window_start__extract_day , EXTRACT(isodow FROM listings_src_26000.active_from) AS listing__window_start__extract_dow , EXTRACT(doy FROM listings_src_26000.active_from) AS listing__window_start__extract_doy - , listings_src_26000.active_to AS listing__window_end__day + , listings_src_26000.active_to AS listing__window_end__second + , DATE_TRUNC('minute', listings_src_26000.active_to) AS listing__window_end__minute + , DATE_TRUNC('hour', listings_src_26000.active_to) AS listing__window_end__hour + , DATE_TRUNC('day', listings_src_26000.active_to) AS listing__window_end__day , DATE_TRUNC('week', listings_src_26000.active_to) AS listing__window_end__week , DATE_TRUNC('month', listings_src_26000.active_to) AS listing__window_end__month , DATE_TRUNC('quarter', listings_src_26000.active_to) AS listing__window_end__quarter @@ -462,19 +504,17 @@ FROM ( subq_1.listing = subq_3.listing ) AND ( ( - subq_1.metric_time__day >= subq_3.window_start__day + subq_1.metric_time__second >= subq_3.window_start__second ) AND ( ( - subq_1.metric_time__day < subq_3.window_end__day + subq_1.metric_time__second < subq_3.window_end__second ) OR ( - subq_3.window_end__day IS NULL + subq_3.window_end__second IS NULL ) ) ) ) subq_4 - WHERE listing__capacity > 2 + WHERE (listing__capacity > 2) AND (metric_time__day > '2020-01-01') ) subq_5 ) subq_6 - GROUP BY - subq_6.metric_time__day ) subq_7 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_join_to_scd_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_join_to_scd_dimension__plan0_optimized.sql index 6b1bdca6c..7c3942b54 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_join_to_scd_dimension__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_join_to_scd_dimension__plan0_optimized.sql @@ -1,10 +1,9 @@ -- Constrain Output with WHERE --- Pass Only Elements: ['bookings', 'metric_time__day'] +-- Pass Only Elements: ['bookings',] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - metric_time__day - , SUM(bookings) AS family_bookings + SUM(bookings) AS family_bookings FROM ( -- Join Standard Outputs SELECT @@ -15,7 +14,8 @@ FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' SELECT - DATE_TRUNC('day', ds) AS metric_time__day + DATE_TRUNC('second', ds) AS metric_time__second + , DATE_TRUNC('day', ds) AS metric_time__day , listing_id AS listing , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_26000 @@ -27,16 +27,14 @@ FROM ( subq_9.listing = listings_src_26000.listing_id ) AND ( ( - subq_9.metric_time__day >= listings_src_26000.active_from + subq_9.metric_time__second >= listings_src_26000.active_from ) AND ( ( - subq_9.metric_time__day < listings_src_26000.active_to + subq_9.metric_time__second < listings_src_26000.active_to ) OR ( listings_src_26000.active_to IS NULL ) ) ) ) subq_12 -WHERE listing__capacity > 2 -GROUP BY - metric_time__day +WHERE (listing__capacity > 2) AND (metric_time__day > '2020-01-01') diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multi_hop_through_scd_dimension__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multi_hop_through_scd_dimension__plan0.sql index 281be2468..9746d9e97 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multi_hop_through_scd_dimension__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multi_hop_through_scd_dimension__plan0.sql @@ -19,8 +19,8 @@ FROM ( -- Join Standard Outputs SELECT subq_6.user__home_state_latest AS listing__user__home_state_latest - , subq_6.window_start__day AS listing__window_start__day - , subq_6.window_end__day AS listing__window_end__day + , subq_6.window_start__second AS listing__window_start__second + , subq_6.window_end__second AS listing__window_end__second , subq_1.ds__day AS ds__day , subq_1.ds__week AS ds__week , subq_1.ds__month AS ds__month @@ -297,10 +297,10 @@ FROM ( ) subq_0 ) subq_1 LEFT OUTER JOIN ( - -- Pass Only Elements: ['user__home_state_latest', 'window_start__day', 'window_end__day', 'listing'] + -- Pass Only Elements: ['user__home_state_latest', 'window_start__second', 'window_end__second', 'listing'] SELECT - subq_5.window_start__day - , subq_5.window_end__day + subq_5.window_start__second + , subq_5.window_end__second , subq_5.listing , subq_5.user__home_state_latest FROM ( @@ -318,6 +318,9 @@ FROM ( , subq_4.ds__extract_day AS user__ds__extract_day , subq_4.ds__extract_dow AS user__ds__extract_dow , subq_4.ds__extract_doy AS user__ds__extract_doy + , subq_2.window_start__second AS window_start__second + , subq_2.window_start__minute AS window_start__minute + , subq_2.window_start__hour AS window_start__hour , subq_2.window_start__day AS window_start__day , subq_2.window_start__week AS window_start__week , subq_2.window_start__month AS window_start__month @@ -329,6 +332,9 @@ FROM ( , subq_2.window_start__extract_day AS window_start__extract_day , subq_2.window_start__extract_dow AS window_start__extract_dow , subq_2.window_start__extract_doy AS window_start__extract_doy + , subq_2.window_end__second AS window_end__second + , subq_2.window_end__minute AS window_end__minute + , subq_2.window_end__hour AS window_end__hour , subq_2.window_end__day AS window_end__day , subq_2.window_end__week AS window_end__week , subq_2.window_end__month AS window_end__month @@ -340,6 +346,9 @@ FROM ( , subq_2.window_end__extract_day AS window_end__extract_day , subq_2.window_end__extract_dow AS window_end__extract_dow , subq_2.window_end__extract_doy AS window_end__extract_doy + , subq_2.listing__window_start__second AS listing__window_start__second + , subq_2.listing__window_start__minute AS listing__window_start__minute + , subq_2.listing__window_start__hour AS listing__window_start__hour , subq_2.listing__window_start__day AS listing__window_start__day , subq_2.listing__window_start__week AS listing__window_start__week , subq_2.listing__window_start__month AS listing__window_start__month @@ -351,6 +360,9 @@ FROM ( , subq_2.listing__window_start__extract_day AS listing__window_start__extract_day , subq_2.listing__window_start__extract_dow AS listing__window_start__extract_dow , subq_2.listing__window_start__extract_doy AS listing__window_start__extract_doy + , subq_2.listing__window_end__second AS listing__window_end__second + , subq_2.listing__window_end__minute AS listing__window_end__minute + , subq_2.listing__window_end__hour AS listing__window_end__hour , subq_2.listing__window_end__day AS listing__window_end__day , subq_2.listing__window_end__week AS listing__window_end__week , subq_2.listing__window_end__month AS listing__window_end__month @@ -374,7 +386,10 @@ FROM ( FROM ( -- Read Elements From Semantic Model 'listings' SELECT - listings_src_26000.active_from AS window_start__day + listings_src_26000.active_from AS window_start__second + , DATE_TRUNC('minute', listings_src_26000.active_from) AS window_start__minute + , DATE_TRUNC('hour', listings_src_26000.active_from) AS window_start__hour + , DATE_TRUNC('day', listings_src_26000.active_from) AS window_start__day , DATE_TRUNC('week', listings_src_26000.active_from) AS window_start__week , DATE_TRUNC('month', listings_src_26000.active_from) AS window_start__month , DATE_TRUNC('quarter', listings_src_26000.active_from) AS window_start__quarter @@ -385,7 +400,10 @@ FROM ( , EXTRACT(day FROM listings_src_26000.active_from) AS window_start__extract_day , EXTRACT(isodow FROM listings_src_26000.active_from) AS window_start__extract_dow , EXTRACT(doy FROM listings_src_26000.active_from) AS window_start__extract_doy - , listings_src_26000.active_to AS window_end__day + , listings_src_26000.active_to AS window_end__second + , DATE_TRUNC('minute', listings_src_26000.active_to) AS window_end__minute + , DATE_TRUNC('hour', listings_src_26000.active_to) AS window_end__hour + , DATE_TRUNC('day', listings_src_26000.active_to) AS window_end__day , DATE_TRUNC('week', listings_src_26000.active_to) AS window_end__week , DATE_TRUNC('month', listings_src_26000.active_to) AS window_end__month , DATE_TRUNC('quarter', listings_src_26000.active_to) AS window_end__quarter @@ -399,7 +417,10 @@ FROM ( , listings_src_26000.country , listings_src_26000.is_lux , listings_src_26000.capacity - , listings_src_26000.active_from AS listing__window_start__day + , listings_src_26000.active_from AS listing__window_start__second + , DATE_TRUNC('minute', listings_src_26000.active_from) AS listing__window_start__minute + , DATE_TRUNC('hour', listings_src_26000.active_from) AS listing__window_start__hour + , DATE_TRUNC('day', listings_src_26000.active_from) AS listing__window_start__day , DATE_TRUNC('week', listings_src_26000.active_from) AS listing__window_start__week , DATE_TRUNC('month', listings_src_26000.active_from) AS listing__window_start__month , DATE_TRUNC('quarter', listings_src_26000.active_from) AS listing__window_start__quarter @@ -410,7 +431,10 @@ FROM ( , EXTRACT(day FROM listings_src_26000.active_from) AS listing__window_start__extract_day , EXTRACT(isodow FROM listings_src_26000.active_from) AS listing__window_start__extract_dow , EXTRACT(doy FROM listings_src_26000.active_from) AS listing__window_start__extract_doy - , listings_src_26000.active_to AS listing__window_end__day + , listings_src_26000.active_to AS listing__window_end__second + , DATE_TRUNC('minute', listings_src_26000.active_to) AS listing__window_end__minute + , DATE_TRUNC('hour', listings_src_26000.active_to) AS listing__window_end__hour + , DATE_TRUNC('day', listings_src_26000.active_to) AS listing__window_end__day , DATE_TRUNC('week', listings_src_26000.active_to) AS listing__window_end__week , DATE_TRUNC('month', listings_src_26000.active_to) AS listing__window_end__month , DATE_TRUNC('quarter', listings_src_26000.active_to) AS listing__window_end__quarter @@ -523,12 +547,12 @@ FROM ( subq_1.listing = subq_6.listing ) AND ( ( - subq_1.metric_time__day >= subq_6.window_start__day + subq_1.metric_time__day >= subq_6.window_start__second ) AND ( ( - subq_1.metric_time__day < subq_6.window_end__day + subq_1.metric_time__day < subq_6.window_end__second ) OR ( - subq_6.window_end__day IS NULL + subq_6.window_end__second IS NULL ) ) ) diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multi_hop_through_scd_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multi_hop_through_scd_dimension__plan0_optimized.sql index c693b5ecd..4a6d0ce04 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multi_hop_through_scd_dimension__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multi_hop_through_scd_dimension__plan0_optimized.sql @@ -17,10 +17,10 @@ FROM ( ) subq_11 LEFT OUTER JOIN ( -- Join Standard Outputs - -- Pass Only Elements: ['user__home_state_latest', 'window_start__day', 'window_end__day', 'listing'] + -- Pass Only Elements: ['user__home_state_latest', 'window_start__second', 'window_end__second', 'listing'] SELECT - listings_src_26000.active_from AS window_start__day - , listings_src_26000.active_to AS window_end__day + listings_src_26000.active_from AS window_start__second + , listings_src_26000.active_to AS window_end__second , listings_src_26000.listing_id AS listing , users_latest_src_26000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings listings_src_26000 @@ -34,12 +34,12 @@ ON subq_11.listing = subq_16.listing ) AND ( ( - subq_11.metric_time__day >= subq_16.window_start__day + subq_11.metric_time__day >= subq_16.window_start__second ) AND ( ( - subq_11.metric_time__day < subq_16.window_end__day + subq_11.metric_time__day < subq_16.window_end__second ) OR ( - subq_16.window_end__day IS NULL + subq_16.window_end__second IS NULL ) ) )