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 historical_sidewalk_caf_licenses_and_applications
table in this repository, by referencing it like:
"cityofnewyork-us/historical-sidewalk-caf-licenses-and-applications-qcdj-rwhu:latest"."historical_sidewalk_caf_licenses_and_applications"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"hearing_public_dd", -- If applicable, the date when a public hearing is scheduled.
"send_package_dd", -- Date when the sidewalk café license application was sent to the relevant Borough President, Community Board, City Council Member, and Speaker of the Council.
"app_sq_ft", -- The business applied for this amount of square footage space for its sidewalk café.
"expiration_date", -- Expiration date of Temporary Operating Letter or DCA License.
"cp", -- Status of the NYC Department of City Planning’s review of enclosed sidewalk café applications.
"app_too_date", -- Expiration date of Temporary Operating Letter. DCA may issue a Temporary Operating Letter to certain applicants while their license application is being reviewed. This allows the business to legally operate for a specific time period.
"hearing", -- Status of the public hearing for reviewing sidewalk café license applications.
"submit_date", -- Latest date when a business pays (a portion of) its submission fee for a DCA sidewalk café license application.
"dpqa", -- Status of DCA review of a sidewalk café license application.
"app_status_date", -- The date when a business’s DCA sidewalk café application reached its APP_STATUS.
"swc_type", -- A sidewalk café is a portion of a legal restaurant that operates on the public sidewalk. There are three types: Enclosed, Unenclosed, and Small Unenclosed.
"app_status", -- This indicates the status of a business’s DCA sidewalk café application.
"lic_status", -- This indicates whether a sidewalk café license is active or inactive.
"cb_dd", -- Date when the application’s Community Board review reached its current status.
"cb", -- Status of the relevant Community Board’s review of a sidewalk café license application.
"hearing_public", -- If a public hearing is scheduled, value will be “SWC Public Hearing”.
"city_council_district", -- The New York City Council District where a business is located.
"state", -- The state where the business is located.
"cd_url", -- The URL for the website of the NYC Community District where a business is located.
"city", -- The city where the business is located.
"hearing_dd", -- Date when the application’s public hearing reached its current status.
"issuance", -- Status of DCA sidewalk café license issuance.
"app_tables", -- The business applied for this number of tables for its sidewalk café space.
"intake_dd", -- The date when an application’s intake reached its current status.
"swc_chairs", -- This indicates the maximum number of chairs for the sidewalk café space as permitted by the business’s DCA license.
"moo_dd", -- Date when the application’s MOCS review reached its current status.
"final_y", -- Y coordinate of business’s address using New York Long Island State Plane.
"community_district", -- The New York City Community District where a business is located.
"business_name", -- The legal business name as filed with the New York State Secretary of State or County Clerk
"cc_dd", -- Date when the application’s City Council review reached its current status.
"moo", -- Status of Mayor’s Office of Contract Services (MOCS) review of a business’s sidewalk café license application.
"issuance_dd", -- Date when the application’s issuance reached its current status.
"app_id", -- An identification number assigned by DCA to record each application received.
"business_name2", -- If applicable, the Doing-Business-As (DBA)/trade name.
"app_swc_type", -- A sidewalk café is a portion of a legal restaurant that operates on the public sidewalk. There are three types: Enclosed, Unenclosed, and Small Unenclosed.
"swc_tables", -- This indicates the maximum number of tables for the sidewalk café space as permitted by the business’s DCA license.
"cc", -- Status of City Council review of a business’s sidewalk café license application.
"intake", -- Status of DCA receipt of a sidewalk café license application.
"swc_sq_ft", -- This indicates the size of the sidewalk café space by square footage as permitted by the business’s DCA license.
"cp_dd", -- Date when the application’s Department of City Planning review reached its current status.
"license_nbr", -- An identification number issued to businesses/individuals to operate legally for the duration of their license term.
"street", -- The street name of the business’s address.
"app_chairs", -- The business applied for this number of chairs for its sidewalk café space.
"zip", -- The zip code where the business is located.
"building", -- The building number of the business’s address.
"dohmh", -- An identification number used by the Department of Health and Mental Hygiene (DOHMH) to permit a food service establishment to operate its business.
"final_x" -- X coordinate of business’s address using New York Long Island State Plane.
FROM
"cityofnewyork-us/historical-sidewalk-caf-licenses-and-applications-qcdj-rwhu:latest"."historical_sidewalk_caf_licenses_and_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/historical-sidewalk-caf-licenses-and-applications-qcdj-rwhu
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/historical-sidewalk-caf-licenses-and-applications-qcdj-rwhu: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/historical-sidewalk-caf-licenses-and-applications-qcdj-rwhu
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/historical-sidewalk-caf-licenses-and-applications-qcdj-rwhu:latest
This will download all the objects for the latest
tag of cityofnewyork-us/historical-sidewalk-caf-licenses-and-applications-qcdj-rwhu
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/historical-sidewalk-caf-licenses-and-applications-qcdj-rwhu: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/historical-sidewalk-caf-licenses-and-applications-qcdj-rwhu: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/historical-sidewalk-caf-licenses-and-applications-qcdj-rwhu
is just another Postgres schema.