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 gas_permits
table in this repository, by referencing it like:
"cambridgema-gov/gas-permits-5cra-jws5:latest"."gas_permits"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"plumber_license_type", -- Plumber/:License Type
"plumber_licensee_name", -- Plumber/:Licensee Name
"plumber_llc_no", -- Plumber/:LLC #
"id", -- Permit ID
"date", -- Refresh Date
"plumber_expiration_date", -- Plumber:Expiration Date
"issue_date", -- Date when permit was issued
"boiler_chimney_count", -- Number of Boiler/Chimney(s) Vented
"boiler_direct_vent_count", -- Number of Boiler/Direct Vent(s)
"breaching_up_to_4000_btu", -- Number of breaching up to 4000 BTU
"chimney_liner_count", -- Number of chimney liner(s)
"conversion_burner_count", -- Number of conversion burner(s)
"disconnect_reconnect_count", -- Number of Disconnect/Reconnect(s)
"dryer_count", -- Number of Dryer(s)
"fireplace_insert_log_count", -- Number of Fireplace-Insert Log(s)
"fireplace_outdoor_pit_count", -- Number of Fireplace-Outdoor Pit(s)
"fryolater_count", -- Number of Fryolater(s)
"furnace_chimney_count", -- Number of Furnace/Chimney(s) Vented
"gas_meter_count", -- Number of Gas Meter(s)
"generator_count", -- Number of Generator(s)
"grill_count", -- Number of Grill(s)
"infrared_heater_count", -- Number of Infrared Heater(s)
"kiln_count", -- Number of Kiln(s)
"air_unit_gravity_count", -- Number of Make ip Air Unit Gravity(s)
"air_unit_forced_count", -- Number of Make ip Air Unit(s) Forced
"oven_count", -- Number of Oven(s)
"pool_heater_count", -- Number of Pool Heater(s)
"roof_top_unit_count", -- Number of Roof Top Unit(s)
"room_heater_count", -- Number of Room Heaters/Vented
"solenoid_valve_count", -- Number of Soleniod Valve(s)
"temporary_heat_count", -- Number of Temporary Heat(s)
"test_count", -- Number of Test(s)
"vent_damper_count", -- Number of Vent Damper(s)
"water_heater_count", -- Number of Water Heater(s)
"building_use",
"plumber_company", -- Plumber Company Name
"plumber_corporation_no", -- Plumber: Corporation #
"affidavit", -- Do you agree to attach a signed affidavit?
"mgl_requirements", -- Do you have a current liability insurance policy or its substantial equivalent which meets the requirements of MGL Ch?
"submit_date", -- Applicant Submit Date
"name_of_plumber",
"plumber_license_no", -- Plumber/:License Number
"plumber_partnership_no", -- Plumber/:Partnership #
"work_type", -- Type of work to be performed
"geocoded_column", -- Address where the work is taking place
"gas_piping_count", -- Number of Gas Piping (new per floor)
"boilers_at_least_a_million", -- Number of Boiler(s) 1,000,000 BTU and over
"booster_count", -- Number of Booster(s)
"cook_stove_count", -- Number of cook stove(s)
"coverage_type", -- Insurance: Type of Coverage
"furnace_direct_vented_count", -- Number of Furnace/Direct Vented(s)
"gas_booster", -- Is there a gas booster?
"high_pressure_gas_system", -- Is this a high-pressure gas system above 1/2 pound PSI?
"longitude",
"plumber_license_status", -- Plumber/:License Status
"status", -- Application Status
"latitude"
FROM
"cambridgema-gov/gas-permits-5cra-jws5:latest"."gas_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/gas-permits-5cra-jws5
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/gas-permits-5cra-jws5: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/gas-permits-5cra-jws5
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/gas-permits-5cra-jws5:latest
This will download all the objects for the latest
tag of cambridgema-gov/gas-permits-5cra-jws5
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/gas-permits-5cra-jws5: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/gas-permits-5cra-jws5: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/gas-permits-5cra-jws5
is just another Postgres schema.