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-hxm5-5ddz:latest"."governors_executive_budget_program_measures_sfy"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"budget_book_budget_year", -- This is the State Fiscal Year when the program measure numbers in this row were submitted for the Governor's Executive Budget Book.
"subsidy_per_passenger_mile", -- Total subsidy divided by the total number of passenger miles
"passengers_handled2", -- Total number of trips provided with at least 1-endpoint in Pennsylvania
"passengers_handled", -- Total number of trips provided by intercity bus carrier
"surface_repairs", -- The number of miles of seal coating, leveling and sealing, spot patching or other pavement repairs
"poor_bridges_rehabilitated", -- The number of bridges that were in poor condition but have been rehabilitated or replaced
"late_bridge_preservations", -- The number of bridges that have had preservation work performed on them late in the timeframe when these activities are appropriate to extend the overall life of the bridge
"early_bridge_preservations", -- The number of bridges that have had preservation work performed on them early in the timeframe when these activities are appropriate to extend the overall life of the bridge
"percentage_of_bridges_in_2", -- The percentage of bridges, by count, that are in poor condition based on a single-digit rating that describes the bridge’s overall status in terms of structural soundness and ability to service traveling public.
"percentage_of_bridges_in_1", -- The percentage of bridges, by count, that are in fair condition based on a single-digit rating that describes the bridge’s overall status in terms of structural soundness and ability to service traveling public.
"percentage_of_national_highway", -- The percentage of miles on the non-Interstate portion of the National Highway System that are in good condition according to the MAP-21 performance measure which is based on surface condition and rideability.
"fiscal_year", -- This is the fiscal year for which the program measure values in this row are applicable. Fiscal Years 2020-21 and 2021-22 are estimated amounts based on agency projections.
"percentage_of_service_center", -- Percentage of customers served within 30 minutes at PennDOT’s physical locations.
"percentage_of_national_highway_2", -- The percentage of miles on the non-Interstate portion of the National Highway System that are in poor condition according to the MAP-21 performance measure which is based on surface condition and rideability.
"percentage_of_national_highway_1", -- The percentage of miles on the non-Interstate portion of the National Highway System that are in fair condition according to the MAP-21 performance measure which is based on surface condition and rideability.
"percentage_of_interstate_2", -- The percentage of miles on the Interstate system that are in poor condition according to the MAP-21 performance measure which is based on surface condition and rideability.
"percentage_of_interstate_1", -- The percentage of miles on the Interstate system that are in fair condition according to the MAP-21 performance measure which is based on surface condition and rideability.
"percentage_of_interstate", -- The percentage of miles on the Interstate system that are in good condition according to the MAP-21 performance measure which is based on surface condition and rideability.
"percentage_of_bridges_in", -- The percentage of bridges, by count, that are in good condition based on a single-digit rating that describes the bridge’s overall status in terms of structural soundness and ability to service traveling public.
"number_of_online_egov", -- The number of customers served through PennDOT’s on-line service channel.
"free_transit", -- Total number of free transit trips provided on fixed route, divided by the amount provided by Lottery funds for Fixed Route Operating Allocation
"trips_on_state_assisted_shared", -- Total number of trips provided to seniors on shared ride vehicles
"number_of_free_transit_trips", -- Total number of senior passenger trips provided on fixed route transit in a fiscal year
"passengers_carried_by_state", -- Total number of passenger trips taken on fixed route in a fiscal year
"total_miles_of_state", -- The total number of miles of structural restoration, resurfacing, and surface repairs
"structural_restoration", -- The number of miles of rehabilitation projects with a minimum of 3 inches of new pavement material, as well as associated work such as base repair, drainage, and shoulder
"miles_of_interstate", -- Miles of Interstate planned to begin construction or reconstruction
"runways_with_a_pavement", -- % of Runways at 51 airports classified Intermediate, advanced or commercial service which have a Pavement Condition Index value above 60
"state_assisted_shared_ride", -- Total number of trips provided to seniors on shared ride vehicles divided by the state funding provided for those trips
"passengers_per_vehicle_hour", -- Total number of passenger trips taken on fixed route, divided by the number of revenue vehicle service hours operated in a fiscal year
"access_rate_of_driver_and", -- The customers’ access to information through technology and automation, with Customer Service Representatives available to handle complex customer needs, is measured monthly with a minimum requirement of 95.5%.
"resurfacing", -- The number of miles of new pavement overlays up to 3 inches
"miles_of_new_highway", -- Miles of new roadway planned to begin construction
"number_of_closed_bridges", -- The number of bridges that have been closed due to structural inadequacy
"miles_of_non_interstate", -- Miles of non-interstate highway planned to begin construction or reconstruction.
"number_of_posted_bridges" -- The number of bridges that have posted weight restrictions
FROM
"pa-gov/governors-executive-budget-program-measures-sfy-hxm5-5ddz: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-hxm5-5ddz
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-hxm5-5ddz: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-hxm5-5ddz
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-hxm5-5ddz:latest
This will download all the objects for the latest
tag of pa-gov/governors-executive-budget-program-measures-sfy-hxm5-5ddz
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-hxm5-5ddz: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-hxm5-5ddz: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-hxm5-5ddz
is just another Postgres schema.