colorado-gov/restaurant-inspections-in-tricounty-colorado-869n-zj3f
Icon for Socrata external plugin

Query the Data Delivery Network

Query the DDN

The easiest way to query any data on Splitgraph is via the "Data Delivery Network" (DDN). The DDN is a single endpoint that speaks the PostgreSQL wire protocol. Any Splitgraph user can connect to it at data.splitgraph.com:5432 and query any version of over 40,000 datasets that are hosted or proxied by Splitgraph.

For example, you can query the restaurant_inspections_in_tricounty_colorado table in this repository, by referencing it like:

"colorado-gov/restaurant-inspections-in-tricounty-colorado-869n-zj3f:latest"."restaurant_inspections_in_tricounty_colorado"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "total_foodborne_illness_risk", -- Total foodborne illness risk violations for inspection codes FC01 - FC29
    "activity_date", -- Date of facility inspection. Corresponds to "InspectionDate" in CDPHE database.
    "site_address", -- Street address of facility selling consumable goods. Corresponds to "FacilityStreetAddress" in CDPHE database.
    "serial_number", -- ID number of the licensed inspection. Corresponds to "InspectionID" in CDPHE database.
    "record_id",
    "total_good_retail_practices", -- Total good retail practices violations for inspection codes FC30 - FC56
    "fc09", -- No bare hand contact with RTE food or a pre-approved alternative procedure properly allowed
    "pe_desc", -- Building Capacity.
    "fc40", -- Personal cleanliness
    "gis_longitude", -- Longitude of facility selling consumable goods.
    "gis_latitude", -- Latitude of facility selling consumable goods.
    "program_identifier", -- Name of facility selling consumable goods. Corresponds to "FacilityName" in CDPHE database.
    "facility_id", -- ID number of the facility selling consumable goods.
    "zip", -- Zip of facility selling consumable goods. Corresponds to "FacilityZip" in CDPHE database.
    "fc12", -- Food received at proper temperature
    "city", -- City of facility selling consumable goods. Corresponds to "FacilityCity" in CDPHE database.
    "fc36", -- Thermometer provided & accurate
    "fc55", -- Physical facilities installed, maintained, & clean
    "fc02", -- Certified Food Protection Manager
    "fc44", -- Utensils, equipment & linens: properly stored, dried, & handled
    "st", -- State of facility selling consumable goods. Corresponds to "FacilityState" in CDPHE database.
    "fc10", -- Adequate handwashing sinks properly supplied and accessible
    "pe", -- Building Capacity.
    "fc20", -- Proper cooling time and temperature
    "fc16", -- Food contact surfaces; cleaned & sanitized
    "fc52", -- Sewage & waste water properly disposed
    "fc15", -- Food separated and protected
    "fc56", -- Adequate ventilation & lighting; designated areas used
    "fc54", -- Garbage & refuse properly disposed; facilities maintained
    "fc53", -- Toilet facilities: properly constructed, supplied, & cleaned
    "fc51", -- Plumbing installed; proper backflow devices
    "fc50", -- Hot & cold water available; adequate pressure
    "fc49", -- Non-food contact surfaces clean
    "fc48", -- Warewashing facilities: installed, maintained, & used; test strips
    "fc47", -- Food & non-food contact surfaces cleanable, properly designed, constructed, & used 
    "fc46", -- Gloves used properly
    "fc45", -- Single-use / single-service articles: properly stored & used
    "fc43", -- In-use utensils: properly stored
    "fc42", -- Washing fruits & vegetables
    "fc41", -- Wiping Cloths; properly used & stored
    "fc39", -- Contamination prevented during food preparation, storage & display
    "fc38", -- Insects, rodents, & animals not present
    "fc37", -- Food properly labeled; original container
    "fc35", -- Approved thawing methods used
    "fc34", -- Plant food properly cooked for hot holding
    "fc33", -- Proper cooling methods used; adequate equipment for temperature control
    "fc32", -- Variance obtained for specialized processing methods
    "fc31", -- Water & ice from approved source
    "fc30", -- Pasteurized eggs used where required
    "fc29", -- Compliance with variance / specialized process / HACCP
    "fc28", -- Toxic substances properly identified, stored & used
    "fc27", -- Food additives: approved & Properly used
    "fc26", -- Pasteurized foods used; prohibited foods not offered
    "fc25", -- Consumer advisory provided for raw/undercooked food
    "fc24", -- Time as a Public Health Control; procedures & records
    "fc23", -- Proper date marking and disposition
    "fc22", -- Proper cold holding temperatures
    "fc21", -- Proper hot holding temperatures
    "fc19", -- Proper reheating procedures for hot holding
    "fc18", -- Proper cooking time & temperatures
    "fc17", -- Proper disposition of returned, previously served, reconditioned & unsafe food
    "fc14", -- Required records available: shellstock tags, parasite destruction
    "fc13", -- Food in good condition, safe, & unadulterated 
    "fc11", -- Food obtained from approved source
    "fc08", -- Hands clean & properly washed
    "fc07", -- No discharge from eyes, nose, and mouth
    "fc06", -- Proper eating, tasting, drinking, or tobacco use
    "fc04", -- Proper use of restriction and exclusion
    "fc03", -- Management, food employee and conditional employee; knowledge, responsibilities and reporting
    "fc01", -- Person in charge present, demonstrates knowledge, and performs duties
    "agency", -- Agency under which operating business is inspected. Corresponds to "Jurisdiction" in CDPHE database. 
    "county", -- County in which inspected business operates.
    "description", -- Type of business. Corresponds to "FacilityType" in CDPHE database.
    "category", -- Risk category.
    "service_desc", -- Type of inspection. Corresponds to "InspectionType" in CDPHE database.
    "fc05" -- Procedures for responding to vomiting and diarrheal events
