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 building_permits_1_and_2_family_deprecated
table in this repository, by referencing it like:
"cambridgema-gov/building-permits-1-and-2-family-deprecated-52p4-36ct:latest"."building_permits_1_and_2_family_deprecated"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"stretchcodeexempt", -- Is project stretch code exempt
"enerconservfiberglass", -- Fiberglass insulation
"designedleedratinglevel", -- Designed LEED rating level (LEED means Leadership in Energy and Environmental Design)
"address", -- Address where work is to be performed
"class", -- Work class
"bldcnstrtype_wood_value", -- Type of building construction
"leedrating_coreshell", -- Type of LEEDS rating system (LEED means Leadership in Energy and Environmental Design)
":@computed_region_swkg_bavi",
":@computed_region_e4yd_rwk4",
"confirmedhersrating", -- Confirmed HERS rating (HERS means Home Energy Rating System)
"gascostofconstruction", -- Cost of gas work
"hvaccostofconstruction", -- Cost of HVAC work
"totalcostofconstruction", -- Total cost of all work to be completed
"detaileddescriptionofwork", -- Description of work to be completed
"currentuse", -- Current use of property
"zoningdistrict", -- Zoning district of property
"bzacasenumber", -- Board of Zoning Appeal case number
"pbcasenumber", -- Planning Board case number
"proposedworkprchstrsdeck", -- Proposed work includes - enclose a covered porch, build uncovered exterior stairs, build decks at the 1st floor level, build roof decks over existing 1st or 2nd floors, create new windows (including moving existing windows), doors, or skylights.
"bldtype_townhouse", -- Town House
"substantialdemo", -- Extent of demolition - substantial
"confirmedleedratinglevel", -- Confirmed LEED rating level (LEED means Leadership in Energy and Environmental Design)
"leedrating_comercialinteriors", -- Type of LEEDS rating system (LEED means Leadership in Energy and Environmental Design)
"address_city",
"energyconservsprayfoam", -- Spray foam insulation
"proposedworkenergyenv", -- Work does not access energy envelope
"substdemostructuralelements", -- Extent of demolition - structural elements
"changeinnumberofunits", -- Was there a change in the number of units
"leedrating_newconstruction", -- Type of LEEDS rating system (LEED means Leadership in Energy and Environmental Design)
"bldtype_twofamily", -- Two Family
"minorinteriordemo", -- Extent of demolition - minor
":@computed_region_rcj3_ccgu",
"leedrating_homes", -- Type of LEEDS rating system (LEED means Leadership in Energy and Environmental Design)
"solarpanels", -- Number of solar panels
"leedratingscredits", -- LEED rating credits (LEED means Leadership in Energy and Environmental Design)
"proposedworknewconst", -- Proposed work includes - new construction, additions, dormers, bays, balconies, covered stairs/landings and/or porches, decks at the 2nd floor level or higher, roof decks over the 3rd floor or higher, or to excavate a basement, change any floor or ceiling height, change the use or increase the number of dwelling units of a building, erect an outbuilding, or to do any similar work.
"proposedworkreconst", -- Proposed work includes reconstruction of an existing exterior building element (porch, deck, etc.).
"exterioralteration", -- Is work to be performed on exterior
"leedrating_schools", -- Type of LEEDS rating system (LEED means Leadership in Energy and Environmental Design)
"windturbinessize", -- Size of wind turbines
"solarpanelsuseforhotwater", -- Are solar panels used for hot water
"cogenerationsystem", -- Number of cogeneration systems
"cogenerationsystemsize", -- Size of cogeneration systems
":@computed_region_guic_hr4a",
"cavitiesinsulatingmaterials", -- Type of insulation being used
"confirmedleedratingcredits", -- Number of Confirmed LEED rating credits (LEED means Leadership in Energy and Environmental Design)
"designedleedratingcredits", -- Number of Designed LEED rating credits (LEED means Leadership in Energy and Environmental Design)
"proposedhersrating", -- Proposed HERS rating (HERS means Home Energy Rating System)
"envelopeinsulationreq", -- Meets or exceeds energy code
"leedrating_retail", -- Type of LEEDS rating system (LEED means Leadership in Energy and Environmental Design)
":@computed_region_v7jj_366k",
":@computed_region_rffn_qbt6",
"descriptionofdemolition", -- Description of demolition
"proposedworknotreg", -- Proposed work does not fall under any of the above categories (reconstruction, porch/deck/stairs, new construction). The proposed work is not of the types listed above and is not regulated by the zoning ordinance.
"parcelnumber", -- Property parcel number
"changeinnumberofunitsquantity", -- The number of units added or subtracted
"bldcnstrtype_nc_value", -- Type of building construction
"applicant", -- Name of applicant
"complete_date", -- Plan application completion date.
"applicationdate", -- Date of Application
"unitorsuite", -- Unit/Suite Number
"address_zip",
"address_state",
"buildingcostofconstruction", -- Cost of building construction
"address_address",
"plannumber", -- Auto-created plan number
"exteriordemoworkareaonly", -- Extent of demolition - work area only
"windturbineslocation", -- Location of wind turbines
"cogenerationsystemlocation", -- Location of cogeneration systems
"proposeduse", -- Proposed use of property
"bldtype_accessorybuilding", -- Accessory Building
"energyconservblownincellulose", -- Blown in insulation
"bldcnstrtype_mw_value", -- Type of building construction
"bldtype_singlefamily", -- Single Family
"twoyearvacancy", -- Was property vacant 2 years prior to application
"parkingspaces", -- Number of parking spaces
"electricalcostofconstruction", -- Cost of electrical work
"plumbingcostofconstruction", -- Cost of plumbing work
"enerconservother", -- Other type of insulation
"energyconservuvalueofwindows", -- U-Value of windows
"leedratingslevel", -- LEED rating level (LEED means Leadership in Energy and Environmental Design)
"windturbines" -- Number of wind turbines
FROM
"cambridgema-gov/building-permits-1-and-2-family-deprecated-52p4-36ct:latest"."building_permits_1_and_2_family_deprecated"
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/building-permits-1-and-2-family-deprecated-52p4-36ct
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/building-permits-1-and-2-family-deprecated-52p4-36ct: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/building-permits-1-and-2-family-deprecated-52p4-36ct
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/building-permits-1-and-2-family-deprecated-52p4-36ct:latest
This will download all the objects for the latest
tag of cambridgema-gov/building-permits-1-and-2-family-deprecated-52p4-36ct
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/building-permits-1-and-2-family-deprecated-52p4-36ct: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/building-permits-1-and-2-family-deprecated-52p4-36ct: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/building-permits-1-and-2-family-deprecated-52p4-36ct
is just another Postgres schema.