feat(pipeline): add e2e orders master medallion flow and dbt models

This commit is contained in:
2026-10-19 01:53:47 +07:00
parent e7d19ebb48
commit a5d766489a
4 changed files with 785 additions and 0 deletions
@@ -0,0 +1,16 @@
-- dbt Gold Regional Waste Revenue & Compliance Mart
SELECT
region_zone,
facility_type,
waste_category,
COUNT(order_id) AS total_orders,
COUNT(DISTINCT facility_id) AS active_facilities_count,
COUNT(DISTINCT generator_company) AS active_generators_count,
ROUND(SUM(volume_ton), 2) AS total_waste_volume_ton,
ROUND(SUM(total_order_amount), 2) AS total_gross_revenue,
ROUND(AVG(total_order_amount / NULLIF(volume_ton, 0)), 2) AS avg_revenue_per_ton,
COUNT(CASE WHEN environmental_compliance_status = 'COMPLIANT' THEN 1 END) AS compliant_orders_count,
CURRENT_TIMESTAMP AS mart_refreshed_at
FROM {{ ref('silver_waste_manifest_enriched') }}
GROUP BY region_zone, facility_type, waste_category
ORDER BY total_waste_volume_ton DESC
@@ -0,0 +1,27 @@
-- dbt Silver Cleansed Manifest Orders Enriched with Master Facilities
SELECT
o.order_id,
o.manifest_code,
o.order_date,
o.generator_company,
o.waste_category,
o.volume_ton,
o.tariff_per_ton,
o.transport_fee,
ROUND((o.volume_ton * o.tariff_per_ton) + o.transport_fee, 2) AS total_order_amount,
o.order_status,
f.facility_id,
f.facility_name,
f.region_zone,
f.facility_type,
f.compliance_rating,
f.facility_status,
CASE
WHEN f.facility_status = 'ACTIVE' AND o.volume_ton <= f.max_daily_capacity_ton THEN 'COMPLIANT'
WHEN f.facility_status != 'ACTIVE' THEN 'UNLICENSED_FACILITY_WARNING'
ELSE 'CAPACITY_EXCEEDED_WARNING'
END AS environmental_compliance_status
FROM {{ ref('bronze_waste_orders') }} o
LEFT JOIN {{ ref('bronze_ref_facilities') }} f
ON o.facility_id = f.facility_id
WHERE o.order_status != 'CANCELLED'