swadhinbiswas

[email protected]
2026-09-14 12:33:47 +0600 committed NaN years ago
4a8f3c5
commit 4a8f3c5
2 files changed
+13 -3
▼dbt/models/marts/route_performance.sql
+7-2
16
16
count(f.flight_id) as total_flights,
17
17
round(avg(f.delay_minutes), 2) as avg_delay_minutes,
18
18
round(
19
- avg(case when f.delay_minutes <= {{ var('on_time_threshold_minutes') }} then 1.0 else 0.0 end), 4
19
+ avg(case
20
+ when f.delay_minutes is null then null
21
+ when f.delay_minutes <= {{ var('on_time_threshold_minutes') }} then 1.0
22
+ else 0.0
23
+ end), 4
20
24
) as on_time_rate,
21
25
avg(r.distance_km) as avg_distance_km
22
26
from routes r
23
- left join flights f on f.departure_icao = r.origin and f.arrival_icao = r.destination
27
+ inner join flights f
28
+ on f.departure_icao = r.origin and f.arrival_icao = r.destination
24
29
group by r.origin, r.destination, r.airline
25
30
)
26
31
27
32
▼dbt/models/staging/stg_fact_flights.sql
+6-1
9
9
flight_id,
10
10
callsign,
11
11
trim(callsign) as callsign_clean,
12
- airline_icao,
12
+ -- OpenSky rows carry no airline code; the callsign prefix is the ICAO
13
+ -- operator (DLH100 -> DLH), which makes airline rankings complete.
14
+ coalesce(
15
+ airline_icao,
16
+ nullif(left(upper(trim(coalesce(callsign, ''))), 3), '')
17
+ ) as airline_icao,
13
18
departure_icao,
14
19
arrival_icao,
15
20
-- Historical Silver rows can hold these as VARCHAR (columns added at
16
21