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 horseshoe_crab_spawning_survey
table in this repository, by referencing it like:
"delaware-gov/horseshoe-crab-spawning-survey-cqsj-dfgg:latest"."horseshoe_crab_spawning_survey"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"year", -- Year of survey
"de_male_90_ci_lower_limit", -- 90% Confidence Interval - Lower limit of values where there exists a 90% probability of male horseshoe crab spawning activity in Delaware
"baywide_female_90_ci_upper_limit", -- 90% Confidence Interval - Upper limit of values where there exists a 90% probability of female horseshoe crab spawning activity
"baywide_male_spawning_activity", -- The mean of the total number of male crabs per total area available for the spawning survey on all surveyed beaches.
"baywide_spawning_activity_lunar_period_1", -- The mean of the total number of female crabs per total area available for the spawning survey on all surveyed beaches. The first moon phase (new or full) in May around which surveying begins - 2 days before, day of, 2 days after.
"avg_daily_water_temp_in_may_c", -- Average of daily water temperatures recorded at the National Ocean Service station at Lewes, DE (Station Identification Number 8557380) during the month of May in °Celsius
"numbermalesperfemale", -- The number of males observed in a given spawning season per female observed during that same season.
"nj_beaches_surveyed", -- Number of beaches on which the standardized form of the spawning survey was conducted in New Jersey
"nj_female_90_ci_upper_limit", -- 90% Confidence Interval - Upper limit of values where there exists a 90% probability of female horseshoe crab spawning activity in New Jersey
"nj_female_90_ci_lower_limit", -- 90% Confidence Interval - Lower limit of values where there exists a 90% probability of female horseshoe crab spawning activity in New Jersey
"total_beaches_surveyed", -- Number of beaches on which the standardized form of the spawning survey was conducted baywide
"baywide_male_sd", -- Standard Deviation - Statistical variation of Index of Spawning Activity (ISA) values for males
"baywide_male_cv", -- Coefficient of variation - Unitless description of the amount of variation relative to the mean Index of Spawning Activity (ISA), expressed as a percentage for males
"baywide_female_spawning_activity", -- Index of female horseshoe crab spawning activity - mean number of female crabs per square meter per night for Delaware and New Jersey beaches
"baywide_spawning_activitylunar_period_4", -- The mean of the total number of female crabs per total area available for the spawning survey on all surveyed beaches. The second moon phase (new or full) in June around which surveying occurs - 2 days before, day of, 2 days after (typically the last period of surveying).
"nj_female_spawning_activity", -- The mean of the total number of female crabs per total area available for the spawning survey on all NJ surveyed beaches
"de_female_spawning_in_may", -- Proportion of females recorded during May of a given survey year on Delaware beaches
"nj_female_spawning_in_may", -- Proportion of females recorded during May of a given survey year on New Jersey Beaches
"de_female_spawning_activity", -- The mean of the total number of female crabs per total area available for the spawning survey on all DE surveyed beaches
"baywide_spawning_activitylunar_period_2", -- The mean of the total number of female crabs per total area available for the spawning survey on all surveyed beaches. The second moon phase (new or full) in May around which surveying occurs - 2 days before, day of, 2 days after.
"baywide_spawning_activitylunar_period_3", -- The mean of the total number of female crabs per total area available for the spawning survey on all surveyed beaches. The first moon phase (new or full) in June around which surveying occurs - 2 days before, day of, 2 days after.
"baywide_male_90_ci_lower_limit", -- 90% Confidence Interval - Lower limit of values where there exists a 90% probability of male horseshoe crab spawning activity
"baywide_female_cv", -- Coefficient of variation - Unitless description of the amount of variation relative to the mean Index of Spawning Activity (ISA), expressed as a percentage for females
"de_male_90_ci_upper_limit", -- 90% Confidence Interval - Upper limit of values where there exists a 90% probability of female horseshoe crab spawning activity in Delaware
"de_female_90_ci_lower_limit", -- 90% Confidence Interval - Lower limit of values where there exists a 90% probability of female horseshoe crab spawning activity in Delaware
"nj_male_spawning_activity", -- The mean of the total number of male crabs per total area available for the spawning survey on all NJ surveyed beaches
"nj_male_90_ci_upper_limit", -- 90% Confidence Interval - Upper limit of values where there exists a 90% probability of male horseshoe crab spawning activity in New Jersey
"nj_male_90_ci_lower_limit", -- 90% Confidence Interval - Lower limit of values where there exists a 90% probability of male horseshoe crab spawning activity in New Jersey
"de_male_spawning_activity", -- The mean of the total number of male crabs per total area available for the spawning survey on all DE surveyed beaches
"de_beaches_surveyed", -- Number of beaches on which the standardized form of the spawning survey was conducted in Delaware
"baywide_female_sd", -- Standard Deviation - Statistical variation of Index of Spawning Activity (ISA) values for females
"de_female_90_ci_upper_limit", -- 90% Confidence Interval - Upper limit of values where there exists a 90% probability of female horseshoe crab spawning activity in Delaware
"baywide_female_90_ci_lower_limit", -- 90% Confidence Interval - Lower limit of values where there exists a 90% probability of female horseshoe crab spawning activity
"baywide_male_90_ci_upper_limit" -- 90% Confidence Interval - Upper limit of values where there exists a 90% probability of male horseshoe crab spawning activity
FROM
"delaware-gov/horseshoe-crab-spawning-survey-cqsj-dfgg:latest"."horseshoe_crab_spawning_survey"
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/horseshoe-crab-spawning-survey-cqsj-dfgg
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/horseshoe-crab-spawning-survey-cqsj-dfgg: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/horseshoe-crab-spawning-survey-cqsj-dfgg
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/horseshoe-crab-spawning-survey-cqsj-dfgg:latest
This will download all the objects for the latest
tag of delaware-gov/horseshoe-crab-spawning-survey-cqsj-dfgg
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/horseshoe-crab-spawning-survey-cqsj-dfgg: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/horseshoe-crab-spawning-survey-cqsj-dfgg: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/horseshoe-crab-spawning-survey-cqsj-dfgg
is just another Postgres schema.