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 usaid_anticorruption_projects_database
table in this repository, by referencing it like:
"datahub-usaid-gov/usaid-anticorruption-projects-database-ubuf-e3x5:latest"."usaid_anticorruption_projects_database"
or in a full query, like:
SELECT
":id", -- Socrata column ID
"final_res", -- URL of the final report on the project, if one was submitted
"rfp_rftop",
"awd_amount", -- Possible size of project expressed as a range of dollars (a) 1 M, b) 1 M- 5 M, c) 5 M- 10 M, d) 10 M- 25 M, e) 25 M- 50 M, f) 50 M- 100 M, g) 100 M)
"mind_eval", -- The URL of a mid-term evaluation report, if one was completed
"awd_value", -- Actual dollars spent
"intervention_type",
"proj_res",
"implementer", -- Partner name
"sector", -- Sector focus of the project (Agriculture and Food Security, Civil Society, Civil Society, Governance, Civil Society, Legislature, Civil Society, Local Government, Civil Society, Media, Civil Society, Rule of Law, Democracy and Governance, Economic Governance, Public Finance, Economic Growth, Economic Growth, Local Government, Economic Growth, Public Finance, Economic Growth, Rule of Law, Education, Elections and Political Processes, Governance, Governance, Civil Society, Governance, Local Government, Public Finance, Governance, Rule of Law, Healthcare, Healthcare, Governance, Independent Agencies, Independent Agencies, Civil Society, Legislature, Legislature, Rule of Law, Local Government, Local Government, Civil Society, Local Government, Civil Society, Independent Agencies, Local Government, Civil Society, Media, Local Government, Civil Society, Private Sector, Local Government, Legislature, Local Government, Public Finance, Media, Private Sector, Economic Growth, Public Finance, Public Finance, Local Government, Public Finance, Rule of Law, Civil Society, Rule of Law, Rule of Law, Civil Society, Rule of Law, Civil Society, Education, Rule of Law, Economic Growth, Rule of Law, Governance, Rule of Law, Independent Agencies, Rule of Law, Legislature, Rule of Law, Legislature, Civil Society, Rule of Law, Local Government, Rule of Law, Public Finance)
"interim_rep", -- The URL of any interim report, if one was submitted
"intervention", -- Type of intervention (Accountability, Accountability, Awareness, Accountability, Awareness, Participation, Accountability, Enforcement, Accountability, Participation, Accountability, Transparency, Assessment, Awareness, Awareness, Accountability, Awareness, Participation, Enforcement, Accountability, Enforcement, Accountability, Transparency, Enforcement, Awareness, Enforcement, Participation, Enforcement, Transparency, Enforcement, Transparency, Accountability, Enforcement, Transparency, Accountability, Awareness, Participation, Participation, Participation, Awareness, Transparency, Transparency, Participation, Transparency, Accountability, Transparency, Accountability, Awareness, Transparency, Accountability, Awareness, Participation, Transparency, Accountability, Participation, Transparency, Awareness, Transparency, Awareness, Participation, Transparency, Participation)
"corruption", -- The World Bank Control of Corruption Index, for the year project started
"final_eval", -- The URL of the final evaluation report, if one was completed
"stability", -- The World Bank Political Stability Index, for the year project started
"region", -- USAID Region or sub-region (East Asia and Pacific (EAP), Europe and Eurasia (E E), Latin America and Caribbean (LAC), Middle East and North Africa (MENA), South and Central Asia (SCA), Sub-Saharan Africa (SSA))
"proj_nm",
"proj_desc",
"uuid",
"addl_docs", -- The URL of additional reports, if any were submitted
"country", -- Country name
"addl_info", -- The URL where additional relevant information can be found
"st_date", -- Year project started
"audit", -- The URL of the audit report, if the project was audited
"end_date" -- Year project ended
FROM
"datahub-usaid-gov/usaid-anticorruption-projects-database-ubuf-e3x5:latest"."usaid_anticorruption_projects_database"
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 datahub-usaid-gov/usaid-anticorruption-projects-database-ubuf-e3x5
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 datahub-usaid-gov/usaid-anticorruption-projects-database-ubuf-e3x5: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 datahub-usaid-gov/usaid-anticorruption-projects-database-ubuf-e3x5
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 datahub-usaid-gov/usaid-anticorruption-projects-database-ubuf-e3x5:latest
This will download all the objects for the latest
tag of datahub-usaid-gov/usaid-anticorruption-projects-database-ubuf-e3x5
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 datahub-usaid-gov/usaid-anticorruption-projects-database-ubuf-e3x5: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 datahub-usaid-gov/usaid-anticorruption-projects-database-ubuf-e3x5: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, datahub-usaid-gov/usaid-anticorruption-projects-database-ubuf-e3x5
is just another Postgres schema.