montgomerycountymd-gov/food-inspection-5pue-gfbe
Loading...

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 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.

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, 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 cloneand sgr checkout.

Cloning Data

Because montgomerycountymd-gov/food-inspection-5pue-gfbe: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 montgomerycountymd-gov/food-inspection-5pue-gfbe

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 montgomerycountymd-gov/food-inspection-5pue-gfbe:latest

This will download all the objects for the latest tag of montgomerycountymd-gov/food-inspection-5pue-gfbe 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 montgomerycountymd-gov/food-inspection-5pue-gfbe: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 montgomerycountymd-gov/food-inspection-5pue-gfbe: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, montgomerycountymd-gov/food-inspection-5pue-gfbe is just another Postgres schema.

Related Documentation:

Loading...