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 city_owned_and_leased_property_colp
table in this repository, by referencing it like:
"cityofnewyork-us/city-owned-and-leased-property-colp-fn4k-qyk2:latest"."city_owned_and_leased_property_colp"
or in a full query, like:
SELECT
":id", -- Socrata column ID
":@computed_region_sbqj_enih", -- This column was automatically created in order to record in what polygon from the dataset 'Police Precincts' (sbqj-enih) the point in column 'the_geom' is located. This enables the creation of region maps (choropleths) in the visualization canvas and data lens.
"non_city_ownership", -- Type of owner
"excatdesc", -- Descriptions for the expanded category values. See EXPANDCAT for the domain values.
"borough", -- NYC borough - 1 (Manhattan), 2 (Bronx), 3 (Brooklyn), 4 (Queens), 5 (Staten Island)
"billbbl", -- The mapped BBL is the BBL used to map the record. For condominium lots, the mapped BBL is the billing BBL, which is the 75nn-series record shown on the tax map and in MapPLUTO. It is generally associated with the condominium management organization. For air rights lots, the mapped BBL is the donating BBL from the Air_Rights_Lot table in the Department of Finance's Digital Tax Map. If there is more than one donating BBL, the one whose lot number most closely matches that of the air rights lot is used. For all other lots, MAPBBL is the same as BBL.
"agreement", -- For City-owned properties that are leased to another entity, this field indicates whether the agreement is short-term, long-term, or there are both short- and long-term agreements present.
"final_commitment", -- A value of "D" indicates potential disposition by the City.
"the_geom", -- Point geometry type
":@computed_region_f5dn_yrer", -- This column was automatically created in order to record in what polygon from the dataset 'Community Districts' (f5dn-yrer) the point in column 'the_geom' is located. This enables the creation of region maps (choropleths) in the visualization canvas and data lens.
":@computed_region_92fq_4b7q", -- This column was automatically created in order to record in what polygon from the dataset 'City Council Districts' (92fq-4b7q) the point in column 'the_geom' is located. This enables the creation of region maps (choropleths) in the visualization canvas and data lens.
"tax_lot", -- The number of the tax lot. Each tax lot is unique within a tax block.
"x_coordinate", -- X coordinate based on the Geosupport label point for the billing BBL. Coordinate system is NAD 1983 State Plane New York Long Island FIPS 3104 Feet.
":@computed_region_yeji_bk3q", -- This column was automatically created in order to record in what polygon from the dataset 'Borough Boundaries' (yeji-bk3q) the point in column 'the_geom' is located. This enables the creation of region maps (choropleths) in the visualization canvas and data lens.
"use_type", -- Description of how the lot is being used by the agency. See Appendix B for a complete list of use codes and descriptions.
"use_code", -- The use code indicates how the lot is being used by the agency. See Appendix B for a complete list of use codes and descriptions.
"agency", -- Abbreviation for agency or entity using the lot. See appendix A for a list of abbreviations with their full name.
"leased_properties", -- A value of "L" indicates that the agency's use of the property is authorized through a lease. For questions about the lease or ownership status of specific lots, please contact DCAS at (212) 386-0622 or RESPlanning311@dcas.nyc.gov.
"expanded_category_code", -- This categorization classifies records into broad groups based on use. Valid values are 1 - 9.
"longitude", -- Longitude based on the Geosupport label point for the billing BBL. Coordinate system is NAD_1983.
"parcel_name", -- Name of the parcel or facility on the lot. DCP applies some modifications to parcel names to improve readability. Some abbreviations are expanded programmatically. Other modifications are made after manual research. For the latter, DCPEDITED = "Y".
"y_coordinate", -- Y coordinate based on the Geosupport label point for the billing BBL. Coordinate system is NAD 1983 State Plane New York Long Island FIPS 3104 Feet.
"address", -- House number and street name
"street_name", -- Name of the street
"house_number", -- House number
"latitude", -- Latitude based on the Geosupport label point for the billing BBL. Coordinate system is NAD_1983.
"cd", -- The community district or joint interest area for the tax lot. The city is divided into 59 community districts and 12 joint interest areas, which are large parks or airports that are not considered part of any community district. This field consists of three digits, the first of which is the borough code. The second and third digits are the community district or joint interest area number, whichever is applicable.
"bbl", -- 10-digit identifier for a tax lot, consisting of the borough code followed by the tax block followed by the tax lot. The borough code is one numeric digit. The tax block is one to five numeric digits, preceded with leading zeros when the block is less than five digits. The tax lot is one to four digits and is preceded with leading zeros when the lot is less than four digits. For condominiums, this is usually the unit BBL.
"tax_block", -- The tax block in which the tax lot is located. Each tax block is unique within a borough.
"category_code" -- Category classifies lots as non-residential properties with a current use, residential properties, or properties without a current use.
FROM
"cityofnewyork-us/city-owned-and-leased-property-colp-fn4k-qyk2:latest"."city_owned_and_leased_property_colp"
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/city-owned-and-leased-property-colp-fn4k-qyk2
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 cityofnewyork-us/city-owned-and-leased-property-colp-fn4k-qyk2: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/city-owned-and-leased-property-colp-fn4k-qyk2
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/city-owned-and-leased-property-colp-fn4k-qyk2:latest
This will download all the objects for the latest
tag of cityofnewyork-us/city-owned-and-leased-property-colp-fn4k-qyk2
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/city-owned-and-leased-property-colp-fn4k-qyk2: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/city-owned-and-leased-property-colp-fn4k-qyk2: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/city-owned-and-leased-property-colp-fn4k-qyk2
is just another Postgres schema.