Flight Data — Hub Airport Connectivity
Flight Data benchmark · all Flight Data queries
Number of unique destinations served from each origin airport
Representative SQL
Rendered for DataFusion with default parameters.
SELECT f.origin, ap.name AS airport_name, ap.city, ap.state, COUNT(DISTINCT f.dest) AS unique_destinations, COUNT(DISTINCT f.reporting_airline) AS serving_carriers, COUNT(*) AS total_departures, ROUND(CAST(AVG(f.dep_delay) AS DECIMAL), 2) AS avg_dep_delayFROM flights AS fLEFT JOIN airports AS ap ON f.origin = ap.codeWHERE f.cancelled = 0 AND f.flight_date >= '2021-08-01' AND f.flight_date < '2025-01-01'GROUP BY f.origin, ap.name, ap.city, ap.stateORDER BY total_departures DESC NULLS LAST, f.originLIMIT 30Representative DataFrame
Expression family (Polars, PySpark, DataFusion), default parameters.
def hub_connectivity_expression_impl(ctx: DataFrameContext) -> Any: flights = ctx.get_table("flights") col, lit = ctx.col, ctx.lit airports = ctx.get_table("airports")
ap = airports.select( col("code").alias("ap_code"), col("name").alias("airport_name"), col("city"), col("state"), )
return ( flights.join(ap, left_on="origin", right_on="ap_code", how="left") .filter(_date_condition(col, lit, lambda col, lit: col("cancelled") == lit(0))) .group_by("origin", "airport_name", "city", "state") .agg( col("dest").n_unique().alias("unique_destinations"), col("reporting_airline").n_unique().alias("serving_carriers"), col("flight_id").count().alias("total_departures"), col("dep_delay").mean().alias("_avg_dep"), ) .with_columns(_round_half_away(ctx, col("_avg_dep"), 2).alias("avg_dep_delay")) .select( "origin", "airport_name", "city", "state", "unique_destinations", "serving_carriers", "total_departures", "avg_dep_delay", ) .sort(["total_departures", "origin"], descending=[True, False]) .limit(30) )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 factorqueries = bench.get_queries(dialect="datafusion") # your platform's dialect; drop dialect= for native SQLprint(queries['hub-connectivity'])For the DataFrame form:
from benchbox.core.query_catalog import get_dataframe_render
print(get_dataframe_render('flightdata', 'hub-connectivity', family="expression").source) # or family="pandas"Source
Query text: benchbox/core/flightdata/queries.py