usaid-gov/baseline-study-of-food-for-peace-title-ii-abv5-ef5d
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 baseline_study_of_food_for_peace_title_ii table in this repository, by referencing it like:

"usaid-gov/baseline-study-of-food-for-peace-title-ii-abv5-ef5d:latest"."baseline_study_of_food_for_peace_title_ii"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "n_crops", -- Number of crops produced
    "g25a_4", -- G25A What crops did you store
    "water_catchment", -- Construction of water catchments
    "seeds_rows", -- Planting seeds in rows
    "bulk_transport", -- Bulk transporting of inputs produce or animals
    "sorting", -- Sorting produce
    "sorghum_storage", -- Storage method Sorghum
    "drugs_veterinarian", -- Purchased drugs or medicine from a veterinarian or community health worker
    "pvo", -- PVO
    "animal_drugs", -- Purchased drugs medicines to give to animals
    "member_id", -- Household member ID for merging with other modules
    "cluster", -- Cluster
    "sustainable_livestock", -- Number of sustainable livestock practices in the past 12 months
    "sustainable_agriculture", -- Number of sustainable agriculture practices in the past 12 months
    "veterinary", -- Use the services of community animal health workers
    "kraals", -- Kraals
    "g25a_14", -- G25A What crops did you store
    "g18_10", -- G18 Did you use any of the following natural resources managment practices or techniques
    "g18_6", -- G18 Did you use any of the following natural resources managment practices or techniques
    "credit", -- Obtained an agricultural credit in the last 12 months
    "broadcasting", -- Broadcasting seed
    "g25a_12", -- G25A What crops did you store
    "trading", -- Trading or marketing wholesale retail or export
    "sustainable_livestock_cat", -- Farmers who used at least 2 sustainable livestock practices in the past 12 months
    "g25a_9", -- G25A What crops did you store
    "processing", -- Drying or processing produce
    "grading", -- Grading produce
    "g25a_5", -- G25A What crops did you store
    "g23a", -- G23A What was the main method that you used to store legumes
    "sustainable_ag", -- Number of sustainable agriculture crop practices and or technologies in the past 12 months
    "g17_4", -- G17 Where did you purchase drugs or medicine
    "crops_no", -- No crops
    "g18_8", -- G18 Did you use any of the following natural resources managment practices or techniques
    "other_methods", -- Other methods other crops
    "savings", -- Saved money in the last 12 months
    "agroforestry", -- Agro forestry or cultivation of fruit trees
    "fmwt", -- Farmer sampling weight
    "crop_rotation", -- Crop rotation
    "sustainable_agriculture_cat", -- Farmers who used at least 3 sustainable agriculture practices in the past 12 months
    "g25a_8", -- G25A What crops did you store
    "insurance", -- Had agricultural insurance in the last 12 months
    "maize_storage", -- Storage method Maize
    "g16_s9_9", -- G16 S9 Did you use any of these practices for species 1 9 sheep
    "livestock_none", -- No activities
    "g18_2", -- G18 Did you use any of the following natural resources managment practices or techniques
    "sustainable_nrm_cat", -- Farmers who used at least 1 sustainable NRM practices in the past 12 months
    "manage_plantation", -- Management of forest plantation
    "sustainable_nrm", -- Number of sustainable NRM practices in the past 12 months
    "valuechain_other", -- Other activities
    "livestock", -- Have animals that raise care for and make decisions about
    "storage", -- Stored sorghum maize legumes rice or other crops
    "purchase_inputs", -- Purchase inputs
    "natural_regeneration", -- Management of natural regeneration
    "value_chain_all_cat", -- Farmers who practiced all the value chain activities promoted by the project in the past 12 months
    "id",
    "g25a_6", -- G25A What crops did you store
    "g18_9", -- G18 Did you use any of the following natural resources managment practices or techniques
    "crops_other", -- Other crop practices
    "sustainable_ag_cat", -- Farmers who used at least 2 sustainable agriculture crop practices and or technologies in the past 12 months
    "g20", -- G20 During the past 12 months did you store any crops from your plots
    "financial_services", -- Farmers who used any financial services in the past 12 months
    "g19", -- G19 REFER TO G04 IS ANSWER YES
    "g25b_c6", -- G25B What was the main method that you used to store
    "intercropping", -- Intercropping
    "g25b_c2", -- G25B What was the main method that you used to store
    "granary", -- Granary other crops
    "soil_hand", -- Soil preparation by hand
    "silo", -- Silo other crops
    "legumes_storage", -- Storage method Legumes
    "rice_storage", -- Storage method Rice
    "g25b_c1", -- G25B What was the main method that you used to store
    "watershed", -- Management of watershed or reforestation
    "livestock_no", -- No livestock
    "g25a_2", -- G25A What crops did you store
    "g18_4", -- G18 Did you use any of the following natural resources managment practices or techniques
    "vaccination", -- Vaccination
    "g17_3", -- G17 Where did you purchase drugs or medicine
    "shelters", -- Animal shelters
    "c25b_c4", -- G25B What was the main method that you used to store
    "g17_5", -- G17 Where did you purchase drugs or medicine
    "g25a_3", -- G25A What crops did you store
    "crops_none", -- No activities
    "deworming", -- Deworming
    "g18_7", -- G18 Did you use any of the following natural resources managment practices or techniques
    "g18_1", -- G18 Did you use any of the following natural resources managment practices or techniques
    "fertilizer", -- Applying fertilizer
    "nrm_none", -- No activities
    "g24a", -- G24A What was the main method that you used to store rice
    "value_chain_cat", -- Farmers who practiced at least two of the value chain activities promoted by the project in the past 12 months
    "g23", -- G23 Did you store legumes
    "valuechain_none", -- No activities
    "g26", -- G26 Did you support the bolus scheme
    "cereal_bank", -- Cereal bank other crops
    "g25a_11", -- G25A What crops did you store
    "g25a_10", -- G25A What crops did you store
    "g25", -- G25 Did you store any other crops
    "g25a_15", -- G25A What crops did you store
    "improved_storage", -- Farmers who used improved storage practices in the past 12 months
    "g16_s9_10", -- G16 S9 Did you use any of these practices for species 1 9 sheep
    "g17_2", -- G17 Where did you purchase drugs or medicine
    "g18_3", -- G18 Did you use any of the following natural resources managment practices or techniques
    "g21a", -- G21A What was the main method that you used to store sorghum
    "g22", -- G22 Did you store maize
    "g24", -- G24 Did you store rice
    "g25a_1", -- G25A What crops did you store
    "strata", -- Strata
    "g17_1", -- G17 Where did you purchase drugs or medicine
    "g25b_c3", -- G25B What was the main method that you used to store
    "soil_plow", -- Soil preparation by ox plow
    "soil_conservation", -- Soil conservation on hillsides
    "crops", -- Planted any crops within the last 12 months
    "g25a_13", -- G25A What crops did you store
    "g21", -- G21 Did you store sorghum
    "value_chain_any", -- Farmers who practiced at least two of the value chain activities promoted by the project in the past 12 months
    "g25a_7", -- G25A What crops did you store
    "g22a", -- G22A What was the main method that you used to store maize
    "g25b_c5", -- G25B What was the main method that you used to store
    "tillage", -- Tillage of land
    "soil_tractor", -- Soil preparation by tractor
    "animal_feeds", -- Homemade animal feeds made of locally available products
    "forest_products", -- Collecting products from forest plants such as gum arabic
    "g18_5" -- G18 Did you use any of the following natural resources managment practices or techniques
FROM
    "usaid-gov/baseline-study-of-food-for-peace-title-ii-abv5-ef5d:latest"."baseline_study_of_food_for_peace_title_ii"
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/baseline-study-of-food-for-peace-title-ii-abv5-ef5d 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/baseline-study-of-food-for-peace-title-ii-abv5-ef5d: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/baseline-study-of-food-for-peace-title-ii-abv5-ef5d" \
  --handler-options '{
    "domain": "data.usaid.gov",
    "tables": {
        "baseline_study_of_food_for_peace_title_ii": "abv5-ef5d"
    }
}'

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/baseline-study-of-food-for-peace-title-ii-abv5-ef5d is just another Postgres schema.