Skip to content
Data Labs: SQL Analytics and a Graph Database

Data Labs: SQL Analytics and a Graph Database

Two labs treat the same kind of question, where things go and how often, with two different data models: tables and graphs.

DuckDBSQLNeo4jCypherpandas

100,000

flights queried

631

average flight distance

70

bike-share stations in the graph

354,000+

trips as relationships

Problem

Understanding the challenge and user needs

Flight records and bike trips both describe movement between places. A table answers how many; a graph answers what connects to what.

Approach

Strategy and methods used to address the problem

DuckDB joined about 100,000 flights from January 2008 to a reference table of more than 82,000 airport codes and to country data with plain SQL. Neo4j loaded 70 bike-share stations and more than 354,000 trips as nodes and relationships, queried with Cypher.

Terminal output of DuckDB queries listing the busiest cities and flights by distance band (opens in a new tab)
The DuckDB script's output: SQL over CSV and JSON files with no database server to run.

Final Solution

The final design and outcome

The same movement data supports aggregate reporting in SQL and route and connection questions in the graph.

Busiest origin cities, January 2008

CityFlights
Las Vegas13,551
Chicago12,588
Phoenix11,081
Baltimore9,269
Oakland7,865
Houston7,745
Dallas7,119
Los Angeles6,751
San Diego6,671
Orlando6,568

Flights by distance band

DistanceFlights
Under 25012,006
250 to 49942,644
500 to 99927,724
1,000 to 1,49911,403
1,500 to 1,9995,019
2,000 and over1,204

Distances run from 66 to 2,363, in the dataset's own units.

Busiest routes

RouteFlightsDistance
Houston Hobby to Dallas Love Field762239
Dallas Love Field to Houston Hobby752239
Oakland to Los Angeles562337
Los Angeles to Oakland554337
Las Vegas to Phoenix516256

Impact & Validation

Results, learnings, and outcomes

Choosing the data model to fit the question, rather than the tool at hand, shapes every later design decision.