Skip to main content

Analyzing the NYC Restaurant Inspections Dataset

93MB · 209K rows

ON THIS PAGE

New York City's Department of Health publishes the results of every restaurant inspection. This tutorial covers the schema, loading the data into Firebolt, and sample SQL queries for extracting insights from the records.

## Dataset schema

The dataset contains 27 columns:

Column NameData TypeDescription
camisINTEGERUnique restaurant ID
dbaTEXTBusiness name ("doing business as")
boroTEXTBorough
buildingTEXTBuilding number
streetTEXTStreet
zipcodeTEXTZIP code
phoneTEXTPhone number
cuisine_descriptionTEXTCuisine type
inspection_dateTEXTDate of inspection
actionTEXTAction taken as a result of inspection
violation_codeTEXTViolation code
violation_descriptionTEXTViolation description
critical_flagTEXTWhether the violation was critical
scoreNUMERICInspection score
gradeTEXTLetter grade
grade_dateDATEDate the grade was issued
record_dateDATEDate the record was created
inspection_typeTEXTType of inspection
latitudeNUMERICLatitude
longitudeNUMERICLongitude
community_boardTEXTCommunity board
council_districtTEXTCouncil district
census_tractTEXTCensus tract
binTEXTBuilding identification number
bblTEXTBorough-block-lot identifier
ntaTEXTNeighborhood tabulation area
location_point1TEXTLocation point

## Loading data into Firebolt

There are two ways to load the data.

### Option 1: COPY FROM

Let Firebolt infer the schema and create the table automatically:

COPY INTO nyc_restaurant_inspections FROM 's3://firebolt-sample-datasets-public-us-east-1/nyc_sample_datasets/nyc_restaurant_inspections/parquet/'WITH PATTERN="*.parquet" AUTO_CREATE=TRUE TYPE=PARQUET;

### Option 2: External table

Create an external table over the Parquet files in S3:

CREATE EXTERNAL TABLE ex_nyc_restaurant_inspections (  camis INTEGER,  dba TEXT,  boro TEXT,  building TEXT,  street TEXT,  zipcode TEXT,  phone TEXT,  cuisine_description TEXT,  inspection_date TEXT,  action TEXT,  violation_code TEXT,  violation_description TEXT,  critical_flag TEXT,  score NUMERIC,  grade TEXT,  grade_date DATE,  record_date DATE,  inspection_type TEXT,  latitude NUMERIC,  longitude NUMERIC,  community_board TEXT,  council_district TEXT,  census_tract TEXT,  bin TEXT,  bbl TEXT,  nta TEXT,  location_point1 TEXT) URL = 's3://firebolt-sample-datasets-public-us-east-1/nyc_sample_datasets/nyc_restaurant_inspections/parquet/'OBJECT_PATTERN = '*.parquet'TYPE = (PARQUET);

Create the internal table:

CREATE TABLE nyc_restaurant_inspections(  camis INTEGER,  dba TEXT,  boro TEXT,  building TEXT,  street TEXT,  zipcode TEXT,  phone TEXT,  cuisine_description TEXT,  inspection_date TEXT,  action TEXT,  violation_code TEXT,  violation_description TEXT,  critical_flag TEXT,  score NUMERIC,  grade TEXT,  grade_date DATE,  record_date DATE,  inspection_type TEXT,  latitude NUMERIC,  longitude NUMERIC,  community_board TEXT,  council_district TEXT,  census_tract TEXT,  bin TEXT,  bbl TEXT,  nta TEXT,  location_point1 TEXT);

Load the data from the external table:

INSERT INTO  nyc_restaurant_inspectionsSELECT  camis,  dba,  boro,  building,  street,  zipcode,  phone,  cuisine_description,  inspection_date,  action,  violation_code,  violation_description,  critical_flag,  score,  grade,  grade_date,  record_date,  inspection_type,  latitude,  longitude,  community_board,  council_district,  census_tract,  bin,  bbl,  nta,  location_point1FROM  ex_nyc_restaurant_inspections;

## Sample SQL queries for analysis

### Total inspections by borough

SELECT boro, COUNT(*) as total_inspectionsFROM nyc_restaurant_inspectionsGROUP BY boroORDER BY total_inspections DESC;

### Top 10 most common cuisine types

SELECT cuisine_description, COUNT(*) as countFROM nyc_restaurant_inspectionsGROUP BY cuisine_descriptionORDER BY count DESCLIMIT 10;

### Top 10 highest-scoring restaurants

SELECT dba, boro, max(score) as scoreFROM nyc_restaurant_inspectionsGROUP BY ALLORDER BY score DESCLIMIT 10;

### Violations by critical flag

SELECT critical_flag, COUNT(*) as countFROM nyc_restaurant_inspectionsGROUP BY critical_flag;

### Average inspection score by cuisine type (top 10)

SELECT cuisine_description, AVG(score) as avg_scoreFROM nyc_restaurant_inspectionsGROUP BY cuisine_descriptionORDER BY avg_score DESCLIMIT 10;

Customize these queries based on your specific analytical objectives.