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 governors_executive_budget_program_measures_sfy
table in this repository, by referencing it like:
"pa-gov/governors-executive-budget-program-measures-sfy-pedd-rnfm:latest"."governors_executive_budget_program_measures_sfy"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"average_days_to_respond_to", -- The average number of days between the day a complaint is received and the day DEP staff respond with a field visit. DEP's complaint response system has four priority levels, and "Priority 1" complaints are the most critical. Days are calculated by the subtraction of calendar days; accordingly, consecutive days result in a difference of 1, and a same-day response results in a difference of 0. Decimals are a result of the average.
"percentage_of_permits", -- The percentage of applications covered by DEP's Permit Decision Guarantee Policy of 2012 that were disposed within the applicable time frames outlined in that policy. This metric only pertains to applications that were "active," meaning that they contained no technical deficiencies to be corrected by the applicant.
"total_inspections_conducted", -- The number of inspections conducted by DEP staff during a given fiscal year.
"total_violations_resolved", -- The number of open violations that were resolved during a given fiscal year. Not all violations are resolved during the same year they were recorded, so this number may include violations that were recorded in previous fiscal years as well.
"total_violations_recorded", -- The number of violations recorded by DEP's inspectors during a given fiscal year.
"percentage_of_community_water", -- DEP's Safe Drinking Water Program is obligated to conduct certain types of inspections on a defined recurring schedule. This percentage reflects those that were conducted on time.
"fiscal_year", -- This is the fiscal year for which the program measure values in this row are applicable. The state fiscal year runs from July 1 to June 30. Fiscal Years 2020-21 and 2021-22 are estimated amounts based on agency projections.
"percentage_of_population", -- The percentage of Pennsylvania's population that lived in counties that monitored below the standard during a given year. A county's change in status will affect the results from year to year, as well as changes in population. This data is reported on a calendar year basis.
"tons_of_municipal_solid_waste", -- Tons of municipal solid waste recycled by Pennsylvania citizens and entities, as reported to DEP by local governments in their Act 101 annual reports. This data is reported on a calendar year basis. The data is subject to change due to corrections and continuous verification.
"cumulative_acres_of_abandoned", -- The total acres of abandoned mine land reclaimed since 1977. This number is cumulative from one fiscal year to the next; therefore, the difference between two fiscal year totals reflects the acres reclaimed between those years.
"total_authorizations_disposed", -- The number of applications for DEP authorizations disposed during a given fiscal year. The term "disposed" includes those that were issued, denied, withdrawn, cancelled, or returned.
"year_budget_finalized", -- This is the State Fiscal Year when the program measure numbers in this row were submitted for the Governor's Executive Budget Book.
"total_authorizations_received" -- The number of applications for DEP authorizations received during a given fiscal year. The term "authorizations" includes permits, licenses, registrations, and certifications.
FROM
"pa-gov/governors-executive-budget-program-measures-sfy-pedd-rnfm:latest"."governors_executive_budget_program_measures_sfy"
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/governors-executive-budget-program-measures-sfy-pedd-rnfm
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 pa-gov/governors-executive-budget-program-measures-sfy-pedd-rnfm: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 pa-gov/governors-executive-budget-program-measures-sfy-pedd-rnfm
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 pa-gov/governors-executive-budget-program-measures-sfy-pedd-rnfm:latest
This will download all the objects for the latest
tag of pa-gov/governors-executive-budget-program-measures-sfy-pedd-rnfm
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 pa-gov/governors-executive-budget-program-measures-sfy-pedd-rnfm: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 pa-gov/governors-executive-budget-program-measures-sfy-pedd-rnfm: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, pa-gov/governors-executive-budget-program-measures-sfy-pedd-rnfm
is just another Postgres schema.