Skip to content

Flight Data — On-Time Performance Trend Over Years

Flight Data benchmark · all Flight Data queries

Annual on-time arrival percentage trend

Representative SQL

Rendered in the benchmark’s native SQL with default parameters (no dialect translation available).

SELECT
f.year,
COUNT(*) AS total_flights,
SUM(CASE WHEN f.cancelled = 1 THEN 1 ELSE 0 END) AS cancelled_flights,
ROUND(100.0 * SUM(CASE WHEN f.cancelled = 1 THEN 1 ELSE 0 END) / COUNT(*), 2) AS cancellation_rate_pct,
SUM(CASE WHEN f.cancelled = 0 AND f.arr_delay <= 15 THEN 1 ELSE 0 END) AS ontime_flights,
ROUND(
100.0 * SUM(CASE WHEN f.cancelled = 0 AND f.arr_delay <= 15 THEN 1 ELSE 0 END) / NULLIF(SUM(CASE WHEN f.cancelled = 0 THEN 1 ELSE 0 END), 0),
2
) AS ontime_pct,
ROUND(AVG(CASE WHEN f.cancelled = 0 THEN f.arr_delay END), 2) AS avg_arr_delay
FROM flights AS f
WHERE
f.flight_date >= '2021-08-01' AND f.flight_date < '2025-01-01'
GROUP BY
f.year
ORDER BY
f.year

Representative DataFrame

Expression family (Polars, PySpark, DataFusion), default parameters.

def improvement_trend_expression_impl(ctx: DataFrameContext) -> Any:
flights, col, lit = _date_window(ctx)
return (
flights.with_columns(
(col("cancelled") == lit(1)).cast(int).alias("_cancelled"),
((col("cancelled") == lit(0)) & (col("arr_delay") <= lit(15))).cast(int).alias("_ontime"),
(col("cancelled") == lit(0)).cast(int).alias("_operated"),
ctx.when(col("cancelled") == lit(0)).then(col("arr_delay")).otherwise(lit(None)).alias("_arr_nc"),
)
.group_by("year")
.agg(
col("flight_id").count().alias("total_flights"),
col("_cancelled").sum().alias("cancelled_flights"),
col("_ontime").sum().alias("ontime_flights"),
col("_operated").sum().alias("_non_cancelled"),
col("_arr_nc").mean().alias("_avg_arr"),
)
.with_columns(
ctx.when(col("_non_cancelled") > lit(0))
.then(col("_non_cancelled"))
.otherwise(lit(None))
.alias("_non_cancelled_nz"),
)
.with_columns(
_round_half_away(ctx, lit(100.0) * col("cancelled_flights") / col("total_flights"), 2).alias(
"cancellation_rate_pct"
),
_round_half_away(ctx, lit(100.0) * col("ontime_flights") / col("_non_cancelled_nz"), 2).alias("ontime_pct"),
_round_half_away(ctx, col("_avg_arr"), 2).alias("avg_arr_delay"),
)
.select(
"year",
"total_flights",
"cancelled_flights",
"cancellation_rate_pct",
"ontime_flights",
"ontime_pct",
"avg_arr_delay",
)
.sort("year")
)

Get the exact query for your run

The blocks above are representative. To get the precise statement a specific platform runs at a specific scale, substitute your own values:

from benchbox import FlightData
bench = FlightData(scale_factor=1.0) # your scale factor
print(bench.get_queries()['improvement-trend'])

For the DataFrame form:

from benchbox.core.query_catalog import get_dataframe_render
print(get_dataframe_render('flightdata', 'improvement-trend', family="expression").source) # or family="pandas"

Source

Query text: benchbox/core/flightdata/queries.py