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_and_food_establishment_inspections
table in this repository, by referencing it like:
"dallasopendata/restaurant-and-food-establishment-inspections-dri5-wcct:latest"."restaurant_and_food_establishment_inspections"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"violation24_memo", -- This field is used for any additional comments about the enforcement action.
"violation23_description", -- A brief description of the violation.
"violation19_memo", -- This field is used for any additional comments about the enforcement action.
"violation19_points", -- The amount of points assigned to this violation.
"violation16_memo", -- This field is used for any additional comments about the enforcement action.
"violation14_description", -- A brief description of the violation.
"violation11_memo", -- This field is used for any additional comments about the enforcement action.
"violation8_memo", -- This field is used for any additional comments about the enforcement action.
"violation8_description", -- A brief description of the violation.
"violation6_memo", -- This field is used for any additional comments about the enforcement action.
"violation4_memo", -- This field is used for any additional comments about the enforcement action.
"violation3_points", -- The amount of points assigned to this violation.
"violation2_points", -- The amount of points assigned to this violation.
"violation2_description", -- A brief description of the violation.
"violation1_memo", -- This field is used for any additional comments about the enforcement action.
"zip", -- Zip Code of the facility's address.
"street_number", -- Street number for the address of the facility.
"insp_date", -- Date the inspection for the facility was performed.
"violation4_text", -- Field used to describe the type of violation associated with the enforcement action.
"violation10_description", -- A brief description of the violation.
"violation8_points", -- The amount of points assigned to this violation.
"violation3_text", -- Field used to describe the type of violation associated with the enforcement action.
"violation24_text", -- Field used to describe the type of violation associated with the enforcement action.
"violation24_description", -- A brief description of the violation.
"violation22_memo", -- This field is used for any additional comments about the enforcement action.
"violation20_description", -- A brief description of the violation.
"violation19_description", -- A brief description of the violation.
"violation18_points", -- The amount of points assigned to this violation.
"violation17_description", -- A brief description of the violation.
"violation14_memo", -- This field is used for any additional comments about the enforcement action.
"violation14_text", -- Field used to describe the type of violation associated with the enforcement action.
"violation12_points", -- The amount of points assigned to this violation.
"violation11_text", -- Field used to describe the type of violation associated with the enforcement action.
"violation10_memo", -- This field is used for any additional comments about the enforcement action.
"violation9_memo", -- This field is used for any additional comments about the enforcement action.
"violation9_description", -- A brief description of the violation.
"violation7_description", -- A brief description of the violation.
"violation5_memo", -- This field is used for any additional comments about the enforcement action.
"violation4_points", -- The amount of points assigned to this violation.
"violation4_description", -- A brief description of the violation.
"violation3_description", -- A brief description of the violation.
"violation2_memo", -- This field is used for any additional comments about the enforcement action.
"violation1_points", -- The amount of points assigned to this violation.
"street_unit", -- Unit number or apartment number for the address of the facility.
"street_type", -- Street type for the address of the facility. For example, AVE, LN, ST, etc.
"street_name", -- Street name for the address of the facility.
"program_identifier", -- The Program Identifier allows users to add a description for a General Health Program record that identifies one general health program from another. For example, two programs (restaurants) at one facility can have the same Program/Element code (1600 - Food). The PROGRAM_IDENTIFIER field allows users to add a description for differentiating the two (The Moonlight Room and The Laguna Lounge).
"lat_long_city",
"lat_long_address",
"violation25_memo", -- This field is used for any additional comments about the enforcement action.
"violation23_memo", -- This field is used for any additional comments about the enforcement action.
"violation21_memo", -- This field is used for any additional comments about the enforcement action.
"violation20_memo", -- This field is used for any additional comments about the enforcement action.
"violation18_description", -- A brief description of the violation.
"violation17_text", -- Field used to describe the type of violation associated with the enforcement action.
"violation16_text", -- Field used to describe the type of violation associated with the enforcement action.
"violation16_description", -- A brief description of the violation.
"violation15_description", -- A brief description of the violation.
"violation14_points", -- The amount of points assigned to this violation.
"violation13_points", -- The amount of points assigned to this violation.
"violation12_text", -- Field used to describe the type of violation associated with the enforcement action.
"violation11_points", -- The amount of points assigned to this violation.
"violation5_description", -- A brief description of the violation.
"site_address", -- Full street address of the facility.
"inspection_year", -- Added column to improve visualization of inspections for specific fiscal years
"violation22_description", -- A brief description of the violation.
"violation21_points", -- The amount of points assigned to this violation.
"violation15_memo", -- This field is used for any additional comments about the enforcement action.
"violation15_points", -- The amount of points assigned to this violation.
"violation13_description", -- A brief description of the violation.
"violation12_memo", -- This field is used for any additional comments about the enforcement action.
"violation12_description", -- A brief description of the violation.
"violation11_description", -- A brief description of the violation.
"violation7_memo", -- This field is used for any additional comments about the enforcement action.
"violation6_description", -- A brief description of the violation.
"violation3_memo", -- This field is used for any additional comments about the enforcement action.
"violation1_description", -- A brief description of the violation.
"violation25_text", -- Field used to describe the type of violation associated with the enforcement action.
"violation23_points", -- The amount of points assigned to this violation.
"violation21_text", -- Field used to describe the type of violation associated with the enforcement action.
"violation18_memo", -- This field is used for any additional comments about the enforcement action.
"violation17_memo", -- This field is used for any additional comments about the enforcement action.
"violation16_points", -- The amount of points assigned to this violation.
"violation13_memo", -- This field is used for any additional comments about the enforcement action.
"violation13_text", -- Field used to describe the type of violation associated with the enforcement action.
"score", -- The aggregate score from the inspection violations. Please note not every violation will reflect a point deduction as establishments are allowed to correct violations during the inspection process, and therefore no reduction in the overall score is reflected for the violation.
"violation25_description", -- A brief description of the violation.
"violation23_text", -- Field used to describe the type of violation associated with the enforcement action.
"violation10_points", -- The amount of points assigned to this violation.
"lat_long", -- Denotes a location point on a longitude line (perpendicular to the equator) and latitude line (parallel to the equator)
"violation21_description", -- A brief description of the violation.
"violation20_text", -- Field used to describe the type of violation associated with the enforcement action.
"violation7_points", -- The amount of points assigned to this violation.
"violation6_points", -- The amount of points assigned to this violation.
"violation5_text", -- Field used to describe the type of violation associated with the enforcement action.
"type", -- Code indicating the inspection type, such as Routine, Follow-up, Complaint, Temporary and Mobile. • Routine Inspections – are conducted at least once every six months • Follow-up Inspections – are conducted as a result of poor sanitation issues, low scores • Complaints Inspections – General Sanitation/Hygienic Practices /Illness Investigation, Smoking and Other • Temporary – the City of Dallas Office of Special Events provides a listing of public events being held involving food and the Consumer Health Division provides guidance and inspects • Mobile – the various mobile food units are inspected annually with random inspections conducted during the year
"violation1_text", -- Field used to describe the type of violation associated with the enforcement action.
"violation2_text", -- Field used to describe the type of violation associated with the enforcement action.
"street_direction", -- Street direction for the address of the facility. For example, N, W, S, etc.
"violation25_points", -- The amount of points assigned to this violation.
"violation8_text", -- Field used to describe the type of violation associated with the enforcement action.
"lat_long_zip",
"month", -- Added column to improve visualization of inspections by month
"violation24_points", -- The amount of points assigned to this violation.
"violation22_text", -- Field used to describe the type of violation associated with the enforcement action.
"violation22_points", -- The amount of points assigned to this violation.
"violation20_points", -- The amount of points assigned to this violation.
"violation9_points", -- The amount of points assigned to this violation.
"violation5_points", -- The amount of points assigned to this violation.
"violation17_points", -- The amount of points assigned to this violation.
"violation9_text", -- Field used to describe the type of violation associated with the enforcement action.
"violation6_text", -- Field used to describe the type of violation associated with the enforcement action.
"violation18_text", -- Field used to describe the type of violation associated with the enforcement action.
"violation10_text", -- Field used to describe the type of violation associated with the enforcement action.
"violation19_text", -- Field used to describe the type of violation associated with the enforcement action.
"violation7_text", -- Field used to describe the type of violation associated with the enforcement action.
":@computed_region_2f7u_b5gs",
":@computed_region_sjyw_rtbm",
"lat_long_state",
"violation15_text" -- Field used to describe the type of violation associated with the enforcement action.
FROM
"dallasopendata/restaurant-and-food-establishment-inspections-dri5-wcct:latest"."restaurant_and_food_establishment_inspections"
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 dallasopendata/restaurant-and-food-establishment-inspections-dri5-wcct
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 dallasopendata/restaurant-and-food-establishment-inspections-dri5-wcct: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 dallasopendata/restaurant-and-food-establishment-inspections-dri5-wcct
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 dallasopendata/restaurant-and-food-establishment-inspections-dri5-wcct:latest
This will download all the objects for the latest
tag of dallasopendata/restaurant-and-food-establishment-inspections-dri5-wcct
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 dallasopendata/restaurant-and-food-establishment-inspections-dri5-wcct: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 dallasopendata/restaurant-and-food-establishment-inspections-dri5-wcct: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, dallasopendata/restaurant-and-food-establishment-inspections-dri5-wcct
is just another Postgres schema.