delaware-gov/delaware-coastal-cleanup-results-jumg-zbb3
Icon for Socrata external plugin

Query the Data Delivery Network

Query the DDN

The 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
    "_55_gallon_drums", -- Number of 55-Gallon Drums found (category removed after 2012)
    "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
    "batteries", -- Number of Batteries found (category removed after 2012)
    "plastic_pieces", -- Number of Plastic Pieces found (category created in 2013)
    "fishing_net_pieces", -- Number of Fishing Net & Pieces found
    "fishing_line", -- Number of Fishing Line (1 yard/meter = 1 piece) found
    "_6_pack_holders", -- Number of 6-Pack Holders found
    "strapping_bands", -- Number of Strapping Bands found
    "tobacco_packaging_wrap", -- Number of Tobacco Packaging/Wrap found
    "balloons", -- Number of Balloons found
    "cigar_tips", -- Number of Cigar Tips found
    "cigarette_lighters", -- Number of Cigarette Lighters found
    "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
    "rope", -- Number of pieces of Rope (1 yard/meter = 1 piece) found
    "cups_plates_foam", -- Number of Cups, Plates (Foam) found (combined with Forks, Knives, Spoons 2008-2012)
    "paper_bags", -- Number of Paper Bags found
    "beverage_bottles_plastic", -- Number of Beverage Bottles (Plastic) found
    "location_lat_long_zip",
    "cleanup_date", -- Date of cleanup
    "location_lat_long", -- Latitude and longitude of cleanup location
    "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)
    "county", -- County in which cleanup location is found
    "location_lat_long_address",
    "location_lat_long_city",
    "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
    "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)
    "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 
    "construction_materials", -- Number of Construction Materials 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)
    "fishing_buoys_pots_traps" -- Number of Fishing Buoys, Pots & Traps 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.

This repository is an "external" repository. That means it's hosted elsewhere, in this case at data.delaware.gov. When you querydelaware-gov/delaware-coastal-cleanup-results-jumg-zbb3: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

Install Splitgraph Locally
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; sgrcan 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 cloneand sgr checkout.

Mounting Data

This repository is an external repository. It's not hosted by Splitgraph. It is hosted by data.delaware.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 \
  "delaware-gov/delaware-coastal-cleanup-results-jumg-zbb3" \
  --handler-options '{
    "domain": "data.delaware.gov",
    "tables": {
        "delaware_coastal_cleanup_results": "jumg-zbb3"
    }
}'

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, delaware-gov/delaware-coastal-cleanup-results-jumg-zbb3 is just another Postgres schema.