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 governors_office_of_storm_recovery_gosr_quarterly
table in this repository, by referencing it like:
"ny-gov/governors-office-of-storm-recovery-gosr-quarterly-ss7k-76ub:latest"."governors_office_of_storm_recovery_gosr_quarterly"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"procured_by", -- The name of the unit of government (municipal, county or state agency) procuring the goods or services. Some of the lesser known acronyms include: Community Development and Disaster Recovery Corporation (CDDRC) Dormitory Authority of the State of New York (DASNY) Department of Environmental Conservation (DEC)/Environmental Facilities Corporation (EFC) Division of Budget (DOB)/NYS Housing Trust Fund Corporation (HTFC) Empire State Development Corporation (ESD) Greater Atlantic Beach Water Reclamation District (GABWRD) Homes and Community Renewal (HCR)/Governor’s Office of Storm Recovery (GOSR) NYS Housing Trust Fund Corporation (HTFC)/Governor’s Office of Storm Recovery (GOSR) Health & Welfare Council of Long Island (HWCLI) NYS Department of Transportation (NYS DOT) Office of Parks, Recreation and Historic Preservation (OPRHP) Rebuilding Together NYC Schoharie Soil and Water Conservation District (SSWCD)
"total_contract_amount", -- The total value of the contract including funds not provided by the Governor’s Office of Storm Recovery or in other words the ‘gross amount’ of the contract. If marked ‘open,’ these contracts are for professional services like temporary staffing or legal services, which do not specify a total dollar amount, but do have specific contract end dates. Some DASNY (Dormitory Authority of the State of New York) term consultant contracts do not have a dollar value assigned, rather, the “Not To Exceed” values are decided at the work order level, not the contract level. When there is a specific scope of work that GOSR needs DASNY to perform, GOSR signs a work order with DASNY specifying the scope and budget, and then DASNY issues a work authorization to a contractor to perform the work. (A “work authorization” is the specific contract mechanism used by DASNY to engage a consultant under an existing term contract that details the specific scope of services to be performed. Conversely, a “work order” is the mechanism used under a different HTFC/DASNY subrecipient agreement pursuant to which HTFC engages DASNY to perform a particular scope of work for a specific budget.)
"contract_end_date", -- The end date of the contract for the goods or services provided in the contract. If blank, the contract is open ended. Open-ended contracts exist only for the following: Architectural and engineering services (by contract agreement). Contract terminates upon issuance of a written notice. Affordable housing co-funded with the NYS Homes and Community Renewal (loan and grant agreement). Contract terminates with the latest expiration date of any of the accompanying regulatory agreements. Note that open ended (date) contracts have a specified dollar amount. Note also that open value contracts exist only for two types of contract: temporary staffing services and for legal services.
"brief_description_of_contract", -- A brief description of the goods and services to be provided under contract. Contracts marked ‘TBD’ indicate a contract between GOSR (HTFC) and a subrecipient where the scope of work has yet to be defined. The scope is defined when a project has been approved and added via an amendment to the subrecipient agreement. In some cases, agreements do not lead to any project, in which case, the contract end date may have passed and the brief description is marked ‘TBD.’ An amendment in progress before the contract end date may result in both a project and a lengthening of the contract which may lag in the reporting contained in this dataset. Finally, an amendment added after the end date of a lapsed subrecipient agreement may have an effective date before the end date, and may both add scope to the agreement and extend the term.
"contractor_name", -- The name of the contractor delivering goods or performing services using GOSR’s Community Development Block Grant Disaster Recovery (CDBG-DR) funds from the US Department of Housing and Urban Development.
"duns_number", -- Dun & Bradstreet’s Data Universal Numbering System or DUNS Number is a unique identifier used to identify individual businesses for many business-to-business transactions. Some joint venture contracts/subrecipient agreements may list multiple DUNS numbers, in other words, separate DUNS for each vendor/subrecipient if there is no joint venture DUNS number.
"contract_execution_date", -- The date of the contract execution for the goods or services provided in the contract.
"amount_of_cdbg_dr_funds" -- The dollar value of the grant provided by the Governor’s Office of Storm Recovery or the ‘net amount’ of CDBG-DR funds in the contract.
FROM
"ny-gov/governors-office-of-storm-recovery-gosr-quarterly-ss7k-76ub:latest"."governors_office_of_storm_recovery_gosr_quarterly"
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 ny-gov/governors-office-of-storm-recovery-gosr-quarterly-ss7k-76ub
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 ny-gov/governors-office-of-storm-recovery-gosr-quarterly-ss7k-76ub: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 ny-gov/governors-office-of-storm-recovery-gosr-quarterly-ss7k-76ub
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 ny-gov/governors-office-of-storm-recovery-gosr-quarterly-ss7k-76ub:latest
This will download all the objects for the latest
tag of ny-gov/governors-office-of-storm-recovery-gosr-quarterly-ss7k-76ub
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 ny-gov/governors-office-of-storm-recovery-gosr-quarterly-ss7k-76ub: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 ny-gov/governors-office-of-storm-recovery-gosr-quarterly-ss7k-76ub: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, ny-gov/governors-office-of-storm-recovery-gosr-quarterly-ss7k-76ub
is just another Postgres schema.