Flight Data — On-Time Rate by Carrier
Flight Data benchmark · all Flight Data queries
On-time arrival percentage by airline carrier
Representative SQL
Rendered in the benchmark’s native SQL with default parameters (no dialect translation available).
SELECT f.reporting_airline, a.name AS airline_name, COUNT(*) AS total_flights, SUM(CASE WHEN f.arr_delay <= 15 THEN 1 ELSE 0 END) AS ontime_flights, ROUND(100.0 * SUM(CASE WHEN f.arr_delay <= 15 THEN 1 ELSE 0 END) / COUNT(*), 2) AS ontime_pct, ROUND(AVG(CASE WHEN f.arr_delay > 0 THEN f.arr_delay END), 2) AS avg_delay_when_lateFROM flights AS fLEFT JOIN airlines AS a ON f.reporting_airline = a.codeWHERE f.cancelled = 0 AND f.flight_date >= '2021-08-01' AND f.flight_date < '2025-01-01'GROUP BY f.reporting_airline, a.nameORDER BY ontime_pct DESC, f.reporting_airlineRepresentative DataFrame
Expression family (Polars, PySpark, DataFusion), default parameters.
def ontime_by_carrier_expression_impl(ctx: DataFrameContext) -> Any: flights = ctx.get_table("flights") col, lit = ctx.col, ctx.lit
return ( flights.join(_airline_names(ctx), left_on="reporting_airline", right_on="a_code", how="left") .filter(_date_condition(col, lit, lambda col, lit: col("cancelled") == lit(0))) .with_columns( (col("arr_delay") <= lit(15)).cast(int).alias("_ontime"), ctx.when(col("arr_delay") > lit(0)).then(col("arr_delay")).otherwise(lit(None)).alias("_late_delay"), ) .group_by("reporting_airline", "airline_name") .agg( col("flight_id").count().alias("total_flights"), col("_ontime").sum().alias("ontime_flights"), col("_late_delay").mean().alias("_avg_late"), ) .with_columns( _round_half_away(ctx, lit(100.0) * col("ontime_flights") / col("total_flights"), 2).alias("ontime_pct"), _round_half_away(ctx, col("_avg_late"), 2).alias("avg_delay_when_late"), ) .select( "reporting_airline", "airline_name", "total_flights", "ontime_flights", "ontime_pct", "avg_delay_when_late", ) .sort(["ontime_pct", "reporting_airline"], descending=[True, False], nulls_last=True) )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 factorprint(bench.get_queries()['ontime-by-carrier'])For the DataFrame form:
from benchbox.core.query_catalog import get_dataframe_render
print(get_dataframe_render('flightdata', 'ontime-by-carrier', family="expression").source) # or family="pandas"Source
Query text: benchbox/core/flightdata/queries.py