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 dob_now_electrical_permit_applications
table in this repository, by referencing it like:
"cityofnewyork-us/dob-now-electrical-permit-applications-dm9a-ab7w:latest"."dob_now_electrical_permit_applications"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"firm_name", -- Name of the applicant's firm (business, corporation, or partnership)
"gis_bbl",
"completion_date", -- Planned end date and time of the work
"job_start_date", -- Planned start date and time of the work
"total_meters", -- Indicates total number of meters (existing meters + new meters - removed meters)
"temp_construction_svc", -- Indicates whether "Temporary Construction Service" category of work is selected
"owner_zip", -- ZIP code of the building's owner
"disability_policy", -- Policy number of the Disability insurance covering the applicant's firm
"worker_comp_policy", -- Policy number of the Workers Compensation insurance covering the applicant's firm
"general_liability_expiration", -- Expiration date of the General Liability insurance policy covering the applicant's firm
"general_liability_company", -- Name of the company providing General Liability insurance to the applicant's firm
"firm_address", -- Street address of the applicant's firm
"street_name", -- The street name of the job location
"job_number", -- A 9-digit identifier for the job. Should match the first part of the Job Filing Number. The first letter indicates the borough for which the filing is associated, followed by an 8-digit ID number
"job_filing_number", -- A unique identifier assigned to a job filing. It consists of job number (a letter indicating the borough followed by an 8-digit number) hyphenated with Filing Number (a 2-digit code identifying the filing type). Once the permit is issued, a suffix "-EL" is added to the job filing number. (Example: M00000001-I1-EL)
"gis_latitude",
"building_use_type", -- Letter code and description of the building class
"gis_longitude",
"job_description", -- A description of the electrical work to be performed. This description will be printed on the work permit.
"new_meters", -- Indicates number of meters to be added by this work
"lighting_work", -- Indicates whether "Lighting Work" category of work is selected
"owner_city", -- City of the building's owner
"disability_company_name", -- Name of the company providing Disability insurance to the applicant's firm
"worker_comp_company_name", -- Name of the company providing Workers Compensation insurance to the applicant's firm
"zip", -- ZIP code of the applicant's firm
"license_number", -- Applicant's license number, included in the DOB-issued licenses for qualified professionals in the construction trades
"bin", -- Building Identification Number (BIN) of the job location. Assigned by Department of City Planning.
"filing_date", -- Date the filing was created. This should be the earliest date associated with this Job Filing Number.
"gis_nta_name",
"filing_fee", -- Fee required for the job filing
"permit_issued_date", -- Date and time the permit was issued
"remove_meters", -- Indicates number of meters to be removed by this work
"category_work_list", -- "Includes description of other work category selected by the applicant. "
"auth_rep_owner_relation", -- Indicates type of relationship between the authorized representative and the building's owner. Example: Management Agent
"auth_rep_last_name", -- Last name of the building's owner
"disability_expiration_date", -- Expiration date of the Disability insurance policy covering the applicant's firm
"city", -- City of the applicant's firm
"house_number", -- The house number of the job location
"gis_census_tract",
"coo_related", -- Indicates whether or not this filing will result in a new Certificate of Occupancy
"owner_state", -- State of the building's owner
"owner_last_name", -- Last name of the building's owner
"total_billable_work_fee", -- The total amount that the applicant will need to pay, including Filing Fee and Legalization Fee, which are paid when the application is first submitted to DOB, as well as all parts fees, which must be paid before the application can marked complete.
"community_board", -- A 3-digit identifier of the Community Board of the job location
"existing_meters", -- Indicates number of existing meters in scope of this work
"_4_wire", -- Indicates number of "4 Wire" needed for meter work
"svc_work_notify_utility", -- Indicates whether "Service Work / Notify Utility" category of work is selected
"removal_of_vio_or_owner", -- Indicates whether this filing is related to removal of violations or owner/occupant objections;
"amount_paid", -- Total amount paid by applicant so far.
"temp_light_power", -- Indicates whether "Temporary Light Power" category of work is selected
"gis_bin",
"const_bis_job_number", -- If this application is related to another job appliation at DOB, the job number will be found here.
"license_type", -- Type of license issued by DOB to the applicant.
"hvac_wiring", -- Indicates whether "HVAC Wiring" category of work is selected
"payment_method", -- Method used in fee payment
"firm_number", -- Firm number assigned to the applicant's business, corporation, or partnership by DOB
"joint_venture_work", -- Indicates whether the work will be performed by other licensed firm(s) as a joint venture (As per NYC Electrical Code §27-3014.13)
"amount_due", -- Balance remaining to be paid by applicant
"auth_rep_first_name", -- First name of the person designated as authorized representative by the building's owner
"zip_code", -- ZIP Code of the job location
"filing_number", -- A 2-digit code identifying the filing type. Should match the last part of the Job Filing Number.
"general_wiring", -- Indicates whether "General Wiring" category of work is selected
"nogood_check_fee", -- A fee required if first check payment to DOB was rejected / returned
"filing_status", -- Indicates the stage of this filing as it progresses through the permit application process.
"block", -- Tax block number of the job location. Assigned by the Department of Finance.
"lot", -- Tax lot number of the job location. Assigned by the Department of Finance.
"borough", -- The borough of the job location
"gis_council_district",
"applicant_first_name", -- First name of the applicant
"owner_first_name", -- First name of the building's owner
"business_name", -- Business name of the building's owner
"_10_points", -- Indicates number of "10 points" needed for meter work
"boiler_burner_wiring", -- Indicates whether "Boiler Burner Wiring" category of work is selected
"filing_type", -- Indicates whether this filing is new, subsequent or Post Approval Amendment (PAA) filing
"worker_comp_expiration_date", -- Expiration date of the Workers Compensation insurance policy covering the applicant's firm
"title", -- Title of the building's owner
"state", -- State of the applicant's firm
"general_liability_policy", -- Policy number of the General Liability insurance covering the applicant's firm
"legalization_fee", -- Fee required for removal of violations for illegal work
"_3_wire", -- Indicates number of "3 Wire" needed for meter work
"owner_type", -- Type of building ownership.
"owner_address", -- Address of the building's owner
"job_status", -- Indicates the overall status of the electrical job.
"applicant_last_name" -- Last name of the applicant
FROM
"cityofnewyork-us/dob-now-electrical-permit-applications-dm9a-ab7w:latest"."dob_now_electrical_permit_applications"
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-now-electrical-permit-applications-dm9a-ab7w
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/dob-now-electrical-permit-applications-dm9a-ab7w: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/dob-now-electrical-permit-applications-dm9a-ab7w
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/dob-now-electrical-permit-applications-dm9a-ab7w:latest
This will download all the objects for the latest
tag of cityofnewyork-us/dob-now-electrical-permit-applications-dm9a-ab7w
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/dob-now-electrical-permit-applications-dm9a-ab7w: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/dob-now-electrical-permit-applications-dm9a-ab7w: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/dob-now-electrical-permit-applications-dm9a-ab7w
is just another Postgres schema.