citydata-mesaaz-gov/building-permits-2gkz-7z4f
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 building_permits table in this repository, by referencing it like:

"citydata-mesaaz-gov/building-permits-2gkz-7z4f:latest"."building_permits"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "property_address", -- The street address where the construction will take place
    "latitude", -- The latitude for the construction.
    "unit_number", -- The Unit Number of Property Address
    "street_number", -- The street number of the property address where the construction will take place
    "issued_month", -- The month the permit was issued by the City of Mesa
    "contractor_name", -- The name of the contractor associated with the permit, if any
    "number_of_dwelling_units", -- The number of units or apartments for this project.
    "rowid", -- Unique Row Identifier
    "permit_number", -- The case/permit number used to refer to this application or permit record This number consists of: 1) A three-character prefix (BLD or PMT, which means a building permit); 2) A four or two digit year (the year in which the application was made); 3) A hyphen; 4) A five digit sequential number
    "permit_year", -- The year when the permit was issued by City of Mesa
    "finaled_month", -- The month the final inspection was completed.
    "finaled_date", -- The date the final inspection was completed. There can be NO work done after this date.
    "number_of_dwellings", -- The number of buildings considered to be dwellings for this project.
    "parcel_number", -- The primary parcel number associated with this permit This number is assigned by Maricopa County and consists of: Book Number (first three characters); Page Number (next two characters); Parcel Number (last three or four characters)
    "issued_year", -- The year the permit was issued by the City of Mesa.
    "street_type", -- The street type of the property address where the construction will take place
    "street_direction", -- The street direction of the property address where the construction will take place
    "street_name", -- The street name of the property address where the construction will take place
    "description", -- A brief description of the work to be done, sometimes includes location information
    "longitude", -- The longitude for the construction.
    "applicant", -- The name of the person that applied for the permit
    "cofo_date", -- The date a Change of Occupancy was completed
    ":@computed_region_fcpr_wj2n",
    "use", -- COM = Commercial construction; RES = Residential construction; SVC = Application for Service(s)
    "council_district", -- City Council District Associated with Property Address
    "contractor_address", -- The address of the contractor associated with the permit, if any
    "type_of_work", -- A more specific description of the Use
    "icc_value", -- The dollar value of the work to be done based on valuation rates furnished by the International Code Council (ICC)
    "finaled_year", -- The year the final inspection was completed.
    "issued_date", -- The date the permit was issued by the City of Mesa, allowing construction to begin
    "status", -- The current status of the permit, which is one of these: Under Review, Approved, Issued, Finaled (meaning project is completed), Void
    "value", -- The dollar value of the work to be done, this is set by the Contractor
    "total_sq_ft", -- The total square footage for work being accomplished by this permit
    "residential_permit", -- 'Y' if this is a permit for a new residential building, or 'N' if otherwise.
    "location" -- Geocoded location for the construction
FROM
    "citydata-mesaaz-gov/building-permits-2gkz-7z4f: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 citydata-mesaaz-gov/building-permits-2gkz-7z4f with SQL in under 60 seconds.

This repository is an "external" repository. That means it's hosted elsewhere, in this case at citydata.mesaaz.gov. When you querycitydata-mesaaz-gov/building-permits-2gkz-7z4f: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)"
 

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; 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 citydata.mesaaz.gov, 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 \
  "citydata-mesaaz-gov/building-permits-2gkz-7z4f" \
  --handler-options '{
    "domain": "citydata.mesaaz.gov",
    "tables": {
        "building_permits": "2gkz-7z4f"
    }
}'

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, citydata-mesaaz-gov/building-permits-2gkz-7z4f is just another Postgres schema.