ny-gov/synthesis-of-environmental-mercury-loads-in-new-4rf4-x6zt
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 synthesis_of_environmental_mercury_loads_in_new table in this repository, by referencing it like:

"ny-gov/synthesis-of-environmental-mercury-loads-in-new-4rf4-x6zt:latest"."synthesis_of_environmental_mercury_loads_in_new"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "assign_habitattype", -- Habitat type of the organism sampled; either Aquatic or Terrestrial. Blank cells represent data that were not required or are not currently available.
    "sex", -- Sex of organism sampled; either F (Female), IM (Immature), M (Male) or U (Unknown). Blank cells represent data that were not required or are not currently available.
    "yearband_changed", -- Year in which the band number changed; either 2013, 2014, or 2017. Blank cells represent data that were not required or are not currently available.
    "org_spp_code", -- Code for common name of organism sampled as originally reported by the researcher. Blank cells represent data that were not required or are not currently available.
    "subject", -- Subject of the sample. Either Amphibian, Bird, Bivalve, Crustacean, Fish, Invertebrate (Invert), Mammal, Mollusk, Reptile, or Unknown. 
    "bdate", -- Date of sample collection
    "waterbody_type", -- Type of water body data was collected from (ex. Canal, river, lake etc.). Blank cells represent data that were not required or are not currently available.
    "project_id", -- Unique project identifier
    "longitude", -- Longitude of data collection point. Blank cells represent data that were not required or are not currently available.
    "latitude", -- Latitude of data collection point. Blank cells represent data that were not required or are not currently available.
    "capture_loc", -- Unique spatial collection point identifier
    "capture_event", -- Unique spatial and temporal collection point identifier
    "analysis_tissue", -- Type of tissue analyzed
    "composite_size", -- Overall size of composite sample analyzed. Blank cells represent data that were not required or are not currently available
    "assign_foraging_guide", -- Diet type of organism sampled; either Carnivore, Herbivore, Invertivore, Invertivore-Piscivore, Omnivore, Piscivore or Planktivore. Blank cells represent data that were not required or are not currently available.
    "composite_yes_no", -- Whether a composite sample was collected; either Yes or No.
    "sample_id", -- Unique sample identifier
    "superclass", -- Superclass of organism sampled as reported in the Integrated Taxonomic Information System; either Actinopterygii or Tetrapoda. Blank cells represent data that were not required or are not currently available.
    "n", -- Number of samples collected
    "length_method", -- Method used to measure length of organism; either Forearm Length (cm), Length, TL (Total Length). Blank cells represent data that were not required or are not currently available.
    "comp_maxwt_g", -- Maximum weight of organisms included as part of the composite sample analyzed measured in grams. Blank cells represent data that were not required or are not currently available
    "sample_comments", -- Relevant comments related to the organism collected and sampled. Blank cells represent data that were not required or are not currently available
    "tissuecollected", -- Type of tissue collected from organisms (ex. Muscle, Egg, Fat, Skin, etc.).
    "comp_avglen_cm", -- Average length of organisms included as part of the composite sample analyzed, measured in centimeters. Blank cells represent data that were not required or are not currently available
    "comp_maxlen_cm", -- Maximum length of organisms included as part of the composite sample analyzed, measured in centimeters. Blank cells represent data that were not required or are not currently available
    "comp_minlen_cm", -- Minimum length of organisms included as part of the composite sample analyzed, measured in centimeters. Blank cells represent data that were not required or are not currently available
    "comp_avgwt_g", -- Average weight of organisms included as part of the composite sample analyzed, measured in grams. Blank cells represent data that were not required or are not currently available
    "comp_minwt_g", -- Minimum weight of organisms included as part of the composite sample analyzed measured in grams. Blank cells represent data that were not required or are not currently available
    "length_cm", -- Length of organism in which the sample was collected from, measured in centimeters. Blank cells represent data that were not required or are not currently available. 
    "mass_g", -- Mass of organism from which the sample was collected, measured in grams. Blank cells represent data that were not required or are not currently available.
    "age", -- Age of organism sampled; either age in numbers, A (Adult), AD (Adult), Adult, AFY (After First Year), AHY (After Hatch Year), ASY (After Second Year), ATY (After Third Year), HY (Hatch Year), SY (Second Year), TY (Third Year), Imm (Immature), Immature, ), J (Juvenile), juvenile, L (Local: young bird incapable of sustained flight, Sub-Adult, U (Unknown),  Unknown, or Yearling. Blank cells represent data that were not required or are not currently available.
    "recap", -- If a unique individual has been captured previously, either Yes or No. Blank cells represent data that were not required or are not currently available.
    "orig_band_num", -- The unique code originally assigned to an individual in the event the band needed to be changed. Blank cells represent data that were not required or are not currently available.
    "band_num", -- The unique code at the time of sample collection used to mark and identify an individual organism (e.g., band identification number from USFWS band, matching band-lab/BANDIT records).
    "distinctcommonname", -- Distinct common name of organism sampled as reported in the Integrated Taxonomic Information System. Blank cells represent data that were not required or are not currently available.
    "species", -- Scientific name of organism sampled as reported in the Integrated Taxonomic Information System. Blank cells represent data that were not required or are not currently available.
    "genus", -- Genus of organism sampled as reported in the Integrated Taxonomic Information System. Blank cells represent data that were not required or are not currently available.
    "family", -- Family of organism sampled as reported in the Integrated Taxonomic Information System. Blank cells represent data that were not required or are not currently available.
    "order", -- Order of organism sampled as reported in the Integrated Taxonomic Information System. Blank cells represent data that were not required or are not currently available.
    "subclass", -- Subclass of organism sampled as reported in the Integrated Taxonomic Information System. Blank cells represent data that were not required or are not currently available.
    "class", -- Class of organism sampled as reported in the Integrated Taxonomic Information System. Blank cells represent data that were not required or are not currently available.
    "tsn", -- Taxonomic Serial Number as reported in the Integrated Taxonomic Information System.
    "org_spp_common" -- Common name of organism sampled as originally reported by the researcher. Blank cells represent data that were not required or are not currently available.
FROM
    "ny-gov/synthesis-of-environmental-mercury-loads-in-new-4rf4-x6zt:latest"."synthesis_of_environmental_mercury_loads_in_new"
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/synthesis-of-environmental-mercury-loads-in-new-4rf4-x6zt 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/synthesis-of-environmental-mercury-loads-in-new-4rf4-x6zt: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.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/synthesis-of-environmental-mercury-loads-in-new-4rf4-x6zt" \
  --handler-options '{
    "domain": "data.ny.gov",
    "tables": {
        "synthesis_of_environmental_mercury_loads_in_new": "4rf4-x6zt"
    }
}'

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/synthesis-of-environmental-mercury-loads-in-new-4rf4-x6zt is just another Postgres schema.