From 0234cac4fb833829a1fb239637b79d64afd0faf2 Mon Sep 17 00:00:00 2001 From: Jordan Stein Date: Thu, 18 Jul 2024 16:43:07 -0700 Subject: [PATCH 1/4] add repro --- dbt_project.yml | 2 +- models/marts/customer360/order_items.yml | 36 +++++++++++++++++++++--- models/marts/customer360/orders.yml | 2 +- requirements.txt | 3 +- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/dbt_project.yml b/dbt_project.yml index b597dad..e5dbb51 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -6,7 +6,7 @@ version: "1.0.0" config-version: 2 # This setting configures which "profile" dbt uses for this project. -profile: "snowflake" +profile: "bigquery" require-dbt-version: ">=1.6.0rc2" # These configurations specify where dbt should look for different types of files. diff --git a/models/marts/customer360/order_items.yml b/models/marts/customer360/order_items.yml index f577416..b7b5614 100644 --- a/models/marts/customer360/order_items.yml +++ b/models/marts/customer360/order_items.yml @@ -21,6 +21,11 @@ semantic_models: type: time type_params: time_granularity: day + - name: ordered_at_test + expr: cast(ordered_at as DATETIME) + type: time + type_params: + time_granularity: day - name: is_food_item type: categorical - name: is_drink_item @@ -41,7 +46,10 @@ semantic_models: expr: case when is_drink_item = 1 then product_price else 0 end - name: median_revenue description: The median revenue generated for each order item. - agg: median + agg: percentile + agg_params: + percentile: .5 + use_approximate_percentile: True expr: product_price groups: @@ -66,12 +74,16 @@ metrics: measure: name: revenue fill_nulls_with: 0 + join_to_timespine: true - name: order_cost description: Sum of cost for each order item. label: Order Cost type: simple type_params: - measure: order_cost + measure: + name: order_cost + join_to_timespine: true + fill_nulls_with: 0 - name: median_revenue description: The median revenue for each order item. Excludes tax. type: simple @@ -125,8 +137,8 @@ metrics: type: cumulative type_params: measure: revenue - cumulative_type_params: - period_agg: last + # cumulative_type_params: + # period_agg: last saved_queries: - name: order_metrics @@ -161,3 +173,19 @@ saved_queries: - name: weekly_revenue config: export_as: table + - name: order_cost_time_spine_test + query_params: + metrics: + - revenue + group_by: + - TimeDimension('metric_time', 'day') + where: + # - "{{TimeDimension('metric_time', 'day')}} >= + # CASE + # WHEN EXTRACT(day FROM CURRENT_DATE AT TIME ZONE 'America/New_York') > 14 THEN + # DATEADD(month, 1, DATE_TRUNC(month, CURRENT_DATE AT TIME ZONE 'America/New_York')) + # WHEN EXTRACT(day FROM CURRENT_DATE AT TIME ZONE 'America/New_York') <= 14 THEN + # DATE_TRUNC(month, CURRENT_DATE AT TIME ZONE 'America/New_York') + # ELSE NULL + # END" + - "{{TimeDimension('order_item__ordered_at_test', 'month')}}>= '2020-01-01'" \ No newline at end of file diff --git a/models/marts/customer360/orders.yml b/models/marts/customer360/orders.yml index a4e3cc5..af5676a 100644 --- a/models/marts/customer360/orders.yml +++ b/models/marts/customer360/orders.yml @@ -60,7 +60,7 @@ semantic_models: expr: customer_id dimensions: - name: ordered_at - expr: ordered_at + expr: cast(ordered_at as datetime) type: time type_params: time_granularity: day diff --git a/requirements.txt b/requirements.txt index 5b0f807..b6dc0cf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ -dbt-metricflow[snowflake]==0.0.5 +dbt-core +dbt-snowflake pre-commit~=3.0.4 sqlfluff-templater-dbt~=2.0.0a5 sqlfluff~=2.0.0a5 From 6f6c18e7b064008372ec30d0840a03d95f66fabd Mon Sep 17 00:00:00 2001 From: Jordan Stein Date: Thu, 18 Jul 2024 16:51:20 -0700 Subject: [PATCH 2/4] add metric time month --- models/marts/customer360/order_items.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/models/marts/customer360/order_items.yml b/models/marts/customer360/order_items.yml index b7b5614..9061d08 100644 --- a/models/marts/customer360/order_items.yml +++ b/models/marts/customer360/order_items.yml @@ -188,4 +188,5 @@ saved_queries: # DATE_TRUNC(month, CURRENT_DATE AT TIME ZONE 'America/New_York') # ELSE NULL # END" - - "{{TimeDimension('order_item__ordered_at_test', 'month')}}>= '2020-01-01'" \ No newline at end of file + # - "{{TimeDimension('order_item__ordered_at_test', 'month')}}>= '2020-01-01'" + - "{{TimeDimension('metric_time', 'month')}}>= '2020-01-01'" \ No newline at end of file From 557bbe13f2c9116b005176e02f8b2b71acb2d1ba Mon Sep 17 00:00:00 2001 From: Jordan Stein Date: Mon, 22 Jul 2024 20:45:51 -0700 Subject: [PATCH 3/4] update order total for demo --- models/staging/stg_orders.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/staging/stg_orders.sql b/models/staging/stg_orders.sql index 0eaf6ae..4f645d1 100644 --- a/models/staging/stg_orders.sql +++ b/models/staging/stg_orders.sql @@ -18,7 +18,7 @@ renamed as ( customer as customer_id, ---------- numerics - (order_total / 100.0) as order_total, + (order_total / 100.0) as order_total_, (tax_paid / 100.0) as tax_paid, ---------- timestamps From a554c035b3fee9766ef75908ed1984e77416bb17 Mon Sep 17 00:00:00 2001 From: Jordan Stein Date: Mon, 22 Jul 2024 20:54:34 -0700 Subject: [PATCH 4/4] update customers --- models/marts/customer360/customers.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/marts/customer360/customers.sql b/models/marts/customer360/customers.sql index 36db145..24347f8 100644 --- a/models/marts/customer360/customers.sql +++ b/models/marts/customer360/customers.sql @@ -27,7 +27,7 @@ order_summary as ( min(orders.ordered_at) as first_ordered_at, max(orders.ordered_at) as last_ordered_at, sum(order_items.product_price) as lifetime_spend_pretax, - sum(orders.order_total) as lifetime_spend + sum(orders.order_total_) as lifetime_spend from orders_table as orders