pa-gov/dangerous-dogs-1996current-county-agriculture-3fcn-e5dk
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 dangerous_dogs_1996current_county_agriculture table in this repository, by referencing it like:

"pa-gov/dangerous-dogs-1996current-county-agriculture-3fcn-e5dk:latest"."dangerous_dogs_1996current_county_agriculture"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "middle_name", -- Middle Name of the Owner
    "address_line_2", -- Owner Street Address line 2
    "full_address", -- Owner complete address
    "business_name", -- Business name if applicable and not an individual owner
    "pa_dept_of_ag_dog_law_region", -- REGION 1: 13410 Dunham Road - Meadville, PA 16335 (Clarion, Crawford, Elk, Erie, Forest, Jefferson, McKean, Mercer, Venango, Warren Counties) 814-332-6890 REGION 2: 2130 County Farm Road - Suite 2 - Montoursville, PA 17754 (Cameron, Clinton, Columbia, Lycoming, Montour, Northumberland, Potter, Snyder, Tioga, Union Counties) 717-433-2640 REGION 3: Rt. 92 South - Box C - Tunkhannock, PA 18657 (Bradford, Carbon, Lackawanna, Luzerne, Monroe, Pike, Sullivan, Susquehanna, Wayne, Wyoming Counties) 717-836-2181 REGION 4: 5349 Wm. Flynn Highway - Gibsonia, PA 15044 (Allegheny, Armstrong, Beaver, Butler, Fayette, Greene, Indiana, Lawrence, Washington, Westmoreland Counties) 724-443-1585 REGION 5 1304 7th St Cricket Field Plaza - Altoona, PA 16601 (Bedford, Blair, Cambria, Centre, Clearfield, Fulton, Huntingdon, Juniata, Mifflin, Somerset Counties) 814-946-7315 REGION 6: 2301 North Cameron St. - Harrisburg, PA 17110 (Adams, Cumberland, Dauphin, Franklin, Lancaster, Lebanon, Perry, York Counties) 717-787-4833 REGION 7: Route 113 - PO Box 300 - Creamery, PA 19430 (Berks, Bucks, Chester, Delaware, Lehigh, Montgomery, Northampton, Philadelphia, Schuylkill Counties) 610-489-1003
    "owner_city", -- Owner City Address
    "owner_address", -- Owner Street Address
    "owner_last_name", -- Last Name of the Owner
    "owner_first_name", -- First Name of the Owner
    "hearing_date", -- Hearing Date for the case
    "owner_county", -- County name where the owner resides
    "county_key", -- PA State County Code as a number
    "dog_info_predator", -- Stating the predator is a Dog
    "dog_info_breed", -- Breed name of the dog when available
    "determination_year", -- The year the determination was made in the case
    "dog_info_age", -- Age of the dog when available
    "county_description", -- Name of the PA county
    "geocoded_column", -- This includes a georeferenced point of Latitude and Longitude calculated from the owner address to help with creating visuals such as maps.
    "account_first_last_name", -- First name, last name on the Account as the owner
    "account_last_first_names", -- Last name, First name, on the Account as the owner
    "owner_zip", -- Owner Zip Code Address
    "court_disposition", -- Valid Values: Guilty, Not Guilty, Appeal,  Dismissed, Ruling,  Pending, Other
    "status_description", -- Status details of the case
    "file_date", -- Date the incident was filed
    ":@computed_region_r6rf_p9et",
    ":@computed_region_rayf_jjgk",
    ":@computed_region_d3gw_znnf",
    ":@computed_region_nmsq_hqvv",
    ":@computed_region_amqz_jbr4",
    "owner_state" -- Owner State Address
FROM
    "pa-gov/dangerous-dogs-1996current-county-agriculture-3fcn-e5dk:latest"."dangerous_dogs_1996current_county_agriculture"
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 pa-gov/dangerous-dogs-1996current-county-agriculture-3fcn-e5dk with SQL in under 60 seconds.

This repository is an "external" repository. That means it's hosted elsewhere, in this case at data.pa.gov. When you querypa-gov/dangerous-dogs-1996current-county-agriculture-3fcn-e5dk: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.pa.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 \
  "pa-gov/dangerous-dogs-1996current-county-agriculture-3fcn-e5dk" \
  --handler-options '{
    "domain": "data.pa.gov",
    "tables": {
        "dangerous_dogs_1996current_county_agriculture": "3fcn-e5dk"
    }
}'

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, pa-gov/dangerous-dogs-1996current-county-agriculture-3fcn-e5dk is just another Postgres schema.