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 delaware_coastal_cleanup_results
table in this repository, by referencing it like:
"delaware-gov/delaware-coastal-cleanup-results-jumg-zbb3:latest"."delaware_coastal_cleanup_results"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"fishing_net_pieces", -- Number of Fishing Net & Pieces found
"fishing_buoys_pots_traps", -- Number of Fishing Buoys, Pots & Traps found
"cups_plates_plastic", -- Number of Cups, Plates (Plastic) found (combined with Forks, Knives, Spoons 2008-2012)
"other_plastic_bags", -- Number of Other Plastic Bags found (category created in 2013)
"grocery_bags_plastic", -- Number of Grocery Bags (Plastic) found
"tires", -- Number of Tires found
"toys", -- Number of Toys found (no "toys" category 2013-2015)
"condoms", -- Number of Condoms found
"diapers", -- Number of Diapers found
"syringes", -- Number of Syringes found
"tampons_tampon_applicators", -- Number of Tampons/Tampon Applicators found
"foam_pieces", -- Number of Foam Pieces found (category created in 2013)
"glass_pieces", -- Number of Glass Pieces found (category created in 2013)
"clothing_shoes", -- Number of Clothing, Shoes found (category removed after 2012)
"shotgun_shells_wadding", -- Number of Shotgun Shells/Wadding found (category removed after 2012)
"light_bulbs_tubes", -- Number of Light Bulbs/Tubes found (category removed after 2012)
"cars_car_parts", -- Number of Cars/Car Parts found (category removed after 2012)
"construction_materials", -- Number of Construction Materials found
"cigarette_lighters", -- Number of Cigarette Lighters found
"cigar_tips", -- Number of Cigar Tips found
"balloons", -- Number of Balloons found
"tobacco_packaging_wrap", -- Number of Tobacco Packaging/Wrap found
"strapping_bands", -- Number of Strapping Bands found
"_6_pack_holders", -- Number of 6-Pack Holders found
"fishing_line", -- Number of Fishing Line (1 yard/meter = 1 piece) found
"beverage_cans", -- Number of Beverage Cans found
"beverage_bottles_glass", -- Number of Beverage Bottles (Glass) found
"forks_knives_spoons", -- Number of Forks, Knives, Spoons found (combined with Cups, Plates 2008-2012)
"straws_stirrers", -- Number of Straws, Stirrers found
"lids_plastic", -- Number of Lids (Plastic) found (category combined with Bottle Caps (Plastic) 2008-2012)
"bottle_caps_metal", -- Number of Bottle Caps (Metal) found
"bottle_caps_plastic", -- Number of Bottle Caps (Plastic) found (category combined with Lids (Plastic) 2008-2012)
"cups_plates_foam", -- Number of Cups, Plates (Foam) found (combined with Forks, Knives, Spoons 2008-2012)
"take_out_away_containers", -- Number of Take Out/Away Containers (Plastic) found (category combined with Food Wrappers 2008-2012)
"food_wrappers", -- Number of Food Wrappers (candy, chips, etc.) found (category combined with Take Out/Away Containers 2008-2012)
"cigarette_butts", -- Number of Cigarette Butts found
"bags", -- Number of bags of trash collected
"miles", -- Miles of beach cleaned
"pounds", -- Pounds of trash collected
"people", -- Number of people involved in cleanup
"children", -- Number of children involved in cleanup (category created in 2013)
"adults", -- Number of adults involved in cleanup (category created in 2013)
"cleanup_site", -- Name for the location of the cleanup site
"_55_gallon_drums", -- Number of 55-Gallon Drums found (category removed after 2012)
"batteries", -- Number of Batteries found (category removed after 2012)
"plastic_pieces", -- Number of Plastic Pieces found (category created in 2013)
"fireworks", -- Number of Fireworks found (category created in 2013)
"appliances", -- Number of Appliances (refrigerators, washers, etc.) found
"other_plastic_foam_packaging", -- Number of Other Plastic/Foam Packaging found
"location_lat_long_city",
"location_lat_long_address",
"county", -- County in which cleanup location is found
"rope", -- Number of pieces of Rope (1 yard/meter = 1 piece) found
"other_plastic_bottles", -- Number of Other Plastic Bottles (oil, bleach, etc.) found
"cups_plates_paper", -- Number of Cups, Plates (Paper) found (combined with Forks, Knives, Spoons 2008-2012)
"location_lat_long_state",
"cleanup_type", -- Type of cleanup (whether land-based or water-based)
"take_out_away_containers_1", -- Number of Take Out/Away Containers (Foam) found (category combined with Food Wrappers 2008-2012)
"location_lat_long", -- Latitude and longitude of cleanup location
"cleanup_date", -- Date of cleanup
"location_lat_long_zip",
"beverage_bottles_plastic", -- Number of Beverage Bottles (Plastic) found
"paper_bags" -- Number of Paper Bags found
FROM
"delaware-gov/delaware-coastal-cleanup-results-jumg-zbb3:latest"."delaware_coastal_cleanup_results"
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 delaware-gov/delaware-coastal-cleanup-results-jumg-zbb3
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 delaware-gov/delaware-coastal-cleanup-results-jumg-zbb3: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 delaware-gov/delaware-coastal-cleanup-results-jumg-zbb3
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 delaware-gov/delaware-coastal-cleanup-results-jumg-zbb3:latest
This will download all the objects for the latest
tag of delaware-gov/delaware-coastal-cleanup-results-jumg-zbb3
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 delaware-gov/delaware-coastal-cleanup-results-jumg-zbb3: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 delaware-gov/delaware-coastal-cleanup-results-jumg-zbb3: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, delaware-gov/delaware-coastal-cleanup-results-jumg-zbb3
is just another Postgres schema.