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_permit_applications_main_street_districts
table in this repository, by referencing it like:
"cityoforlando/building-permit-applications-main-street-districts-ny35-rb8n:latest"."building_permit_applications_main_street_districts"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"rcnt_cocdt", -- Y = COC was created in the last 6 months
"rcnt_coodt", -- Y = COO was created in the last 6 months
"rcnt_issdt", -- Y = Permit was Issued in the last 6 months
"state", -- Related to Address Contact of Primary Applicant
"zip", -- Related to Address Contact of Primary Applicant
"cra", -- Community Redevelopment Area
"apno", -- Application Number
"apname", -- Project Name
"bldgapplstatus", -- Application Status
"application_date", -- Date the Application was processed by the City of Orlando
"addr1", -- Related to Address Contact of Primary Applicant
"addr2", -- Related to Address Contact of Primary Applicant
"capacity", -- Role or Capacity of the Applicant in relation to the project
"city", -- Related to Address Contact of Primary Applicant
"dayphn", -- Phone Contact of Primary Applicant
"email", -- Email Contact of Primary Applicant
"fullname", -- Name of the Primary Applicant
"bldgarea", -- Square Footage for Project
"comments_search", -- Project Comments
"coodttm", -- Certificate of Occupancy Date
"expdttm", -- Expire Date of Permit
"findttm", -- Date the Permit was Finalized (Work is completed)
"issdttm", -- Date the Permit was Issued (Work can begin)
"loc", -- Additional Location information
"worktype", -- Code that indicates the type of work covered by the permit
"appl_milestone", -- Describes the processing stage of the application
"ownersestval", -- Owner's estimated value of the project
"planrevtypecd", -- C = Commercial, R1 = Single Family Residential, R3 = Multi Family Residential
"cocdate", -- Cert of Completion Date
"sbffilenumber", -- Sewer Benefit Fee file code
"parkminspacesreqd", -- Minimum Parking Spaces Required
"parkonsiteprovided", -- Indicates if Onsite Parking is provided
"commissionerdistrict", -- Commissioner District Number
"pid", -- Parcel ID for the Address. If many parcel IDs exist at this address, this field will be blank.
"situs", -- Address Situs
"gpsx", -- GPS X Reference: Projected Coordinate System = NAD_1983_StatePlane_Florida_East_FIPS_0901_Feet
"gpsy", -- GPS Y Reference: Projected Coordinate System = NAD_1983_StatePlane_Florida_East_FIPS_0901_Feet
"parent_apno", -- If the permit is the result of an originating (parent) permit, this column provides the Application # of the Originating or Parent permit #. A Parent permit application can have many related "child" applications and they may be different application types.
"parent_milestone", -- Milestone, or processing stage, of the Parent Application (if applicable)
"appl_type", -- Type of Permit Application. Most common types are BLD (Building), ELE (Electrical), MEC (Mechanical), PLM (Plumbing), ENG (Engineering), FIR (Fire)
"is_parent", -- Y = This is an Originating (Parent) Permit Application that has related (Child) Permit Applications.
"commissioner_name", -- Commissioner Name
"driarea", -- Development of Regional Impact Area
"mainstreet_dist", -- Provides the Mainstreet District where the project is occurring
"georef",
":@computed_region_u8wz_9eai", -- This column was automatically created in order to record in what polygon from the dataset 'Orlando Main Street Program Area' (u8wz-9eai) the point in column 'georef' is located. This enables the creation of region maps (choropleths) in the visualization canvas and data lens.
":@computed_region_bgqw_styj", -- This column was automatically created in order to record in what polygon from the dataset 'Orlando Commissioner Districts' (bgqw-styj) the point in column 'georef' is located. This enables the creation of region maps (choropleths) in the visualization canvas and data lens.
":@computed_region_gsfg_ku74", -- This column was automatically created in order to record in what polygon from the dataset 'Orlando Neighborhoods' (gsfg-ku74) the point in column 'georef' is located. This enables the creation of region maps (choropleths) in the visualization canvas and data lens.
"neighborhood", -- Provides the Neighborhood where the project is occurring (if applicable)
"rcnt_apdt" -- Y = Application was created in the last 6 months
FROM
"cityoforlando/building-permit-applications-main-street-districts-ny35-rb8n:latest"."building_permit_applications_main_street_districts"
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 cityoforlando/building-permit-applications-main-street-districts-ny35-rb8n
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 cityoforlando/building-permit-applications-main-street-districts-ny35-rb8n: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 cityoforlando/building-permit-applications-main-street-districts-ny35-rb8n
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 cityoforlando/building-permit-applications-main-street-districts-ny35-rb8n:latest
This will download all the objects for the latest
tag of cityoforlando/building-permit-applications-main-street-districts-ny35-rb8n
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 cityoforlando/building-permit-applications-main-street-districts-ny35-rb8n: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 cityoforlando/building-permit-applications-main-street-districts-ny35-rb8n: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, cityoforlando/building-permit-applications-main-street-districts-ny35-rb8n
is just another Postgres schema.