FROM
    "colorado-gov/restaurant-inspections-in-tricounty-colorado-869n-zj3f:latest"."restaurant_inspections_in_tricounty_colorado"
LIMIT 100;

Connecting to the DDN is easy. All you need is an existing SQL client that can connect to Postgres. As long as you have a SQL client ready, you'll be able to query colorado-gov/restaurant-inspections-in-tricounty-colorado-869n-zj3f with SQL in under 60 seconds.

This repository is an "external" repository. That means it's hosted elsewhere, in this case at data.colorado.gov. When you querycolorado-gov/restaurant-inspections-in-tricounty-colorado-869n-zj3f:latest on the DDN, we "mount" the repository using the socrata mount handler. The mount handler proxies your SQL query to the upstream data source, translating it from SQL to the relevant language (in this case SoQL).

We also cache query responses on the DDN, but we run the DDN on multiple nodes so a CACHE_HIT is only guaranteed for subsequent queries that land on the same node.

Query Your Local Engine

Install Splitgraph Locally
bash -c "$(curl -sL https://github.com/splitgraph/splitgraph/releases/latest/download/install.sh)"
 

Read the installation docs.

Splitgraph Cloud is built around Splitgraph Core (GitHub), which includes a local Splitgraph Engine packaged as a Docker image. Splitgraph Cloud is basically a scaled-up version of that local Engine. When you query the Data Delivery Network or the REST API, we mount the relevant datasets in an Engine on our servers and execute your query on it.

It's possible to run this engine locally. You'll need a Mac, Windows or Linux system to install sgr, and a Docker installation to run the engine. You don't need to know how to actually use Docker; sgrcan manage the image, container and volume for you.

There are a few ways to ingest data into the local engine.

For external repositories (like this repository), the Splitgraph Engine can "mount" upstream data sources by using sgr mount. This feature is built around Postgres Foreign Data Wrappers (FDW). You can write custom "mount handlers" for any upstream data source. For an example, we blogged about making a custom mount handler for HackerNews stories.

For hosted datasets, where the author has pushed Splitgraph Images to the repository, you can "clone" and/or "checkout" the data using sgr cloneand sgr checkout.

Mounting Data

This repository is an external repository. It's not hosted by Splitgraph. It is hosted by data.colorado.gov, and Splitgraph indexes it. This means it is not an actual Splitgraph image, so you cannot use sgr clone to get the data. Instead, you can use the socrata adapter with the sgr mount command. Then, if you want, you can import the data and turn it into a Splitgraph image that others can clone.

First, install Splitgraph if you haven't already.

Mount the table with sgr mount

sgr mount socrata \
  "colorado-gov/restaurant-inspections-in-tricounty-colorado-869n-zj3f" \
  --handler-options '{
    "domain": "data.colorado.gov",
    "tables": {
        "restaurant_inspections_in_tricounty_colorado": "869n-zj3f"
    }
}'

That's it! Now you can query the data in the mounted table like any other Postgres table.

Query the data with your existing tools

Once you've loaded the data into your local Splitgraph engine, you can query it with any of your existing tools. As far as they're concerned, colorado-gov/restaurant-inspections-in-tricounty-colorado-869n-zj3f is just another Postgres schema.