Query the Data Delivery Network
Query the DDNThe 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
"facility_id", -- ID number of the facility selling consumable goods.
"record_id",
"serial_number", -- ID number of the licensed inspection. Corresponds to "InspectionID" in CDPHE database.
"service_desc", -- Type of inspection. Corresponds to "InspectionType" in CDPHE database.
"pe", -- Building Capacity.
"pe_desc", -- Building Capacity.
"category", -- Risk category.
"description", -- Type of business. Corresponds to "FacilityType" in CDPHE database.
"county", -- County in which inspected business operates.
"agency", -- Agency under which operating business is inspected. Corresponds to "Jurisdiction" in CDPHE database.
"program_identifier", -- Name of facility selling consumable goods. Corresponds to "FacilityName" in CDPHE database.
"site_address", -- Street address of facility selling consumable goods. Corresponds to "FacilityStreetAddress" in CDPHE database.
"city", -- City of facility selling consumable goods. Corresponds to "FacilityCity" in CDPHE database.
"st", -- State of facility selling consumable goods. Corresponds to "FacilityState" in CDPHE database.
"zip", -- Zip of facility selling consumable goods. Corresponds to "FacilityZip" in CDPHE database.
"gis_latitude", -- Latitude of facility selling consumable goods.
"gis_longitude", -- Longitude of facility selling consumable goods.
"activity_date", -- Date of facility inspection. Corresponds to "InspectionDate" in CDPHE database.
"fc01", -- Person in charge present, demonstrates knowledge, and performs duties
"fc02", -- Certified Food Protection Manager
"fc03", -- Management, food employee and conditional employee; knowledge, responsibilities and reporting
"fc04", -- Proper use of restriction and exclusion
"fc05", -- Procedures for responding to vomiting and diarrheal events
"fc06", -- Proper eating, tasting, drinking, or tobacco use
"fc07", -- No discharge from eyes, nose, and mouth
"fc08", -- Hands clean & properly washed
"fc09", -- No bare hand contact with RTE food or a pre-approved alternative procedure properly allowed
"fc10", -- Adequate handwashing sinks properly supplied and accessible
"fc11", -- Food obtained from approved source
"fc12", -- Food received at proper temperature
"fc13", -- Food in good condition, safe, & unadulterated
"fc14", -- Required records available: shellstock tags, parasite destruction
"fc15", -- Food separated and protected
"fc16", -- Food contact surfaces; cleaned & sanitized
"fc17", -- Proper disposition of returned, previously served, reconditioned & unsafe food
"fc18", -- Proper cooking time & temperatures
"fc19", -- Proper reheating procedures for hot holding
"fc20", -- Proper cooling time and temperature
"fc21", -- Proper hot holding temperatures
"fc22", -- Proper cold holding temperatures
"fc23", -- Proper date marking and disposition
"fc24", -- Time as a Public Health Control; procedures & records
"fc25", -- Consumer advisory provided for raw/undercooked food
"fc26", -- Pasteurized foods used; prohibited foods not offered
"fc27", -- Food additives: approved & Properly used
"fc28", -- Toxic substances properly identified, stored & used
"fc29", -- Compliance with variance / specialized process / HACCP
"total_foodborne_illness_risk", -- Total foodborne illness risk violations for inspection codes FC01 - FC29
"fc30", -- Pasteurized eggs used where required
"fc31", -- Water & ice from approved source
"fc32", -- Variance obtained for specialized processing methods
"fc33", -- Proper cooling methods used; adequate equipment for temperature control
"fc34", -- Plant food properly cooked for hot holding
"fc35", -- Approved thawing methods used
"fc36", -- Thermometer provided & accurate
"fc37", -- Food properly labeled; original container
"fc38", -- Insects, rodents, & animals not present
"fc39", -- Contamination prevented during food preparation, storage & display
"fc40", -- Personal cleanliness
"fc41", -- Wiping Cloths; properly used & stored
"fc42", -- Washing fruits & vegetables
"fc43", -- In-use utensils: properly stored
"fc44", -- Utensils, equipment & linens: properly stored, dried, & handled
"fc45", -- Single-use / single-service articles: properly stored & used
"fc46", -- Gloves used properly
"fc47", -- Food & non-food contact surfaces cleanable, properly designed, constructed, & used
"fc48", -- Warewashing facilities: installed, maintained, & used; test strips
"fc49", -- Non-food contact surfaces clean
"fc50", -- Hot & cold water available; adequate pressure
"fc51", -- Plumbing installed; proper backflow devices
"fc52", -- Sewage & waste water properly disposed
"fc53", -- Toilet facilities: properly constructed, supplied, & cleaned
"fc54", -- Garbage & refuse properly disposed; facilities maintained
"fc55", -- Physical facilities installed, maintained, & clean
"fc56", -- Adequate ventilation & lighting; designated areas used
"total_good_retail_practices" -- Total good retail practices violations for inspection codes FC30 - FC56
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.
Query Your Local Engine
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; sgr
can manage the image, container and volume for you.
There are a few ways to ingest data into the local engine.
For external repositories, 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 (like this repository), where the author has pushed Splitgraph Images to the repository, you can "clone" and/or "checkout" the data using sgr clone
and sgr checkout
.
Cloning Data
Because colorado-gov/restaurant-inspections-in-tricounty-colorado-869n-zj3f:latest
is a Splitgraph Image, you can clone the data from Spltgraph Cloud to your local engine, where you can query it like any other Postgres database, using any of your existing tools.
First, install Splitgraph if you haven't already.
Clone the metadata with sgr clone
This will be quick, and does not download the actual data.
sgr clone colorado-gov/restaurant-inspections-in-tricounty-colorado-869n-zj3f
Checkout the data
Once you've cloned the data, you need to "checkout" the tag that you want. For example, to checkout the latest
tag:
sgr checkout colorado-gov/restaurant-inspections-in-tricounty-colorado-869n-zj3f:latest
This will download all the objects for the latest
tag of colorado-gov/restaurant-inspections-in-tricounty-colorado-869n-zj3f
and load them into the Splitgraph Engine. Depending on your connection speed and the size of the data, you will need to wait for the checkout to complete. Once it's complete, you will be able to query the data like you would any other Postgres database.
Alternatively, use "layered checkout" to avoid downloading all the data
The data in colorado-gov/restaurant-inspections-in-tricounty-colorado-869n-zj3f:latest
is 0 bytes. If this is too big to download all at once, or perhaps you only need to query a subset of it, you can use a layered checkout.:
sgr checkout --layered colorado-gov/restaurant-inspections-in-tricounty-colorado-869n-zj3f:latest
This will not download all the data, but it will create a schema comprised of foreign tables, that you can query as you would any other data. Splitgraph will lazily download the required objects as you query the data. In some cases, this might be faster or more efficient than a regular checkout.
Read the layered querying documentation to learn about when and why you might want to use layered queries.
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.