cityofnewyork-us/dob-permit-issuance-ipu4-2q9a
Icon for Socrata external plugin

Query the Data Delivery Network

Query the DDN

The 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 dob_permit_issuance table in this repository, by referencing it like:

"cityofnewyork-us/dob-permit-issuance-ipu4-2q9a:latest"."dob_permit_issuance"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "act_as_superintendent", -- Permittee Acts as Superintendent
    "site_fill", -- Site Fill
    "permit_sequence__", -- Permit Sequence #
    "permit_type", -- Permit Type (DM-Demolition, EW-Equipment Work, PL-Plumbing, etc.)  Complete List - http://www.nyc.gov/html/dob/downloads/pdf/bisjobstatus.pdf
    "permit_status", -- Permit Status
    "special_district_2", -- Special District 2
    "residential", -- Residential
    "bldg_type", -- 1-2-3 Family  or Other
    "owner_s_house_street_name", -- Owner's House Street Name
    "city", -- Owner’s House City
    "owner_s_zip_code", -- Owner’s House Zip Code
    "gis_council_district",
    "gis_longitude",
    "job_start_date", -- Job Start Date
    "permittee_s_last_name", -- Permittee's Last Name
    "owner_s_house__", -- Owner's House #
    "gis_census_tract",
    "bin__", -- Number assigned by City Planning to a specific building
    "street_name", -- Street Name where Property is located
    "zip_code", -- Tax lot Zip Code
    "permittee_s_other_title", -- Permittee's Other Title
    "hic_license", -- HIC License
    "site_safety_mgr_business_name", -- Site Safety Mgr Business Name
    "owner_s_business_name", -- Business Name of Property Owner
    "lot", -- Tax lot assigned by Department of Finance
    "filing_date", -- Filing Date
    "work_type", -- DOB Designated Work Types (PL-Plumbing,  BL-Boiler, MH-Mechanical, OT-Other Constuction Equipment, etc.)
    "site_safety_mgr_s_last_name", -- Site Safety Mgr's Last Name
    "job_type", -- Job Type, based on DOB Job Code (NB-New Building, A1, A2, A3- Alterations 1-3, SG-Sign, etc.)
    "non_profit", -- Non-Profit
    "oil_gas", -- Oil Gas
    "special_district_1", -- Special District 1
    "owner_s_last_name", -- Last Name of property owner
    "owner_s_phone__", -- Owner's Phone #
    "community_board", -- 3-digit identifier: Borough code = first position, last 2 = community board
    "permittee_s_first_name", -- Permittee's First Name
    "superintendent_first___last_name", -- Superintendent First & Last Name
    "superintendent_business_name", -- Superintendent Business Name
    "owner_s_first_name", -- First Name of property owner
    "state", -- Owner’s House State
    "dobrundate", -- Date when query is run and pushed to Open Data. Could be used to differentiate report dates.
    "permit_si_no",
    "gis_nta_name",
    "permit_subtype", -- Permit Subtype (Subset of Equipment Work Permit Type-- BL-Boiler, FA- Fire Alarm, Subset of Construction Equipment Permit Type-- CH-Chute, SF-Scaffold, etc.) Complete List - http://www.nyc.gov/html/dob/downloads/pdf/bisjobstatus.pdf
    "permittee_s_business_name", -- Permittee's Business Name
    "permittee_s_license__", -- Permittee's License #
    "gis_latitude",
    "issuance_date", -- Issuance Date
    "expiration_date", -- Expiration Date
    "owner_s_business_type", -- Owner's Business Type
    "permittee_s_phone__", -- Permittee's Phone #
    "block", -- Tax block assigned by Department of Finance
    "site_safety_mgr_s_first_name", -- Site Safety Mgr's First Name
    "permittee_s_license_type", -- Permittee's License Type
    "job__", -- Number assigned by DOB to Job Filing
    "house__", -- House Number of Residence or Commercial Property
    "job_doc___", -- Document Number
    "self_cert", -- Self_Cert
    "filing_status", -- Filing Status
    "borough" -- 1= Manhattan, 2= Bronx, 3 = Brooklyn, 4 = Queens, 5 = Staten Island
FROM
    "cityofnewyork-us/dob-permit-issuance-ipu4-2q9a:latest"."dob_permit_issuance"
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 cityofnewyork-us/dob-permit-issuance-ipu4-2q9a with SQL in under 60 seconds.

This repository is an "external" repository. That means it's hosted elsewhere, in this case at data.cityofnewyork.us. When you querycityofnewyork-us/dob-permit-issuance-ipu4-2q9a:latest on the DDN, we "mount" the repository using the socrata mount handler. The mount handler proxies your SQL query to the upstream data source, translating it from SQL to the relevant language (in this case SoQL).

We also cache query responses on the DDN, but we run the DDN on multiple nodes so a CACHE_HIT is only guaranteed for subsequent queries that land on the same node.

Query Your Local Engine

Install Splitgraph Locally
bash -c "$(curl -sL https://github.com/splitgraph/splitgraph/releases/latest/download/install.sh)"
 

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; sgrcan manage the image, container and volume for you.

There are a few ways to ingest data into the local engine.

For external repositories (like this repository), 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, where the author has pushed Splitgraph Images to the repository, you can "clone" and/or "checkout" the data using sgr cloneand sgr checkout.

Mounting Data

This repository is an external repository. It's not hosted by Splitgraph. It is hosted by data.cityofnewyork.us, and Splitgraph indexes it. This means it is not an actual Splitgraph image, so you cannot use sgr clone to get the data. Instead, you can use the socrata adapter with the sgr mount command. Then, if you want, you can import the data and turn it into a Splitgraph image that others can clone.

First, install Splitgraph if you haven't already.

Mount the table with sgr mount

sgr mount socrata \
  "cityofnewyork-us/dob-permit-issuance-ipu4-2q9a" \
  --handler-options '{
    "domain": "data.cityofnewyork.us",
    "tables": {
        "dob_permit_issuance": "ipu4-2q9a"
    }
}'

That's it! Now you can query the data in the mounted table like any other Postgres table.

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, cityofnewyork-us/dob-permit-issuance-ipu4-2q9a is just another Postgres schema.

Related Documentation: