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 plumbing_permits
table in this repository, by referencing it like:
"cambridgema-gov/plumbing-permits-8793-tet2:latest"."plumbing_permits"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"num_of_kitchen_sinks", -- Number of kitchen sinks
"num_of_dishwashers", -- Number of dishwashers
"floors_s_where_toilet_s_will", -- Floor(s) where toilet(s) will be located
"floor_s_where_sill_cock_s", -- Floor(s) where sill cock(s) will be located
"num_of_water_filter_s", -- Number of Water Filter(s)
"num_of_ph_neutralizing_system", -- Number of PH Neutralizing System(s)
"num_of_grease_interceptor_s_1", -- Number of Grease Interceptor(s) (Exterior)
"num_of_cross_connection_device_1", -- Number of Cross Connection Device(s) - Non-Testable
"floor_s_where_safe_water", -- Floor(s) where Safe Water Pan(s) will be located
"floor_s_where_ph_neutralizing", -- Floor(s) where PH Neutralizing Sump(s) will be located
"floor_s_where_roof_drain", -- Floor(s) where Roof Drain(s) will be located
"floor_s_where_grease", -- Floor(s) where Grease Interceptor(s) (Interior) will be located
"floor_s_where_dedicated_gas", -- Floor(s) where Dedicated Gas/Oil/Sand System(s) will be located
"company_name", -- Name of plumbing company
"floor_s_where_bathtub_s_will", -- Floor(s) where bathtub will be located
"water_department_permit_number", -- Permit number from the Water Department
"fulladdress", -- Location of where plumbing work is being done
"num_of_pedicare_dental_chair", -- Number of Pedicare/Dental Chair(s)
"num_of_cross_connection_device", -- Number of Cross Connection Device(s) - Testable
"floor_s_where_floor_area", -- Floor(s) where Floor/Area Drain(s) will be located
"num_of_washing_machines", -- Number of washing machines
"num_of_icemakers", -- Number of icemakers
"num_of_bathtubs", -- Number of bathtubs
"floor_s_where_kitchen_sink", -- Floor(s) where kitchen sink will be located
"num_of_water_cooler_s_filtered", -- Number of Water Cooler(s) Filtered
"num_of_three_bay_sink_s", -- Number of Three Bay Sink(s)
"num_of_grease_interceptor_s", -- Number of Grease Interceptor(s) (Interior)
"floor_s_where_cross_connection", -- Floor(s) where Testable Cross Connection Device(s) will be located
"num_of_sewer_ejector_s", -- Number of Sewer Ejector(s)
"num_of_water_meter_s_irrigation", -- Number of Water Meter(s) (Irrigation)
"num_of_roof_drain_s", -- Number of Roof Drain(s)
"floor_s_where_urinal_s_will", -- Floor(s) where Urinal(s) will be located
"floor_s_where_cross_connection_1", -- Floor(s) where Nontestable Cross Connection Device(s) will be located
"license_type", -- Type of plumbing license
"floor_s_where_back_water", -- Floor(s) where Back Water Valve(s) will be located
"fixture_count_in_excess_of", -- Fixture count in excess of five
"fixture_count", -- Number of fixtures
"floor_s_where_lavatories", -- Floor(s) where lavatories will be located
"expiration_date",
"floor_s_where_dishwasher", -- Floor(s) where dishwasher will be located
"floor_s_where_washing_machine", -- Floor(s) where washing machine will be located
"issue_date",
"applicant_submit_date",
"num_of_water_piping_new_per", -- Number of Water Piping (New per floor)
"num_of_water_meter_s_sub", -- Number of Water Meter(s) (Sub)
"num_of_water_heater_s_tankless", -- Number of Water Heater(s) (Tankless)
"num_of_water_heater_s_indirect", -- Number of Water Heater(s) (Indirect)
"num_of_water_heater_s_gas", -- Number of Water Heater(s) (Gas)
"num_of_water_heater_s_electric", -- Number of Water Heater(s) (Electric)
"num_of_sanitary_waste__vent", -- Number of Sanitary Waste & Vent(s)
"num_of_hand_sink_s", -- Number of Hand Sink(s)
"num_of_food_prep_sink_s", -- Number of Food Prep Sink(s)
"num_of_flushing_rim_sink_s", -- Number of Flushing Rim Sink(s)
"num_of_mop_sink_s", -- Number of Mop Sink(s)
"num_of_floor_area_drain_s", -- Number of Floor/Area Drain(s)
"num_of_dedicated_water_recycle", -- Number of Dedicated Water Recycle System(s)
"num_of_dedicated_special_waste", -- Number of Dedicated Special Waste System(s)
"num_of_dedicated_gray_water", -- Number of Dedicated Gray Water System(s)
"num_of_dedicated_gas_oil_sand", -- Number of Dedicated Gas/Oil/Sand System(s)
"floor_s_where_water_meter_1", -- Floor(s) where Water Meter(s) (Sub) will be located
"floor_s_where_water_heater_1", -- Floor(s) where Water Heater(s) (Gas) will be located
"floor_s_where_water_filter", -- Floor(s) where Water Filter(s) will be located
"floor_s_where_three_bay_sink", -- Floor(s) where Three Bay Sink(s) will be located
"floor_s_where_solar_hybrid", -- Floor(s) where Solar/Hybrid System(s) will be located
"floor_s_where_sewer_ejector", -- Floor(s) where Sewer Ejector(s) will be located
"floor_s_where_ph_neutralizing_1", -- Floor(s) where PH Neutralizing System(s) will be located
"floor_s_where_pedicare_dental", -- Floor(s) where Pedicare/Dental Chair(s) will be located
"floor_s_where_water_meter", -- Floor(s) where Water Meter(s) (Irrigation) will be located
"floor_s_where_hand_sink_s", -- Floor(s) where Hand Sink(s) will be located
"floor_s_where_food_prep_sink", -- Floor(s) where Food Prep Sink(s) will be located
"floor_s_where_flushing_rim", -- Floor(s) where Flushing Rim Sink(s) will be located
"floor_s_where_mop_sink_s", -- Floor(s) where Mop Sink(s) will be located
"floor_s_where_disconnect", -- Floor(s) where Disconnect/Re-Connect(s) will be located
"floor_s_where_dedicated_water", -- Floor(s) where Dedicated Water Recycle System(s) will be located
"floor_s_where_dedicated", -- Floor(s) where Dedicated Special Waste System(s) will be located
"floor_s_where_grease_1", -- Floor(s) where Grease Interceptor(s) (Exterior) will be located
"type_of_work_to_be_performed", -- Type of work to be performed (e.g. renovation, replacement, etc.)
"num_of_toilets", -- Number of toilets
"num_of_sill_cocks_hose_bib", -- Number of sill cocks
"num_of_shower_stalls", -- Number of shower stalls
"num_of_lavatories", -- Number of lavatories
"num_of_solar_hybrid_system_s", -- Number of Solar/Hybrid System(s)
"num_of_ph_neutralizing_sump", -- Number of PH Neutralizing Sump(s)
"num_of_urinal_s", -- Number of Urinal(s)
"floor_s_where_dedicated_gray", -- Floor(s) where Dedicated Gray Water System(s) will be located
"num_of_back_water_valves", -- Number of Back Water Valves
"num_of_safe_water_pan_s", -- Number of Safe Water Pan(s)
"status", -- Application status
"floor_s_where_water_cooler", -- Floor(s) where Water Cooler (Filtered) will be located
"id",
"latitude",
"longitude",
"street_address",
"floor_s_where_icemakers_s", -- Floor(s) where icemaker will be located
"num_of_disconnect_re_connect", -- Number of Disconnect/Re-Connect(s)
"would_you_like_to_add_a", -- Would you like to add a fixture that doesn't appear on this page?
"floor_s_where_vacuum_drainage", -- Floor(s) where Vacuum Drainage System(s) will be located
"num_of_vacuum_drainage_system", -- Number of Vacuum Drainage System(s)
"floor_s_where_water_piping", -- Floor(s) where Water Piping (New per floor)(s) will be located
"floor_s_where_water_heater_3", -- Floor(s) where Water Heater(s) (Tankless) will be located
"floor_s_where_water_heater_2", -- Floor(s) where Water Heater(s) (Indirect) will be located
"floor_s_where_water_heater", -- Floor(s) where Water Heater(s) (Electric) will be located
"floor_s_where_sanitary_waste", -- Floor(s) where Sanitary Waste & Vent(s) will be located
"will_there_be_a_testable", -- Will there be a testable cross connection device?
"num_of_food_disposals", -- Number of food disposals
"floor_s_where_shower_stall", -- Floor(s) where shower stalls will be located
"floor_s_where_food_disposal", -- Floor(s) where food disposal will be located
"will_plans_be_submitted_with" -- Will plans be submitted with this application?
FROM
"cambridgema-gov/plumbing-permits-8793-tet2:latest"."plumbing_permits"
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 cambridgema-gov/plumbing-permits-8793-tet2
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 cambridgema-gov/plumbing-permits-8793-tet2: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 cambridgema-gov/plumbing-permits-8793-tet2
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 cambridgema-gov/plumbing-permits-8793-tet2:latest
This will download all the objects for the latest
tag of cambridgema-gov/plumbing-permits-8793-tet2
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 cambridgema-gov/plumbing-permits-8793-tet2: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 cambridgema-gov/plumbing-permits-8793-tet2: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, cambridgema-gov/plumbing-permits-8793-tet2
is just another Postgres schema.