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 harmful_algal_bloom_statewide_occurrence_summary
table in this repository, by referencing it like:
"ny-gov/harmful-algal-bloom-statewide-occurrence-summary-qtg2-hjth:latest"."harmful_algal_bloom_statewide_occurrence_summary"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"geocoded_column_address",
"dec_region", -- Region 1: Nassau County and Suffolk counties; Region 2: Kings, Bronx, New York, Queens and Richmond Counties; Region 3: Dutchess, Orange, Putnam, Rockland, Sullivan, Ulster and Westchester counties; Region 4: Albany, Columbia, Delaware, Greene, Montgomery, Otsego, Rensselaer, Schenectady and Schoharie counties; Region 5: Clinton, Essex, Franklin, Fulton, Hamilton, Saratoga, Warren and Washington counties; Region 6: Herkimer, Jefferson, Lewis, Oneida and St. Lawrence counties; Region 7: Broome, Cayuga, Chenango, Cortland, Madison, Onondaga, Oswego, Tioga and Tompkins counties; Region 8: Chemung, Genesee, Livingston, Monroe, Ontario, Orleans, Schuyler, Seneca, Steuben, Wayne and Yates counties; Region 9: Allegany, Chautauqua, Cattaraugus, Erie, Niagara and Wyoming counties.
"geocoded_column_city",
"number_of_weeks_with_updates", -- Number times type of bloom changed while the waterbody was listed on DEC ‘s HAB Notification list
"waterbody_name", -- NYS DEC Waterbody Name
"geocoded_column", -- Open Data/Socrata-generated geocoding information from supplied latitude/longitude values.
"longitude", -- Longitude
"latitude", -- Latitude
"date_of_last_listing", -- Date last listed for that year on DEC HAB Notification list
":@computed_region_yamh_8v7k",
"year", -- Year Harmful Algal Bloom Reported
"date_of_first_listing", -- Date first listed for that year on the DEC HAB Notification Page see link: https://www.dec.ny.gov/chemical/83310.html for this year’ s Harmful Algal Bloom Notification
"bloom_type", -- The letter codes below refer to maximum bloom status that was documented by the DEC HABs Program in each waterbody in each year. S (Suspicious Bloom): DEC staff determined that conditions fit the description of a cyanobacteria HAB based on visual observations and/or digital photographs; C (Confirmed Bloom): Water sampling results have confirmed the presence of a cyanobacteria HAB which may produce toxins or other harmful compounds; HT (Confirmed with High Toxins Bloom): Water sampling results confirmed that there were toxins present in quantities to potentially cause health effects if people or animals came in contact with the water.
":@computed_region_wbg7_3whc",
":@computed_region_kjdx_g34t",
"number_of_weeks_on_dec_notification_list", -- Number of Weeks Waterbody listed on DEC’s HAB’s Notification list
"county", -- County
"geocoded_column_state",
"geocoded_column_zip"
FROM
"ny-gov/harmful-algal-bloom-statewide-occurrence-summary-qtg2-hjth:latest"."harmful_algal_bloom_statewide_occurrence_summary"
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/harmful-algal-bloom-statewide-occurrence-summary-qtg2-hjth
with SQL in under 60 seconds.
This repository is an "external" repository. That means it's hosted elsewhere, in this case at data.ny.gov. When you queryny-gov/harmful-algal-bloom-statewide-occurrence-summary-qtg2-hjth:latest
on the DDN, we "mount" the repository using the socrata
mount handler. The mount handler proxies your SQL query to the upstream data source, translating it from SQL to the relevant language (in this case SoQL).
We also cache query responses on the DDN, but we run the DDN on multiple nodes so a CACHE_HIT
is only guaranteed for subsequent queries that land on the same node.
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 (like this repository), 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, where the author has pushed Splitgraph Images to the repository, you can "clone" and/or "checkout" the data using sgr clone
and sgr checkout
.
Mounting Data
This repository is an external repository. It's not hosted by Splitgraph. It is hosted by data.ny.gov, and Splitgraph indexes it. This means it is not an actual Splitgraph image, so you cannot use sgr clone
to get the data. Instead, you can use the socrata
adapter with the sgr mount
command. Then, if you want, you can import the data and turn it into a Splitgraph image that others can clone.
First, install Splitgraph if you haven't already.
Mount the table with sgr mount
sgr mount socrata \
"ny-gov/harmful-algal-bloom-statewide-occurrence-summary-qtg2-hjth" \
--handler-options '{
"domain": "data.ny.gov",
"tables": {
"harmful_algal_bloom_statewide_occurrence_summary": "qtg2-hjth"
}
}'
That's it! Now you can query the data in the mounted table like any other Postgres table.
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/harmful-algal-bloom-statewide-occurrence-summary-qtg2-hjth
is just another Postgres schema.