Migrate Metrics from REP to FCT

This commit is contained in:
CIEF DataTeam
2023-07-31 16:08:46 +00:00
parent 631e7769b9
commit 66b79b6ece
@@ -26,25 +26,21 @@ join_tables AS (
create_metrics AS (
SELECT
*,
{% for column_name in ["parent_company", "sub_company"] %}
CASE
WHEN ROW_NUMBER() OVER (PARTITION BY join_tables.{{column_name}}_id ORDER BY join_tables.origin_warehouse_shipping_order_created_datetime) = 1 THEN 1
WHEN ROW_NUMBER() OVER (PARTITION BY join_tables.parent_company_id ORDER BY join_tables.origin_warehouse_shipping_order_created_datetime) = 1 THEN 1
ELSE 0
END AS is_first_time_{{column_name}},
END AS is_first_time_parent_company,
CASE
WHEN join_tables.origin_warehouse_shipping_order_status = 'COMPLETED'
AND
MIN(IFF(join_tables.origin_warehouse_shipping_order_status = 'COMPLETED', join_tables.origin_warehouse_shipping_order_created_datetime, NULL))
OVER (PARTITION BY join_tables.{{column_name}}_id)
OVER (PARTITION BY join_tables.parent_company_id)
= join_tables.origin_warehouse_shipping_order_created_datetime
THEN 1
ELSE 0
END AS is_first_time_{{column_name}}_completed,
{% endfor %}
-- temp debug, need make sure it do not have null in fct, cause cant add
(ZEROIFNULL(total_package_cbm) + ZEROIFNULL(over_weight_cbm) + ZEROIFNULL(pallet_charge_cbm)) AS total_order_cbm,
END AS is_first_time_parent_company_completed,
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime