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 ctcachcd_resource_opportunity_areas_2022
table in this repository, by referencing it like:
"bayareametro-gov/ctcachcd-resource-opportunity-areas-2022-vr7h-smni:latest"."ctcachcd_resource_opportunity_areas_2022"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"tract_geoid", -- Census tract geographic feature identification value. These are motly used in the analysis of urban areas.
"region", -- Subunit of California the analysis was run on. The subset of state regions includes all, or part, of five regions. The analysis was done by region to reduce unfair comparisons between the significantly varied areas found in the state. Column values are 'San Francisco Bay Area Region' (Region is composed of Alameda County, Contra Costa County (partial), Marin County (partial), Napa County (partial), City and County of San Francisco, San Mateo County (partial), Santa Clara County (partial), Solano County (partial), and Sonoma County (partial)) and 'Rural Areas' (Category is composed of (for this subset) Contra Costa County (partial), Marin County (partial), Napa County (partial), San Mateo County (partial), Santa Clara County (partial), Solano County (partial), and Sonoma County (partial)).
"oppcat", -- Final category assigned to census tract. Category determination is based on community index score and a filter for impoverished and racially segregated neighborhoods. Column values are 'High Segregation & Poverty' (Tracts with at least 30% of the population falling under the federal poverty line and a racial Location Quotient of higher than 1.25 for Black, Hispanic, Asian, or all people of color in comparison to the county), 'Highest Resource' (Allocated to 20 percent of the tracts in each region with the highest relative index scores), 'High Resource' (Allocated to the next 20 percent, after Highest Resource category, of the tracts in each region based on relative index scores), 'Moderate Resource' (Higher of the remaining non-filtered and non-excluded tracts in each region, based on community index scores. Remaining tracts were evenly divided between the two lowest resource categories), 'Low Resource' (Lower of the remaining non-filtered and non-excluded tracts in each region, based on community index scores. Remaining tracts were evenly divided between the two lowest resource categories), and null/blank (Missing or insufficient data).
"index", -- Tract-level/block group-level z-score determining overall community index value. Value was calculated by averaging the three analysis domain (economic, environment, and education) results. These index scores are used to sort each tract into opportunity categories.
"fipco", -- Federal Information Processing Series (FIPS) code for state and county.Format is SSCCC, where SS is two-digit state code (06, California, is the only value) and CCC is three digit county code. Column values are 06001 (Alameda County), 06013 (Contra Costa County), 06041 (Marin County), 06055 (Napa County), 06075 (San Francisco, City and County of), 06081 (San Mateo County), 06085 (Santa Clara County), 06095 (Solano County), and 06097 (Sonoma County).
"env_hl_", -- Results of environmental analysis (by region). The CalEnviroScreen 4.0 indicators for this domain are ozone, PM2.5, diesel PM, drinking water, pesticides, toxic releases, traffic, children's lead risk from housing, cleanup sites, groundwater threats, hazardous waste, impaired water bodies, and solid waste sites. Each census tract received a score for each indicator, except where data was missing. To account for the fact that each indicator was measured differently (e.g., percent versus dollar amount), a unit-less “z-score” was calculated for each indicator within each region. These tract-level z-scores were then averaged together by domain (with each indicator’s score receiving an equal weighting).
"ed_domn", -- Results of education analysis (by region). The indicators for this domain are math proficiency, reading proficiency, high school graduation rates, and student poverty rate. Each census tract received a score for each indicator, except where data was missing. To account for the fact that each indicator was measured differently (e.g., percent versus dollar amount), a unit-less “z-score” was calculated for each indicator within each region. These tract-level z-scores were then averaged together by domain (with each indicator’s score receiving an equal weighting).
"ecn_dmn", -- Results of economic analysis (by region). The indicators for this domain are poverty, adult education, employment, job proximity, and median home value. Each census tract received a score for each indicator, except where data was missing. To account for the fact that each indicator was measured differently (e.g., percent versus dollar amount), a unit-less “z-score” was calculated for each indicator within each region. These tract-level z-scores were then averaged together by domain (with each indicator’s score receiving an equal weighting).
"blkgp_geoid", -- Census block group geographic feature identification value. These are mostly used in the analysis of rural areas.
"cnty_nm", -- Text name of the county.
"geometry" -- Feature geometry.
FROM
"bayareametro-gov/ctcachcd-resource-opportunity-areas-2022-vr7h-smni:latest"."ctcachcd_resource_opportunity_areas_2022"
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 bayareametro-gov/ctcachcd-resource-opportunity-areas-2022-vr7h-smni
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 bayareametro-gov/ctcachcd-resource-opportunity-areas-2022-vr7h-smni: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 bayareametro-gov/ctcachcd-resource-opportunity-areas-2022-vr7h-smni
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 bayareametro-gov/ctcachcd-resource-opportunity-areas-2022-vr7h-smni:latest
This will download all the objects for the latest
tag of bayareametro-gov/ctcachcd-resource-opportunity-areas-2022-vr7h-smni
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 bayareametro-gov/ctcachcd-resource-opportunity-areas-2022-vr7h-smni: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 bayareametro-gov/ctcachcd-resource-opportunity-areas-2022-vr7h-smni: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, bayareametro-gov/ctcachcd-resource-opportunity-areas-2022-vr7h-smni
is just another Postgres schema.