2020-04-03 13:23:32 +00:00
---
2022-04-09 13:29:05 +00:00
sidebar_label: OnTime Airline Flight Data
description: Dataset containing the on-time performance of airline flights
2020-04-03 13:23:32 +00:00
---
2022-04-09 13:29:05 +00:00
# OnTime
2017-12-28 15:13:23 +00:00
2022-05-29 03:26:13 +00:00
This dataset contains data from Bureau of Transportation Statistics.
2019-01-24 16:10:05 +00:00
2022-05-29 03:43:50 +00:00
## Creating a table
2017-12-28 15:13:23 +00:00
2020-03-20 10:10:48 +00:00
``` sql
2021-02-23 12:08:01 +00:00
CREATE TABLE `ontime`
(
`Year` UInt16,
`Quarter` UInt8,
`Month` UInt8,
`DayofMonth` UInt8,
`DayOfWeek` UInt8,
`FlightDate` Date,
2022-05-29 03:26:13 +00:00
`Reporting_Airline` LowCardinality(String),
2021-02-23 12:08:01 +00:00
`DOT_ID_Reporting_Airline` Int32,
2022-05-29 03:26:13 +00:00
`IATA_CODE_Reporting_Airline` LowCardinality(String),
`Tail_Number` LowCardinality(String),
`Flight_Number_Reporting_Airline` LowCardinality(String),
2021-02-23 12:08:01 +00:00
`OriginAirportID` Int32,
`OriginAirportSeqID` Int32,
`OriginCityMarketID` Int32,
`Origin` FixedString(5),
2022-05-29 03:26:13 +00:00
`OriginCityName` LowCardinality(String),
2021-02-23 12:08:01 +00:00
`OriginState` FixedString(2),
2022-05-29 03:26:13 +00:00
`OriginStateFips` FixedString(2),
`OriginStateName` LowCardinality(String),
2021-02-23 12:08:01 +00:00
`OriginWac` Int32,
`DestAirportID` Int32,
`DestAirportSeqID` Int32,
`DestCityMarketID` Int32,
`Dest` FixedString(5),
2022-05-29 03:26:13 +00:00
`DestCityName` LowCardinality(String),
2021-02-23 12:08:01 +00:00
`DestState` FixedString(2),
2022-05-29 03:26:13 +00:00
`DestStateFips` FixedString(2),
`DestStateName` LowCardinality(String),
2021-02-23 12:08:01 +00:00
`DestWac` Int32,
`CRSDepTime` Int32,
`DepTime` Int32,
`DepDelay` Int32,
`DepDelayMinutes` Int32,
`DepDel15` Int32,
2022-05-29 03:26:13 +00:00
`DepartureDelayGroups` LowCardinality(String),
`DepTimeBlk` LowCardinality(String),
2021-02-23 12:08:01 +00:00
`TaxiOut` Int32,
2022-05-29 03:26:13 +00:00
`WheelsOff` LowCardinality(String),
`WheelsOn` LowCardinality(String),
2021-02-23 12:08:01 +00:00
`TaxiIn` Int32,
`CRSArrTime` Int32,
`ArrTime` Int32,
`ArrDelay` Int32,
`ArrDelayMinutes` Int32,
`ArrDel15` Int32,
2022-05-29 03:26:13 +00:00
`ArrivalDelayGroups` LowCardinality(String),
`ArrTimeBlk` LowCardinality(String),
`Cancelled` Int8,
2021-02-23 12:08:01 +00:00
`CancellationCode` FixedString(1),
2022-05-29 03:26:13 +00:00
`Diverted` Int8,
2021-02-23 12:08:01 +00:00
`CRSElapsedTime` Int32,
`ActualElapsedTime` Int32,
2022-05-29 03:26:13 +00:00
`AirTime` Int32,
2021-02-23 12:08:01 +00:00
`Flights` Int32,
`Distance` Int32,
2022-05-29 03:26:13 +00:00
`DistanceGroup` Int8,
2021-02-23 12:08:01 +00:00
`CarrierDelay` Int32,
`WeatherDelay` Int32,
`NASDelay` Int32,
`SecurityDelay` Int32,
`LateAircraftDelay` Int32,
2022-05-29 03:26:13 +00:00
`FirstDepTime` Int16,
`TotalAddGTime` Int16,
`LongestAddGTime` Int16,
`DivAirportLandings` Int8,
`DivReachedDest` Int8,
`DivActualElapsedTime` Int16,
`DivArrDelay` Int16,
`DivDistance` Int16,
`Div1Airport` LowCardinality(String),
2021-02-23 12:08:01 +00:00
`Div1AirportID` Int32,
`Div1AirportSeqID` Int32,
2022-05-29 03:26:13 +00:00
`Div1WheelsOn` Int16,
`Div1TotalGTime` Int16,
`Div1LongestGTime` Int16,
`Div1WheelsOff` Int16,
`Div1TailNum` LowCardinality(String),
`Div2Airport` LowCardinality(String),
2021-02-23 12:08:01 +00:00
`Div2AirportID` Int32,
`Div2AirportSeqID` Int32,
2022-05-29 03:26:13 +00:00
`Div2WheelsOn` Int16,
`Div2TotalGTime` Int16,
`Div2LongestGTime` Int16,
`Div2WheelsOff` Int16,
`Div2TailNum` LowCardinality(String),
`Div3Airport` LowCardinality(String),
2021-02-23 12:08:01 +00:00
`Div3AirportID` Int32,
`Div3AirportSeqID` Int32,
2022-05-29 03:26:13 +00:00
`Div3WheelsOn` Int16,
`Div3TotalGTime` Int16,
`Div3LongestGTime` Int16,
`Div3WheelsOff` Int16,
`Div3TailNum` LowCardinality(String),
`Div4Airport` LowCardinality(String),
2021-02-23 12:08:01 +00:00
`Div4AirportID` Int32,
`Div4AirportSeqID` Int32,
2022-05-29 03:26:13 +00:00
`Div4WheelsOn` Int16,
`Div4TotalGTime` Int16,
`Div4LongestGTime` Int16,
`Div4WheelsOff` Int16,
`Div4TailNum` LowCardinality(String),
`Div5Airport` LowCardinality(String),
2021-02-23 12:08:01 +00:00
`Div5AirportID` Int32,
`Div5AirportSeqID` Int32,
2022-05-29 03:26:13 +00:00
`Div5WheelsOn` Int16,
`Div5TotalGTime` Int16,
`Div5LongestGTime` Int16,
`Div5WheelsOff` Int16,
`Div5TailNum` LowCardinality(String)
2022-05-29 03:31:15 +00:00
) ENGINE = MergeTree
2022-05-29 03:26:13 +00:00
ORDER BY (Year, Quarter, Month, DayofMonth, FlightDate, IATA_CODE_Reporting_Airline);
2017-12-28 15:13:23 +00:00
```
2022-05-29 03:43:50 +00:00
## Import from Raw Data {#import-from-raw-data}
Downloading data:
``` bash
wget --no-check-certificate --continue https://transtats.bts.gov/PREZIP/On_Time_Reporting_Carrier_On_Time_Performance_1987_present_{1987..2022}_{1..12}.zip
```
2021-02-28 20:27:01 +00:00
Loading data with multiple threads:
2017-12-28 15:13:23 +00:00
2020-03-20 10:10:48 +00:00
``` bash
2022-05-29 03:26:13 +00:00
ls -1 *.zip | xargs -I{} -P $(nproc) bash -c "echo {}; unzip -cq {} '* .csv' | sed 's/\.00//g' | clickhouse-client --input_format_csv_empty_as_default 1 --query='INSERT INTO ontime FORMAT CSVWithNames'"
2017-12-28 15:13:23 +00:00
```
2021-02-28 20:27:01 +00:00
(if you will have memory shortage or other issues on your server, remove the `-P $(nproc)` part)
2022-05-29 03:43:50 +00:00
## Import from a saved copy
Alternatively, you can import data from a saved copy by the following query:
```
INSERT INTO ontime SELECT * FROM s3('https://clickhouse-public-datasets.s3.amazonaws.com/ontime/csv_by_year/* .csv.gz', CSVWithNames) SETTINGS max_insert_threads = 40;
```
The snapshot was created on 2022-05-29.
2020-03-20 10:10:48 +00:00
## Queries {#queries}
2017-12-28 15:13:23 +00:00
Q0.
2020-03-20 10:10:48 +00:00
``` sql
2019-06-17 09:06:08 +00:00
SELECT avg(c1)
FROM
(
SELECT Year, Month, count(*) AS c1
FROM ontime
GROUP BY Year, Month
);
2017-12-28 15:13:23 +00:00
```
Q1. The number of flights per day from the year 2000 to 2008
2020-03-20 10:10:48 +00:00
``` sql
2019-06-17 09:06:08 +00:00
SELECT DayOfWeek, count(*) AS c
FROM ontime
WHERE Year>=2000 AND Year< =2008
GROUP BY DayOfWeek
ORDER BY c DESC;
2017-12-28 15:13:23 +00:00
```
Q2. The number of flights delayed by more than 10 minutes, grouped by the day of the week, for 2000-2008
2020-03-20 10:10:48 +00:00
``` sql
2019-06-17 09:06:08 +00:00
SELECT DayOfWeek, count(*) AS c
FROM ontime
WHERE DepDelay>10 AND Year>=2000 AND Year< =2008
GROUP BY DayOfWeek
ORDER BY c DESC;
2017-12-28 15:13:23 +00:00
```
2020-03-19 06:53:47 +00:00
Q3. The number of delays by the airport for 2000-2008
2017-12-28 15:13:23 +00:00
2020-03-20 10:10:48 +00:00
``` sql
2019-06-17 09:06:08 +00:00
SELECT Origin, count(*) AS c
FROM ontime
WHERE DepDelay>10 AND Year>=2000 AND Year< =2008
GROUP BY Origin
ORDER BY c DESC
LIMIT 10;
2017-12-28 15:13:23 +00:00
```
Q4. The number of delays by carrier for 2007
2020-03-20 10:10:48 +00:00
``` sql
2021-02-23 14:14:22 +00:00
SELECT IATA_CODE_Reporting_Airline AS Carrier, count(*)
2019-06-17 09:06:08 +00:00
FROM ontime
WHERE DepDelay>10 AND Year=2007
GROUP BY Carrier
ORDER BY count(*) DESC;
2017-12-28 15:13:23 +00:00
```
Q5. The percentage of delays by carrier for 2007
2020-03-20 10:10:48 +00:00
``` sql
2019-05-22 02:20:09 +00:00
SELECT Carrier, c, c2, c*100/c2 as c3
2017-12-28 15:13:23 +00:00
FROM
(
SELECT
2021-02-23 14:14:22 +00:00
IATA_CODE_Reporting_Airline AS Carrier,
2017-12-28 15:13:23 +00:00
count(*) AS c
FROM ontime
WHERE DepDelay>10
AND Year=2007
GROUP BY Carrier
2021-02-23 14:14:22 +00:00
) q
2020-03-17 18:10:23 +00:00
JOIN
2017-12-28 15:13:23 +00:00
(
SELECT
2021-02-23 14:14:22 +00:00
IATA_CODE_Reporting_Airline AS Carrier,
2017-12-28 15:13:23 +00:00
count(*) AS c2
FROM ontime
WHERE Year=2007
GROUP BY Carrier
2021-02-23 14:14:22 +00:00
) qq USING Carrier
2017-12-28 15:13:23 +00:00
ORDER BY c3 DESC;
```
Better version of the same query:
2020-03-20 10:10:48 +00:00
``` sql
2021-02-23 14:14:22 +00:00
SELECT IATA_CODE_Reporting_Airline AS Carrier, avg(DepDelay>10)*100 AS c3
2019-06-17 09:06:08 +00:00
FROM ontime
WHERE Year=2007
GROUP BY Carrier
2020-03-17 18:10:23 +00:00
ORDER BY c3 DESC
2017-12-28 15:13:23 +00:00
```
Q6. The previous request for a broader range of years, 2000-2008
2020-03-20 10:10:48 +00:00
``` sql
2019-05-22 02:20:09 +00:00
SELECT Carrier, c, c2, c*100/c2 as c3
2017-12-28 15:13:23 +00:00
FROM
(
SELECT
2021-02-23 14:14:22 +00:00
IATA_CODE_Reporting_Airline AS Carrier,
2017-12-28 15:13:23 +00:00
count(*) AS c
FROM ontime
WHERE DepDelay>10
2019-06-17 09:06:08 +00:00
AND Year>=2000 AND Year< =2008
2017-12-28 15:13:23 +00:00
GROUP BY Carrier
2021-02-23 14:14:22 +00:00
) q
2020-03-17 18:10:23 +00:00
JOIN
2017-12-28 15:13:23 +00:00
(
SELECT
2021-02-23 14:14:22 +00:00
IATA_CODE_Reporting_Airline AS Carrier,
2017-12-28 15:13:23 +00:00
count(*) AS c2
FROM ontime
2019-06-17 09:06:08 +00:00
WHERE Year>=2000 AND Year< =2008
2017-12-28 15:13:23 +00:00
GROUP BY Carrier
2021-02-23 14:14:22 +00:00
) qq USING Carrier
2017-12-28 15:13:23 +00:00
ORDER BY c3 DESC;
```
Better version of the same query:
2020-03-20 10:10:48 +00:00
``` sql
2021-02-23 14:14:22 +00:00
SELECT IATA_CODE_Reporting_Airline AS Carrier, avg(DepDelay>10)*100 AS c3
2019-06-17 09:06:08 +00:00
FROM ontime
WHERE Year>=2000 AND Year< =2008
GROUP BY Carrier
2020-03-17 18:10:23 +00:00
ORDER BY c3 DESC;
2017-12-28 15:13:23 +00:00
```
Q7. Percentage of flights delayed for more than 10 minutes, by year
2020-03-20 10:10:48 +00:00
``` sql
2017-12-28 15:13:23 +00:00
SELECT Year, c1/c2
FROM
(
select
Year,
2019-05-22 02:20:09 +00:00
count(*)*100 as c1
2017-12-28 15:13:23 +00:00
from ontime
WHERE DepDelay>10
GROUP BY Year
2021-02-23 14:14:22 +00:00
) q
2020-03-17 18:10:23 +00:00
JOIN
2017-12-28 15:13:23 +00:00
(
select
Year,
count(*) as c2
from ontime
GROUP BY Year
2021-02-23 14:14:22 +00:00
) qq USING (Year)
2019-06-17 09:06:08 +00:00
ORDER BY Year;
2017-12-28 15:13:23 +00:00
```
Better version of the same query:
2020-03-20 10:10:48 +00:00
``` sql
2020-03-17 18:10:23 +00:00
SELECT Year, avg(DepDelay>10)*100
2019-06-17 09:06:08 +00:00
FROM ontime
GROUP BY Year
ORDER BY Year;
2017-12-28 15:13:23 +00:00
```
Q8. The most popular destinations by the number of directly connected cities for various year ranges
2020-03-20 10:10:48 +00:00
``` sql
SELECT DestCityName, uniqExact(OriginCityName) AS u
2019-10-23 15:32:42 +00:00
FROM ontime
WHERE Year >= 2000 and Year < = 2010
2019-06-17 09:06:08 +00:00
GROUP BY DestCityName
2019-10-23 15:32:42 +00:00
ORDER BY u DESC LIMIT 10;
2017-12-28 15:13:23 +00:00
```
Q9.
2020-03-20 10:10:48 +00:00
``` sql
2019-06-17 09:06:08 +00:00
SELECT Year, count(*) AS c1
FROM ontime
GROUP BY Year;
2017-12-28 15:13:23 +00:00
```
Q10.
2020-03-20 10:10:48 +00:00
``` sql
2019-06-17 09:06:08 +00:00
SELECT
2021-02-23 14:14:22 +00:00
min(Year), max(Year), IATA_CODE_Reporting_Airline AS Carrier, count(*) AS cnt,
2019-06-17 09:06:08 +00:00
sum(ArrDelayMinutes>30) AS flights_delayed,
round(sum(ArrDelayMinutes>30)/count(*),2) AS rate
2017-12-28 15:13:23 +00:00
FROM ontime
WHERE
2019-06-17 09:06:08 +00:00
DayOfWeek NOT IN (6,7) AND OriginState NOT IN ('AK', 'HI', 'PR', 'VI')
AND DestState NOT IN ('AK', 'HI', 'PR', 'VI')
AND FlightDate < '2010-01-01'
2017-12-28 15:13:23 +00:00
GROUP by Carrier
2019-06-17 09:06:08 +00:00
HAVING cnt>100000 and max(Year)>1990
2017-12-28 15:13:23 +00:00
ORDER by rate DESC
LIMIT 1000;
```
Bonus:
2020-03-20 10:10:48 +00:00
``` sql
2019-06-17 09:06:08 +00:00
SELECT avg(cnt)
FROM
(
SELECT Year,Month,count(*) AS cnt
FROM ontime
WHERE DepDel15=1
GROUP BY Year,Month
);
2017-12-28 15:13:23 +00:00
2019-06-17 09:06:08 +00:00
SELECT avg(c1) FROM
(
SELECT Year,Month,count(*) AS c1
FROM ontime
GROUP BY Year,Month
);
2017-12-28 15:13:23 +00:00
2019-06-17 09:06:08 +00:00
SELECT DestCityName, uniqExact(OriginCityName) AS u
FROM ontime
GROUP BY DestCityName
ORDER BY u DESC
LIMIT 10;
2017-12-28 15:13:23 +00:00
2019-06-17 09:06:08 +00:00
SELECT OriginCityName, DestCityName, count() AS c
FROM ontime
GROUP BY OriginCityName, DestCityName
ORDER BY c DESC
LIMIT 10;
2017-12-28 15:13:23 +00:00
2019-06-17 09:06:08 +00:00
SELECT OriginCityName, count() AS c
FROM ontime
GROUP BY OriginCityName
ORDER BY c DESC
LIMIT 10;
2017-12-28 15:13:23 +00:00
```
2018-07-30 16:34:55 +00:00
2022-05-27 23:18:07 +00:00
You can also play with the data in Playground, [example ](https://play.clickhouse.com/play?user=play#U0VMRUNUIERheU9mV2VlaywgY291bnQoKikgQVMgYwpGUk9NIG9udGltZQpXSEVSRSBZZWFyPj0yMDAwIEFORCBZZWFyPD0yMDA4CkdST1VQIEJZIERheU9mV2VlawpPUkRFUiBCWSBjIERFU0M7Cg== ).
2021-01-06 20:27:00 +00:00
2018-09-04 11:18:59 +00:00
This performance test was created by Vadim Tkachenko. See:
2018-07-30 16:34:55 +00:00
2020-03-21 04:11:51 +00:00
- https://www.percona.com/blog/2009/10/02/analyzing-air-traffic-performance-with-infobright-and-monetdb/
- https://www.percona.com/blog/2009/10/26/air-traffic-queries-in-luciddb/
- https://www.percona.com/blog/2009/11/02/air-traffic-queries-in-infinidb-early-alpha/
- https://www.percona.com/blog/2014/04/21/using-apache-hadoop-and-impala-together-with-mysql-for-data-analysis/
- https://www.percona.com/blog/2016/01/07/apache-spark-with-air-ontime-performance-data/
- http://nickmakos.blogspot.ru/2012/08/analyzing-air-traffic-performance-with.html
2018-10-16 10:47:17 +00:00
2021-09-19 20:05:54 +00:00
[Original article ](https://clickhouse.com/docs/en/getting_started/example_datasets/ontime/ ) <!--hide-->