usaid-gov/guatemala-maternal-health-and-sanitation-data-icah-5qgn
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 guatemala_maternal_health_and_sanitation_data table in this repository, by referencing it like:

"usaid-gov/guatemala-maternal-health-and-sanitation-data-icah-5qgn:latest"."guatemala_maternal_health_and_sanitation_data"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "at_spmes", -- SP MES in which oversaw ANTHROPOMETRY
    "hhwt", -- Sampling weight for households and household members
    "at_mi", -- Minutes module starts ANTHROPOMETRY
    "pvo", -- PVO
    "eligible_women", -- Women eligible for Module E between 15 and 49 years of age
    "c1819", -- Went to bed hungry
    "cl", -- Miscellaneous
    "gendered_hh", -- Gendered Household type
    "at_com1",
    "at_id", -- ANTHROPOMETRY ID
    "male_adult_max", -- Household has at least one male 18 or older
    "strata", -- Strata
    "ch", -- Pulses legumes nuts
    "hhs", -- Household Hunger Scale
    "cj", -- Oil fats
    "at_hi", -- Anthropometry module starts Time
    "filter",
    "int_date", -- Date of Interview
    "improved_water", -- Households using an improved drinking water source
    "at_ropa", -- AT CLOTH
    "c1617", -- No food at all in the house
    "cd", -- Fruits
    "mi_count1", -- Number of unique caretakers interviewed per hh according to MOD I I01C
    "at_spano", -- SP A O in which oversaw ANTHROPOMETRY
    "ck", -- Sugar honey
    "child_max", -- Household has at least one child under 18
    "at_spid", -- Supervisor Id SP ID ANTHROPOMETRY
    "cb", -- Root and tubers
    "toilet",
    "at_mf", -- Module ends AT MF ANTHROPOMETRY Minutes
    "foods_min", -- Flag for case deletion Did not consume ANY foods in the last 7 days or MISSING
    "cc", -- Vegetables
    "at_com2",
    "at_dia", -- Conducted AT Dia ANTHROPOMETRY
    "at_spdia", -- SP Dia in which oversaw ANTHROPOMETRY
    "improved_sanitation", -- Households using improved sanitation facilities
    "at_hf", -- Module Time ends ANTHROPOMETRY AT HF
    "female_adult_max", -- Household has at least one female 18 or older
    "cluster", -- Cluster
    "wom_count", -- Number of women interviewed in household per MOD E E02
    "birth_date", -- Woman s date of birth
    "total_members", -- Total household members
    "wmwt", -- Sampling weight for women 15 49 adjusted for module E non response
    "mtwt", -- Sampling weight for mothers of children under 5 years of age adjusted for module I non response
    "c2021", -- Went all day and night without eating
    "id",
    "hdds_missing",
    "hhs_n", -- Household Hunger Scale moderate or severe hunger
    "soap_water", -- Cleansing agent and water at handwashing station
    "hdds", -- Average Household Dietary Diversity Score HDDS
    "ci", -- Milk and milk products
    "cg", -- Fish and seafood
    "ce", -- Meats organs blood
    "at_mes", -- Conducted AT MES ANTHROPOMETRY
    "at_ano", -- Conducted AT A O ANTHROPOMETRY
    "ca", -- Cereals
    "wom_age", -- Women s age in completed years
    "cf" -- Eggs
FROM
    "usaid-gov/guatemala-maternal-health-and-sanitation-data-icah-5qgn:latest"."guatemala_maternal_health_and_sanitation_data"
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 usaid-gov/guatemala-maternal-health-and-sanitation-data-icah-5qgn with SQL in under 60 seconds.

This repository is an "external" repository. That means it's hosted elsewhere, in this case at data.usaid.gov. When you queryusaid-gov/guatemala-maternal-health-and-sanitation-data-icah-5qgn: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.usaid.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 \
  "usaid-gov/guatemala-maternal-health-and-sanitation-data-icah-5qgn" \
  --handler-options '{
    "domain": "data.usaid.gov",
    "tables": {
        "guatemala_maternal_health_and_sanitation_data": "icah-5qgn"
    }
}'

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, usaid-gov/guatemala-maternal-health-and-sanitation-data-icah-5qgn is just another Postgres schema.