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
table in this repository, by referencing it like:
"cityofchicago/building-permits-ydr8-5enu:latest"."building_permits"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"subtotal_waived", -- Sum of BUILDING_FEE_WAIVED, ZONING_FEE_WAIVED and OTHER_FEE_WAIVED
"pin_list", -- Property index number(s) (PINs) disclosed by applicant and verified by city staff as part of permit application review (not available for all permits); PINs are assigned to parcels of land for property tax purposes. This column replaces columns PIN1 through PIN10, which will be removed soon, no earlier than 6/1/2024.
"other_fee_waived", -- Amount of other permit-related fees waived
"other_fee_subtotal", -- Sum of OTHER_FEE_PAID, OTHER _FEE_UNPAID and OTHER _FEE_WAIVED
"contact_5_state", -- Contact 5's primary address state
"contact_14_name", -- Contact 14's full name
"contact_14_zipcode", -- Contact 14's primary address ZIP code
"subtotal_unpaid", -- Sum of BUILDING_FEE_UNPAID, ZONING_FEE_UNPAID and OTHER_FEE_UNPAID
"contact_15_type", -- Contact 15's relationship to permit
"work_description", -- Description of work authorized by the permit
"contact_6_type", -- Contact 6's relationship to permit
"permit_", -- Tracking number assigned at beginning of permit application process
"processing_time", -- Number of days between APPLICATION_START_DATE and ISSUE_DATE
"building_fee_paid", -- Amount of building permit fees received
"contact_7_city", -- Contact 7's primary address city
"contact_14_city", -- Contact 14's primary address city
"review_type", -- Process used to review permit application
"contact_4_zipcode", -- Contact 4's primary address ZIP code
"contact_12_city", -- Contact 12's primary address city
"street_number", -- Address number - for buildings with address ranges, primary address is used
"contact_7_zipcode", -- Contact 7's primary address ZIP code
"contact_8_state", -- Contact 8's primary address state
"contact_10_zipcode", -- Contact 10's primary address ZIP code
"contact_7_state", -- Contact 7's primary address state
"building_fee_subtotal", -- Sum of BUILDING_FEE_PAID, BUILDING_FEE_UNPAID and BUILDING_FEE_WAIVED
"building_fee_unpaid", -- Amount of building permit fees due
"other_fee_unpaid", -- Amount of other permit-related fees due
"contact_3_type", -- Contact 3's relationship to permit
"contact_12_type", -- Contact 12's relationship to permit
"contact_13_city", -- Contact 13's primary address city
"street_direction", -- Street direction
"contact_2_state", -- Contact 2's primary address state
":@computed_region_bdys_3d7i",
":@computed_region_43wa_7qmu",
"contact_11_zipcode", -- Contact 11's primary address ZIP code
"contact_5_type", -- Contact 5's relationship to permit
"contact_2_zipcode", -- Contact 2's primary address ZIP code
"contact_3_city", -- Contact 3's primary address city
"contact_6_state", -- Contact 6's primary address state
"contact_1_zipcode", -- Contact 1's primary address ZIP code
"contact_7_type", -- Contact 7's relationship to permit
":@computed_region_awaf_s7ux",
"contact_6_zipcode", -- Contact 6's primary address ZIP code
"ward", -- The ward (city council district) of the property's primary address at the time of permit issuance. The ward map is available in a separate dataset.
"contact_15_zipcode", -- Contact 15's primary address ZIP code
"contact_4_type", -- Contact 4's relationship to permit
"issue_date", -- For most permit types, date when City determined permit was ready to issue, subject to payment of permit fees; For Express Permit Program, date when permit issued based on full payment of applicable permit fee
"contact_4_city", -- Contact 4's primary address city
"contact_4_name", -- Contact 4's full name
"contact_9_type", -- Contact 9's relationship to permit
"location", -- The location of the property's primary address in a format that allows for creation of maps and other geographic operations on this data portal
"ycoordinate", -- The north-south coordinate of the property's primary address, defined in feet, based on NAD 83 - State Plane Eastern IL
"contact_9_city", -- Contact 9's primary address city
"contact_9_zipcode", -- Contact 9's primary address ZIP code
"contact_13_state", -- Contact 13's primary address state
"zoning_fee_paid", -- Amount of zoning review fees received
"contact_10_city", -- Contact 10's primary address city
"contact_3_state", -- Contact 3's primary address state
"other_fee_paid", -- Amount of other permit-related fees received
"census_tract", -- The census tract of the property's primary address. The census tract map is available in a separate dataset.
":@computed_region_rpca_8um6",
"contact_15_city", -- Contact 15's primary address city
"subtotal_paid", -- Sum of BUILDING_FEE_PAID, ZONING_FEE_PAID and OTHER_FEE_PAID
"contact_4_state", -- Contact 4's primary address state
"contact_12_state", -- Contact 12's primary address state
"contact_15_state", -- Contact 15's primary address state
"contact_5_city", -- Contact 5's primary address city
"latitude", -- The latitude of the property's primary address
"community_area", -- The Chicago community area of the property's primary address. The community area map is available in a separate dataset.
"zoning_fee_unpaid", -- Amount of zoning review fees due
"contact_11_city", -- Contact 11's primary address city
"contact_2_name", -- Contact 2's full name
"contact_1_name", -- Contact 1's full name
"contact_3_name", -- Contact 3's full name
"contact_12_name", -- Contact 12's full name
"application_start_date", -- Date when City began reviewing permit application
"zoning_fee_waived", -- Amount of zoning review fees waived
"contact_11_type", -- Contact 11's relationship to permit
"contact_5_zipcode", -- Contact 5's primary address ZIP code
"street_name", -- Street name
"contact_13_type", -- Contact 13's relationship to permit
"contact_8_type", -- Contact 8's relationship to permit
"contact_6_name", -- Contact 6's full name
"zoning_fee_subtotal", -- Sum of ZONING_FEE_PAID, ZONING _FEE_UNPAID and ZONING _FEE_WAIVED
"contact_15_name", -- Contact 15's full name
"contact_10_type", -- Contact 10's relationship to permit
"contact_9_state", -- Contact 9's primary address state
"permit_milestone", -- Current milestone of permit (not available for all permit types).
"building_fee_waived", -- Amount of building permit fees waived
"reported_cost", -- Estimated cost of work provided by applicant (not available for all permits)
"contact_13_zipcode", -- Contact 13's primary address ZIP code
"contact_5_name", -- Contact 5's full name
"contact_10_name", -- Contact 10's full name
"contact_12_zipcode", -- Contact 12's primary address ZIP code
"longitude", -- The longitude of the property's primary address
"contact_8_zipcode", -- Contact 8's primary address ZIP code
"contact_1_type", -- Contact 1's relationship to permit
"contact_7_name", -- Contact 7's full name
"contact_8_name", -- Contact 8's full name
"contact_8_city", -- Contact 8's primary address city
"id", -- Unique database record identifier
"contact_1_city", -- Contact 1's primary address city
"work_type", -- Classification of activity authorized by permit (not available for all permit types).
"contact_1_state", -- Contact 1's primary address state
"xcoordinate", -- The east-west coordinate of the property's primary address, defined in feet, based on NAD 83 - State Plane Eastern IL
"permit_type", -- Type of permit
"contact_11_name", -- Contact 11's full name
"contact_2_city", -- Contact 2's primary address city
"contact_9_name", -- Contact 9's full name
"contact_14_type", -- Contact 14's relationship to permit
"contact_14_state", -- Contact 14's primary address state
"contact_3_zipcode", -- Contact 3's primary address ZIP code
"contact_6_city", -- Contact 6's primary address city
"contact_10_state", -- Contact 10's primary address state
":@computed_region_vrxf_vc4k",
"contact_11_state", -- Contact 11's primary address state
"contact_13_name", -- Contact 13's full name
":@computed_region_6mkv_f3dw",
"permit_status", -- Current status of permit (not available for all permit types).
"total_fee", -- Sum of SUBTOTAL_PAID, SUBTOTAL_UNPAID and SUBTOTAL_WAIVED
"contact_2_type" -- Contact 2's relationship to permit
FROM
"cityofchicago/building-permits-ydr8-5enu:latest"."building_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 cityofchicago/building-permits-ydr8-5enu
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 cityofchicago/building-permits-ydr8-5enu: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 cityofchicago/building-permits-ydr8-5enu
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 cityofchicago/building-permits-ydr8-5enu:latest
This will download all the objects for the latest
tag of cityofchicago/building-permits-ydr8-5enu
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 cityofchicago/building-permits-ydr8-5enu: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 cityofchicago/building-permits-ydr8-5enu: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, cityofchicago/building-permits-ydr8-5enu
is just another Postgres schema.