cityofnewyork-us/affordable-housing-production-by-building-hg8x-zxpr
Loading...

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

"cityofnewyork-us/affordable-housing-production-by-building-hg8x-zxpr:latest"."affordable_housing_production_by_building"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "house_number", -- The House Number is the street number in the building’s address. E.g., the house number is ‘100’ in ‘100 Gold Street.’
    "studio_units", -- Studio Units are units with 0-bedrooms.
    "_5_br_units", -- 5-BR Units are units with 5-bedrooms.
    "project_id", -- The Project ID is a unique numeric identifier assigned to each project by HPD.
    "project_name", -- The Project Name is the name assigned to the project by HPD.
    "project_start_date", -- The Project Start Date is the date of the project loan or agreement closing.
    "project_completion_date", -- The Project Completion Date is the date that the last building in the project was completed. If the project has not yet completed, then the field is blank.
    "building_id", -- The Building ID is a unique numeric identifier assigned to each building by HPD.
    "street_name", -- The Street Name is the name of the street in the building’s address. E.g., the street name is ‘Gold Street’ in ‘100 Gold Street.’
    "borough", -- The Borough is the borough where the building is located.
    "community_board", -- The Community Board field indicates the New York City Community District where the building is located.
    "neighborhood_tabulation_area", -- The Neighborhood Tabulation Area indicates the New York City Neighborhood Tabulation Area where the building is located.
    "latitude", -- The Latitude and Longitude specify the location of the property on the earth’s surface. The coordinates provided are an estimate of the location based on the street segment and address range.
    "latitude_internal", -- The Latitude (Internal) and Longitude (Internal) specify the location of the property on the earth’s surface. The coordinates provided are of the internal centroid derived from the tax lot.
    "longitude_internal", -- The Latitude (Internal) and Longitude (Internal) specify the location of the property on the earth’s surface. The coordinates provided are of the internal centroid derived from the tax lot.
    "building_completion_date", -- The Building Completion Date is the date the building was completed. The field is blank if the building has not completed.
    "extremely_low_income_units", -- Extremely Low Income Units are units with rents that are affordable to households earning 0 to 30% of the area median income (AMI).
    "very_low_income_units", -- Very Low Income Units are units with rents that are affordable to households earning 31 to 50% of the area median income (AMI).
    "_1_br_units", -- 1-BR Units are units with 1-bedroom.
    "_2_br_units", -- 2-BR Units are units with 2-bedrooms.
    "_4_br_units", -- 4-BR Units are units with 4-bedrooms.
    "counted_rental_units", -- Counted Rental Units are the units in the building, counted toward the Housing New York plan, where assistance has been provided to landlords in exchange for a requirement for affordable units.
    "all_counted_units", -- The Counted Units field indicates the total number of affordable units, counted towards the Housing New York plan, that are in the building.
    "postcode", -- Zip code
    "bbl", -- The BBL (Borough, Block, and Lot) is a unique identifier for each tax lot in the City.
    "bin", -- The BIN (Building Identification Number) is a unique identifier for each building in the City.
    "council_district", -- The Council District indicates the New York City Council District where the building is located.
    "census_tract", -- The Census Tract indicates the 2010 U.S. Census Tract where the building is located.
    "longitude", -- The Latitude and Longitude specify the location of the property on the earth’s surface. The coordinates provided are an estimate of the location based on the street segment and address range.
    "reporting_construction_type", -- The Reporting Construction Type field indicates whether the building is categorized as ‘new construction’ or ‘preservation’ in Housing New York statistics. Note that some preservation projects included here may not actually involve construction, because they extend the project’s regulatory restrictions but do not require rehabilitation.
    "extended_affordability_status", -- The Extended Affordability Only field indicates whether the project is considered to be Extended Affordability. An extended affordability project involves no construction, but secures an extended or new regulatory agreement. All extended affordability projects have a ‘reporting construction type’ of ‘preservation.’
    "prevailing_wage_status", -- The Prevailing Wage Status field indicates whether the project is subject to prevailing wage requirements, such as Davis Bacon.
    "low_income_units", -- Low Income Units are units with rents that are affordable to households earning 51 to 80% of the area median income (AMI).
    "moderate_income_units", -- Moderate Income Units are units with rents that are affordable to households earning 81 to 120% of the area median income (AMI).
    "middle_income_units", -- Middle Income Units are units with rents that are affordable to households earning 121 to 165% of the area median income (AMI).
    "other_income_units", -- Other Units are units reserved for building superintendents.
    "_3_br_units", -- 3-BR Units are units with 3-bedrooms.
    "_6_br_units", -- 6-BR+ Units are units with 6-bedrooms or more.
    "unknown_br_units", -- Unknown-BR Units are units with an unknown number of bedrooms.
    "counted_homeownership_units", -- Counted Homeownership Units are the units in the building, counted toward the Housing New York Plan, where assistance has been provided directly to homeowners.
    "total_units" -- The Total Units field indicates the total number of units, affordable and market rate, in each building.
FROM
    "cityofnewyork-us/affordable-housing-production-by-building-hg8x-zxpr:latest"."affordable_housing_production_by_building"
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/affordable-housing-production-by-building-hg8x-zxpr with SQL in under 60 seconds.

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, 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 cloneand sgr checkout.

Cloning Data

Because cityofnewyork-us/affordable-housing-production-by-building-hg8x-zxpr: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 cityofnewyork-us/affordable-housing-production-by-building-hg8x-zxpr

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 cityofnewyork-us/affordable-housing-production-by-building-hg8x-zxpr:latest

This will download all the objects for the latest tag of cityofnewyork-us/affordable-housing-production-by-building-hg8x-zxpr 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 cityofnewyork-us/affordable-housing-production-by-building-hg8x-zxpr: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 cityofnewyork-us/affordable-housing-production-by-building-hg8x-zxpr: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, cityofnewyork-us/affordable-housing-production-by-building-hg8x-zxpr is just another Postgres schema.

Related Documentation:

Loading...