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 food_inspection
table in this repository, by referencing it like:
"montgomerycountymd-gov/food-inspection-5pue-gfbe:latest"."food_inspection"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"category",
"organization",
"inspectiondate",
"zip",
"address1",
"longitude",
"violation7a", -- Potentially hazardous food must be cooked to a minimum internal temperature for a required time period.
"type",
"city",
"address2",
"latitude",
"inspectiontype",
"violation4", -- Employees must wash hands with soap and warm water prior to handling exposed foods or food-contact surfaces, before starting work, as often as required to remove soil and contamination, after using toilet facilities, and before/between glove use.
"violation9", -- All sewage must be properly disposed in a manner than complies with all applicable approving authorities and remain free from any part of the system overflowing.
"violation6a", -- Cold food must be held at or below required temperature during storage, display, or transport.
"violation3", -- A food handler must not serve or handle food intended for public consumption if known or suspected of having a disease that is transmissible by food.
"violation1", -- All food, or food ingredients, must derive from a source regulated by an approving authority (private homes or unlicensed establishments are not approved sources) and are not adulterated or misbranded.
"violationmenu", -- Montgomery County requires that all restaurant chains with 10 or more locations nationally must list on the menu or menu board the calories for each menu item and have available upon request additional written nutritional information.
"location",
"violation7b", -- Potentially hazardous food must be reheated to a minimum internal temperature within a specified time period and maintained at that temperature for a designated time.
"violation5", -- Potentially hazardous food’s internal temperature is cooled to the proper temperatures within the required time frame.
"violationsmoking", -- Smoking is prohibited inside and eating or drinking establishment. No Smoking signs must be clearly posted.
"violationtransfat", -- Montgomery County prohibits the storage, use or serving of any food item containing 0.5 grams or more of partially hydrogenated vegetable oil, shortening or margarine. Does not apply to any product sold in the manufacture’s original sealed packaging.
"violation20", -- Toxic substances and pesticides are properly labeled and stored to prevent contamination of food or food preparation surfaces. This column only reflects inspection results completed after 11/06/12.
"inspectionresults", -- This is the overall result of the inspection. Note: A closed facility may have re-opened and the re-inspection results have not been posted to this site yet. Please contact a closed establishment to determine if they have been re-opened for business.
"location_address",
"violation22", -- Effective control measures are used to eliminate and prevent rodents, flies, roaches and other vermin from the building. This column only reflects inspection results completed after 11/06/12.
"violation2", -- Food deemed unfit for human consumption or otherwise is poisonous or a deleterious substances, is diseased, filthy, putrid, or decomposed.
"location_state",
"violation6b", -- Hot food must be held at or above the required temperature during storage, display, or transport.
"name",
"establishment_id",
"violation8", -- All food service establishments must be supplied with hot and cold running water under pressure from an approved source.
"location_city",
"location_zip",
":@computed_region_6vgr_duib", -- This column was automatically created in order to record in what polygon from the dataset 'Council Districts 7' (6vgr-duib) the point in column 'location' is located. This enables the creation of region maps (choropleths) in the visualization canvas and data lens.
":@computed_region_d9ke_fpxt",
":@computed_region_rbt8_3x7n",
":@computed_region_d7bw_bq6x",
":@computed_region_kbsp_ykn9",
":@computed_region_tx5f_5em3",
":@computed_region_vu5j_pcmz"
FROM
"montgomerycountymd-gov/food-inspection-5pue-gfbe:latest"."food_inspection"
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 montgomerycountymd-gov/food-inspection-5pue-gfbe
with SQL in under 60 seconds.
This repository is an "external" repository. That means it's hosted elsewhere, in this case at data.montgomerycountymd.gov. When you querymontgomerycountymd-gov/food-inspection-5pue-gfbe: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
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 (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 clone
and sgr checkout
.
Mounting Data
This repository is an external repository. It's not hosted by Splitgraph. It is hosted by data.montgomerycountymd.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 \
"montgomerycountymd-gov/food-inspection-5pue-gfbe" \
--handler-options '{
"domain": "data.montgomerycountymd.gov",
"tables": {
"food_inspection": "5pue-gfbe"
}
}'
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, montgomerycountymd-gov/food-inspection-5pue-gfbe
is just another Postgres schema.