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.

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, 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 cloneand sgr checkout.

Cloning Data

Because ny-gov/synthesis-of-environmental-mercury-loads-in-new-4rf4-x6zt: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 ny-gov/synthesis-of-environmental-mercury-loads-in-new-4rf4-x6zt

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 ny-gov/synthesis-of-environmental-mercury-loads-in-new-4rf4-x6zt:latest

This will download all the objects for the latest tag of ny-gov/synthesis-of-environmental-mercury-loads-in-new-4rf4-x6zt 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 ny-gov/synthesis-of-environmental-mercury-loads-in-new-4rf4-x6zt: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 ny-gov/synthesis-of-environmental-mercury-loads-in-new-4rf4-x6zt: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, ny-gov/synthesis-of-environmental-mercury-loads-in-new-4rf4-x6zt is just another Postgres schema.

Related Documentation:

Loading...